From d117452a801af081ebaf2c516e2d715eacf37601 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 31 Jan 2007 14:10:37 -0500 Subject: tone down the detached head warning This is not meant to frighten people or even to suggest they might be doing something wrong, but rather to notify them of a state change and provide a likely option in the case this state was entered by mistake. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- git-checkout.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index 8500f51ea2..0bae86e325 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -155,9 +155,9 @@ then detached="$new" if test -n "$oldbranch" then - detach_warn="warning: you are not on ANY branch anymore. -If you meant to create a new branch from this checkout, you may still do -so (now or later) by using -b with the checkout command again. Example: + detach_warn="Note: you are not on ANY branch anymore. +If you want to create a new branch from this checkout, you may do so +(now or later) by using -b with the checkout command again. Example: git checkout -b " fi elif test -z "$oldbranch" && test -n "$branch" -- cgit v1.2.3 From e4b0e4ab8ee68df0fa99100640ed5cb54b736141 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 1 Feb 2007 01:08:41 -0800 Subject: detached HEAD -- finishing touches This updates "git-checkout" to report which branch you are switching to. Especially for people who do not use __git_ps1 from contrib/completion/git-completion.bash this would give a friendlier feedback of what is going on, and should make the reminder message much less scary. Here is a sample session (the prompt tells which branch I am on). * I have some local modification and realize that the change deserves to be on its own new topic branch. [git.git (master)]$ git diff --stat git-checkout.sh | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) * So I switch to a new branch. I get a listing of local modifications and assuring "Switched to a new branch" message. [git.git (master)]$ git checkout -b jc/checkout M git-checkout.sh Switched to a new branch "jc/checkout" * If I switch back to "master", I get essentially the same. [git.git (jc/checkout)]$ git checkout master M git-checkout.sh Switched to branch "master" * Detaching head would say which commit I am at and reminds me that I am not on any branch (not that I would detach my HEAD while keeping precious local changes around in any real-world workflow -- this is just a sample session). [git.git (master)]$ git checkout master^ M git-checkout.sh Note: you are not on any branch and are at commit "master^" If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b * Coming back to an attached state can lose the detached HEAD, so I get warned and stopped. [git.git]$ git checkout master You are not on any branch and switching to branch 'master' may lose your changes. At this point, you can do one of two things: (1) Decide it is Ok and say 'git checkout -f master'; (2) Start a new branch from the current commit, by saying 'git checkout -b '. Leaving your HEAD detached; not switching to branch 'master'. * Moving around while my HEAD is detached is Ok. I still get the list of local modifications. [git.git]$ git checkout master^0 M git-checkout.sh * The previous step that switched to the tip commit is an obscure but useful trick. My HEAD is still detached but now it is pointed at by an existing ref, so I can come back safely. [git.git]$ git checkout master M git-checkout.sh Switched to branch "master" * And we are back on the "master" branch. [git.git (master)]$ exit Signed-off-by: Junio C Hamano --- git-checkout.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index 0bae86e325..deb479524a 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -155,7 +155,7 @@ then detached="$new" if test -n "$oldbranch" then - detach_warn="Note: you are not on ANY branch anymore. + detach_warn="Note: you are not on any branch and are at commit \"$new_name\" If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b " @@ -228,7 +228,7 @@ else saved_err=$? if test "$saved_err" = 0 then - test "$new" = "$old" || git diff-index --name-status "$new" + git diff-index --name-status "$new" fi (exit $saved_err) fi @@ -251,6 +251,12 @@ if [ "$?" -eq 0 ]; then if test -n "$branch" then GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD "refs/heads/$branch" + if test -n "$newbranch" + then + echo >&2 "Switched to a new branch \"$branch\"" + else + echo >&2 "Switched to branch \"$branch\"" + fi elif test -n "$detached" then # NEEDSWORK: we would want a command to detach the HEAD -- cgit v1.2.3 From 92cf95696f0837b555d90fe6ef0ffd2b8348b4d0 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 1 Feb 2007 12:30:28 -0500 Subject: reword the detached head message a little again Seems clearer this way, to me at least. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- git-checkout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index deb479524a..97c26adba9 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -155,7 +155,7 @@ then detached="$new" if test -n "$oldbranch" then - detach_warn="Note: you are not on any branch and are at commit \"$new_name\" + detach_warn="Note: moving to \"$new_name\" which isn't a local branch If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b " -- cgit v1.2.3 From 6124aee5d903150a649a75bf51a68b4bdfd67140 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 1 Feb 2007 12:31:26 -0500 Subject: add a quiet option to git-checkout Those new messages are certainly nice, but there might be cases where they are simply unwelcome, like when git-commit is used within scripts. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- git-checkout.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index 97c26adba9..99a81f509a 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -1,6 +1,6 @@ #!/bin/sh -USAGE='[-f] [-b ] [-m] [] [...]' +USAGE='[-q] [-f] [-b ] [-m] [] [...]' SUBDIRECTORY_OK=Sometimes . git-sh-setup require_work_tree @@ -15,6 +15,7 @@ branch= newbranch= newbranch_log= merge= +quiet= LF=' ' while [ "$#" != "0" ]; do @@ -40,6 +41,9 @@ while [ "$#" != "0" ]; do -m) merge=1 ;; + "-q") + quiet=1 + ;; --) break ;; @@ -153,7 +157,7 @@ detach_warn= if test -z "$branch$newbranch" && test "$new" != "$old" then detached="$new" - if test -n "$oldbranch" + if test -n "$oldbranch" && test -z "$quiet" then detach_warn="Note: moving to \"$new_name\" which isn't a local branch If you want to create a new branch from this checkout, you may do so @@ -180,8 +184,11 @@ fi if [ "X$old" = X ] then - echo >&2 "warning: You appear to be on a branch yet to be born." - echo >&2 "warning: Forcing checkout of $new_name." + if test -z "$quiet" + then + echo >&2 "warning: You appear to be on a branch yet to be born." + echo >&2 "warning: Forcing checkout of $new_name." + fi force=1 fi @@ -226,7 +233,7 @@ else exit 0 ) saved_err=$? - if test "$saved_err" = 0 + if test "$saved_err" = 0 && test -z "$quiet" then git diff-index --name-status "$new" fi @@ -251,11 +258,9 @@ if [ "$?" -eq 0 ]; then if test -n "$branch" then GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD "refs/heads/$branch" - if test -n "$newbranch" + if test -z "$quiet" then - echo >&2 "Switched to a new branch \"$branch\"" - else - echo >&2 "Switched to branch \"$branch\"" + echo >&2 "Switched to${newbranch:+ a new} branch \"$branch\"" fi elif test -n "$detached" then -- cgit v1.2.3