threads / patch / 469

patchMaking cg-seek more robust

Subject: [PATCH] Making cg-seek more robust

## tl;dr

One message between May 4, 2005 and May 4, 2005. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Pavel Roskin· May 4, 2005, 00:08 UTC · lore
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 <proski@gnu.org>

--- aa6233be6d1b8bf42797c409a7c23b50593afc99/cg-seek (mode:100755 sha1:111f7842e5ec20a1e0714e162ca221da5e06ce33) +++ uncommitted/cg-seek (mode:100755)

Show changes to diff +9 −4
@@ -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

← back to recent threads