@matheusbsbs / matheus-bagliano / commits / 648861040f
Fork 0

git-checkout: do not warn detaching HEAD when it is already detached.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 8, 2007 at 02:19 UTC 648861040f2c5fd001a5edcfbb05813505bbb8f1
1 file changed +8 -3
git-checkout.sh
+8 -3
@@ -6,6 +6,7 @@ SUBDIRECTORY_OK=Sometimes
6
7 old_name=HEAD
8 old=$(git-rev-parse --verify $old_name 2>/dev/null)
9 +oldbranch=$(git-symbolic-ref $old_name 2>/dev/null)
10 new=
11 new_name=
12 force=
@@ -149,13 +150,17 @@ then
150 # NEEDSWORK: we would want to have this command here
151 # that allows us to detach the HEAD atomically.
152 # git update-ref --detach HEAD "$new"
152 - rm -f "$GIT_DIR/HEAD"
153 - echo "$new" >"$GIT_DIR/HEAD"
154 - echo >&2 "WARNING: you are not on ANY branch anymore.
153 + echo "$new" >"$GIT_DIR/HEAD.new" &&
154 + mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" || die "Cannot detach HEAD"
155 +
156 + if test -n "$oldbranch"
157 + then
158 + echo >&2 "WARNING: you are not on ANY branch anymore.
159 If you meant to create a new branch from the commit, you need -b to
160 associate a new branch with the wanted checkout. Example:
161 git checkout -b <new_branch_name> $arg
162 "
163 + fi
164 fi
165
166 if [ "X$old" = X ]