[PATCH] tone down the detached head warning

Previous thread: Re: More precise tag following by Jakub Narebski on Wednesday, January 31, 2007 - 10:35 am. (1 message)

Next thread: git-kill: rewrite history removing a commit by Michael S. Tsirkin on Wednesday, January 31, 2007 - 12:55 pm. (5 messages)
From: Nicolas Pitre
Date: Wednesday, January 31, 2007 - 12:10 pm

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 <nico@cam.org>

---

diff --git a/git-checkout.sh b/git-checkout.sh
index 8500f51..0bae86e 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 <new_branch_name>"
 	fi
 elif test -z "$oldbranch" && test -n "$branch"
-

From: Jeff King
Date: Wednesday, January 31, 2007 - 4:19 pm

I like this much better. Though I wonder in Carl's case if we can do
even better, since the user is checking out a tracking branch. Does it
really make sense to say "you are not on ANY branch"? Maybe instead:

-- >8 --
git-checkout: note use of remote tracking branch when making detached warning

---
Carl, can you comment? Does this require more explanation about why it
matters that you're on a remote tracking branch?

 git-checkout.sh |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/git-checkout.sh b/git-checkout.sh
index ed04815..68533a1 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -14,6 +14,7 @@ force=
 branch=
 newbranch=
 newbranch_log=
+detached_remote=
 merge=
 LF='
 '
@@ -58,6 +59,9 @@ while [ "$#" != "0" ]; do
 			if git-show-ref --verify --quiet -- "refs/heads/$arg"
 			then
 				branch="$arg"
+			elif git-show-ref --verify --quiet -- "refs/remotes/$arg"
+			then
+				detached_remote="$arg"
 			fi
 		elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)
 		then
@@ -155,7 +159,11 @@ then
 	detached="$new"
 	if test -n "$oldbranch"
 	then
-		detach_warn="Note: you are not on ANY branch anymore.
+		case "$detached_remote" in
+		  "") detach_warn="Note: you are not on ANY branch anymore." ;;
+		   *) detach_warn="Note: you are on the remote tracking branch '$detached_remote'" ;;
+		esac
+		detach_warn="$detach_warn
 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 <new_branch_name>"
-- 
1.5.0.rc2.587.gbedb-dirty

-

From: Carl Worth
Date: Wednesday, January 31, 2007 - 4:54 pm

Getting rid of the word "Warning" and naming the remote-tracking
branch instead of saying "not on ANY branch", (my, why should git ever
yell like that?), are definitely improvements.

But they're fairly incremental. The fact is that the user is doing a
very simple operation here, (just checking out a state for which git
already has a name), and the user is given 3 lines of text to read and
try to understand, (what the heck is a "remote tracking branch"
anyway?). It still looks to me like the kind of thing that promotes a
"git is hard to use" conception.

But, back to the original use case that brought this up. I did botch
something in the original description. The "git clone; git checkout
origin/branch-name" case does trigger the detached head state with its
warnings. But the other alternative I showed does not:

	git fetch git://... branch-name:branch-name

Here, of course the user can use:

	git checkout branch-name

and not ever enter the "detached HEAD" state at all. So with this
usage the discussion about where and when to warn becomes moot.

But this still isn't satisfying to me as something to offer users, as
I'd really like them to be able to just "git pull" to follow
subsequent things I commit to the branch. But for that the user would
still need a bunch of configuration setup.

So it does come around to the fact that I'd like it to be easier for a
user to get all the configuration setup for a local branch that knows
which remote-tracking branch its associated with, (and this whether or
not the remote-tracking branch was configured as part of the original
clone or not).

-Carl
From: Nicolas Pitre
Date: Wednesday, January 31, 2007 - 5:11 pm

No.  This is misleading.

You are _not_ on the remote tracking branch.  You just happen to have 
checked out a commit that came from a tracking branch, but you are still 
detached from any branch at that point.


Nicolas
-

From: Jeff King
Date: Wednesday, January 31, 2007 - 8:00 pm

Sure, but that is a very subtle distinction that I doubt will make sense
to git newbies. Having them check out what they consider to be a branch
(and which is, in fact, a line of development -- just not one that you
have locally marked as a head) and responding with "you are not on ANY
branch" is a little off-putting.

Is there some text we can use that makes more sense in all situations?

I think part of the "scariness" of the message is that git-checkout does
not _usually_ produce output. I wonder if, when switching HEAD, it
usually printed "Now on branch <foo>", and for detached printed some
special variant, it would seem more natural.

-Peff
-

Previous thread: Re: More precise tag following by Jakub Narebski on Wednesday, January 31, 2007 - 10:35 am. (1 message)

Next thread: git-kill: rewrite history removing a commit by Michael S. Tsirkin on Wednesday, January 31, 2007 - 12:55 pm. (5 messages)