From 782ec49485b7f22fb93f6631703b8ce3ef066532 Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov Date: Sat, 19 Mar 2011 19:53:11 +0300 Subject: [PATCH] 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 --- tg-update.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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() { -- 2.11.4.GIT