From: Andrey Borzenkov Date: Sat, 19 Mar 2011 16:53:11 +0000 (+0300) Subject: tg-update: check for detached state of current branch X-Git-Tag: topgit-0.9~5^2 X-Git-Url: https://repo.or.cz/w/topgit.git/commitdiff_plain/782ec49485b7f22fb93f6631703b8ce3ef066532 tg-update: check for detached state of current branch Check that current branch is not detached if called "-a" so we can return to it. Signed-off-by: Andrey Borzenkov --- diff --git a/tg-update.sh b/tg-update.sh index ecbc0d5..10d4c0f 100644 --- a/tg-update.sh +++ b/tg-update.sh @@ -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() {