{"thread":{"id":"7363","subject":"[PATCH] report where the new HEAD is upon detaching HEAD","startedAt":"2007-03-23T09:37:19Z","lastAt":"2007-03-23T09:37:19Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37797","messageId":"7vejngqp0w.fsf@assigned-by-dhcp.cox.net","threadId":"7363","inReplyTo":null,"subject":"[PATCH] report where the new HEAD is upon detaching HEAD","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-03-23T09:37:19Z","receivedAt":"2007-03-23T09:37:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"After \"git reset\" moves the HEAD around, it reports which commit\nyou are on, which gives the user a warm fuzzy feeling of\nassurance.  Give the same assurance from git-checkout when\nmoving the detached HEAD around.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n git-checkout.sh |   12 ++++++++++--\n 1 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 3c9b1bb..a7390e8 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -163,6 +163,13 @@ cd_to_toplevel\n detached=\n detach_warn=\n \n+describe_detached_head () {\n+\ttest -n \"$quiet\" || {\n+\t\tprintf >&2 \"$1 \"\n+\t\tGIT_PAGER= git log >&2 -1 --pretty=oneline --abbrev-commit \"$2\"\n+\t}\n+}\n+\n if test -z \"$branch$newbranch\" && test \"$new\" != \"$old\"\n then\n \tdetached=\"$new\"\n@@ -173,9 +180,9 @@ If you want to create a new branch from this\n (now or later) by using -b with the checkout command again. Example:\n   git checkout -b <new_branch_name>\"\n \tfi\n-elif test -z \"$oldbranch\" && test -z \"$quiet\"\n+elif test -z \"$oldbranch\"\n then\n-\techo >&2 \"Previous HEAD position was $old\"\n+\tdescribe_detached_head 'Previous HEAD position was' \"$old\"\n fi\n \n if [ \"X$old\" = X ]\n@@ -275,6 +282,7 @@ if [ \"$?\" -eq 0 ]; then\n \t\tthen\n \t\t\techo >&2 \"$detach_warn\"\n \t\tfi\n+\t\tdescribe_detached_head 'HEAD is now at' HEAD\n \tfi\n \trm -f \"$GIT_DIR/MERGE_HEAD\"\n else\n"}]}