DORMANTno replies

[PATCH] Making cg-seek more robust

From: Pavel Roskin <hidden>
Date: 2016-06-15 22:41:56

Hello!

This patch does following:

If .git/HEAD is not a link, it's detected early, so that basename is not
called without arguments.

.git/HEAD is not deleted until validity of the branch is verified.

.git/blocked is deleted by "rm -f" to suppress unneeded error message if
it's missing.

Signed-off-by: Pavel Roskin <redacted>
--- aa6233be6d1b8bf42797c409a7c23b50593afc99/cg-seek  (mode:100755 sha1:111f7842e5ec20a1e0714e162ca221da5e06ce33)
+++ uncommitted/cg-seek  (mode:100755)
@@ -29,18 +29,23 @@
 if [ -s .git/blocked ]; then
 	branch=$(grep '^seeked from ' .git/blocked | sed 's/^seeked from //')
 else
-	branch=$(basename $(readlink .git/HEAD)) || die "HEAD is not on branch"
+	tmp=$(readlink .git/HEAD)
+	[ "$tmp" ] || die "HEAD is not on branch"
+	branch=$(basename "$tmp")
 fi
 
 curcommit=$(commit-id)
 
-rm .git/HEAD
 if [ ! "$dstcommit" ] || [ "$dstcommit" = "$branch" ]; then
+	rm .git/HEAD
 	ln -s "refs/heads/$branch" .git/HEAD
-	rm .git/blocked
+	rm -f .git/blocked
 	dstcommit=$(commit-id)
 else
-	echo $(commit-id "$dstcommit") >.git/HEAD
+	tmp=$(commit-id "$dstcommit")
+	[ "$tmp" ] || die "branch $dstcommit not found"
+	rm .git/HEAD
+	echo "$tmp" >.git/HEAD
 	[ -s .git/blocked ] || echo "seeked from $branch" >.git/blocked
 fi
 

-- 
Regards,
Pavel Roskin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help