On Wed, Sep 03, 2008 at 12:49:43PM -0400, Daniel Barkalow wrote: > Good point. I think I confused myself with the new branch case. On the > other hand, I think the "not starting a new branch" case should go as > well. If you've got a detached HEAD, and you do: > > $ git checkout -b foo origin/master > > we probably ought to describe the old state. The reason that starting a > new branch usually shouldn't give the message is that new->commit == > old.commit (assuming that the defaults have gotten filled in by this > point, which they should have). Right, I was thinking it was necessary for the starting a new branch case, but a better test is checking whether the commits are the same. So based on what you said and thinking a bit, I came up with: if (!opts->quiet && !old.path && new->commit != old.commit) and then I had the brilliant idea of checking what git-checkout.sh did. And sure enough: elif test -z "$oldbranch" && test "$new" != "$old" then describe_detached_head 'Previous HEAD position was' "$old" fi Patch is below. -- >8 -- checkout: fix message when leaving detached HEAD The shell version of git checkout would print: Previous HEAD position was 1234abcd... commit subject line when leaving a detached HEAD for another commit. Ths C version attempted to implement this, but got the condition wrong such that the behavior never triggered. This patch simplifies the conditions for showing the message to the ones used by the shell version: any time we are leaving a detached HEAD and the new and old commits are not the same (this suppresses it for the "git checkout -b new" case recommended when you enter the detached state). Signed-off-by: Jeff King <peff@xxxxxxxx> --- builtin-checkout.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-) diff --git a/builtin-checkout.c b/builtin-checkout.c index b380ad6..efdb1e0 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -386,13 +386,11 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new) } /* - * If the new thing isn't a branch and isn't HEAD and we're - * not starting a new branch, and we want messages, and we - * weren't on a branch, and we're moving to a new commit, - * describe the old commit. + * If we were on a detached HEAD, but we are now moving to + * a new commit, we want to mention the old commit once more + * to remind the user that it might be lost. */ - if (!new->path && strcmp(new->name, "HEAD") && !opts->new_branch && - !opts->quiet && !old.path && new->commit != old.commit) + if (!opts->quiet && !old.path && new->commit != old.commit) describe_detached_head("Previous HEAD position was", old.commit); if (!old.commit) { -- 1.6.0.1.208.gcc04.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html