@matheusbsbs / matheus-bagliano / commits / abba9dbbf4
Fork 0

checkout: report where the new HEAD is upon detaching HEAD

After "git reset" moves the HEAD around, it reports which commit you are on, which gives the user a warm fuzzy feeling of assurance. Give the same assurance from git-checkout when moving the detached HEAD around. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 23, 2007 at 02:37 UTC abba9dbbf450d4037a5e2054250f197169ac63eb
1 file changed +10 -2
git-checkout.sh
+10 -2
@@ -163,6 +163,13 @@ cd_to_toplevel
163 detached=
164 detach_warn=
165
166 +describe_detached_head () {
167 + test -n "$quiet" || {
168 + printf >&2 "$1 "
169 + GIT_PAGER= git log >&2 -1 --pretty=oneline --abbrev-commit "$2"
170 + }
171 +}
172 +
173 if test -z "$branch$newbranch" && test "$new" != "$old"
174 then
175 detached="$new"
@@ -173,9 +180,9 @@ If you want to create a new branch from this checkout, you may do so
180 (now or later) by using -b with the checkout command again. Example:
181 git checkout -b <new_branch_name>"
182 fi
176 -elif test -z "$oldbranch" && test -z "$quiet"
183 +elif test -z "$oldbranch"
184 then
178 - echo >&2 "Previous HEAD position was $old"
185 + describe_detached_head 'Previous HEAD position was' "$old"
186 fi
187
188 if [ "X$old" = X ]
@@ -275,6 +282,7 @@ if [ "$?" -eq 0 ]; then
282 then
283 echo >&2 "$detach_warn"
284 fi
285 + describe_detached_head 'HEAD is now at' HEAD
286 fi
287 rm -f "$GIT_DIR/MERGE_HEAD"
288 else