Skip to content

Commit

Permalink
builtin-checkout: Don't tell user that HEAD has moved before it has
Browse files Browse the repository at this point in the history
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 <theappleman@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Daniel Cordero authored and Junio C Hamano committed May 16, 2009
1 parent c646217 commit 77ebd56
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions builtin-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,6 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
parse_commit(new->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 (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
describe_detached_head("Previous HEAD position was", old.commit);

if (!old.commit && !opts->force) {
if (!opts->quiet) {
warning("You appear to be on a branch yet to be born.");
Expand All @@ -561,6 +553,14 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
if (ret)
return ret;

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

update_refs_for_switch(opts, &old, new);

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

0 comments on commit 77ebd56

Please sign in to comment.