From 648861040f2c5fd001a5edcfbb05813505bbb8f1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 8 Jan 2007 02:19:38 -0800 Subject: git-checkout: do not warn detaching HEAD when it is already detached. Signed-off-by: Junio C Hamano diff --git a/git-checkout.sh b/git-checkout.sh index 8e11ca4..5a73887 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -6,6 +6,7 @@ SUBDIRECTORY_OK=Sometimes old_name=HEAD old=$(git-rev-parse --verify $old_name 2>/dev/null) +oldbranch=$(git-symbolic-ref $old_name 2>/dev/null) new= new_name= force= @@ -149,13 +150,17 @@ then # NEEDSWORK: we would want to have this command here # that allows us to detach the HEAD atomically. # git update-ref --detach HEAD "$new" - rm -f "$GIT_DIR/HEAD" - echo "$new" >"$GIT_DIR/HEAD" - echo >&2 "WARNING: you are not on ANY branch anymore. + echo "$new" >"$GIT_DIR/HEAD.new" && + mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" || die "Cannot detach HEAD" + + if test -n "$oldbranch" + then + echo >&2 "WARNING: you are not on ANY branch anymore. If you meant to create a new branch from the commit, you need -b to associate a new branch with the wanted checkout. Example: git checkout -b $arg " + fi fi if [ "X$old" = X ] -- cgit v0.10.2-6-g49f6