tg-update: check for detached state of current branch
authorAndrey Borzenkov <arvidjaar@gmail.com>
Sat, 19 Mar 2011 16:53:11 +0000 (19 19:53 +0300)
committerAndrey Borzenkov <arvidjaar@gmail.com>
Sat, 19 Mar 2011 16:53:11 +0000 (19 19:53 +0300)
Check that current branch is not detached if called "-a" so we
can return to it.

Signed-off-by: Andrey Borzenkov <arvidjaar@gmail.com>
tg-update.sh

index ecbc0d5..10d4c0f 100644 (file)
@@ -31,11 +31,15 @@ while [ -n "$1" ]; do
 done
 [ -z "$pattern" ] && pattern=refs/top-bases
 
-current="$(git symbolic-ref HEAD | sed 's#^refs/\(heads\|top-bases\)/##')"
-if [ -z "$all" -a -z "$name" ]; then
-       name="$current"
-       base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
-       die "not a TopGit-controlled branch"
+current="$(git symbolic-ref HEAD 2>/dev/null | sed 's#^refs/\(heads\|top-bases\)/##')"
+if [ -z "$all" ]; then
+       if [ -z "$name" ]; then
+               name="$current"
+               base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+                       die "not a TopGit-controlled branch"
+       fi
+else
+       [ -n "$current" ] || die "cannot return to detached tree; switch to another branch"
 fi
 
 update_branch() {