Skip to content

Commit

Permalink
checkout: fix message when leaving detached HEAD
Browse files Browse the repository at this point in the history
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@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 3, 2008
1 parent 44a68fd commit bea005e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions builtin-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bea005e

Please sign in to comment.