From 648861040f2c5fd001a5edcfbb05813505bbb8f1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 8 Jan 2007 02:19:38 -0800 Subject: [PATCH] git-checkout: do not warn detaching HEAD when it is already detached. Signed-off-by: Junio C Hamano --- git-checkout.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/git-checkout.sh b/git-checkout.sh index 8e11ca4bc8..5a7388759c 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 ]