Skip to content

Commit 77ebd56

Browse files
Daniel Corderogitster
authored andcommitted
builtin-checkout: Don't tell user that HEAD has moved before it has
Previously, checkout would tell the user this message before moving HEAD, without regard to whether the upcoming move will result in success. If the move failed, this causes confusion. Show the message after the move, unless the move failed. Signed-off-by: Daniel Cordero <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c646217 commit 77ebd56

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin-checkout.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,6 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
541541
parse_commit(new->commit);
542542
}
543543

544-
/*
545-
* If we were on a detached HEAD, but we are now moving to
546-
* a new commit, we want to mention the old commit once more
547-
* to remind the user that it might be lost.
548-
*/
549-
if (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
550-
describe_detached_head("Previous HEAD position was", old.commit);
551-
552544
if (!old.commit && !opts->force) {
553545
if (!opts->quiet) {
554546
warning("You appear to be on a branch yet to be born.");
@@ -561,6 +553,14 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
561553
if (ret)
562554
return ret;
563555

556+
/*
557+
* If we were on a detached HEAD, but have now moved to
558+
* a new commit, we want to mention the old commit once more
559+
* to remind the user that it might be lost.
560+
*/
561+
if (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
562+
describe_detached_head("Previous HEAD position was", old.commit);
563+
564564
update_refs_for_switch(opts, &old, new);
565565

566566
ret = post_checkout_hook(old.commit, new->commit, 1);

0 commit comments

Comments
 (0)