@matheusbsbs / matheus-bagliano / commits / bea005e21b
Fork 0

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@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 3, 2008 at 14:07 UTC bea005e21bf9f4f19d5e2afe538a5ba9123bdbdc
1 file changed +4 -6
builtin-checkout.c
+4 -6
@@ -386,13 +386,11 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
386 }
387
388 /*
389 - * If the new thing isn't a branch and isn't HEAD and we're
390 - * not starting a new branch, and we want messages, and we
391 - * weren't on a branch, and we're moving to a new commit,
392 - * describe the old commit.
389 + * If we were on a detached HEAD, but we are now moving to
390 + * a new commit, we want to mention the old commit once more
391 + * to remind the user that it might be lost.
392 */
394 - if (!new->path && strcmp(new->name, "HEAD") && !opts->new_branch &&
395 - !opts->quiet && !old.path && new->commit != old.commit)
393 + if (!opts->quiet && !old.path && new->commit != old.commit)
394 describe_detached_head("Previous HEAD position was", old.commit);
395
396 if (!old.commit) {