diff options
author | Junio C Hamano <junkio@cox.net> | 2007-01-08 02:19:38 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-01-08 03:02:11 -0800 |
commit | 648861040f2c5fd001a5edcfbb05813505bbb8f1 (patch) | |
tree | 6e2893db0e4226ebbecdcef9b91f49358cd5221e /git-checkout.sh | |
parent | c847f537125ceab3425205721fdaaa834e6d8a83 (diff) | |
download | git-648861040f2c5fd001a5edcfbb05813505bbb8f1.tar.gz |
git-checkout: do not warn detaching HEAD when it is already detached.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-checkout.sh')
-rwxr-xr-x | git-checkout.sh | 11 |
1 files 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 <new_branch_name> $arg " + fi fi if [ "X$old" = X ] |