Making cg-seek more robust
PATCH 1/1 Making cg-seek more robust
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 <[email protected]>
cg-seek (mode:100755) renamed from cg-seek (mode:100755 sha1:111f7842e5ec20a1e0714e162ca221da5e06ce33) +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
Signature · 2 lines
Regards, Pavel Roskin