From: Junio C Hamano Date: Mon, 8 Jan 2007 10:19:38 +0000 (-0800) Subject: git-checkout: do not warn detaching HEAD when it is already detached. X-Git-Tag: v1.5.0-rc1~5^2~5 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=648861040f2c5fd001a5edcfbb05813505bbb8f1;p=git.git 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 8e11ca4bc..5a7388759 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 ]