Skip to content

Commit 3c62183

Browse files
peffgitster
authored andcommitted
checkout: do not die when leaving broken detached HEAD
If we move away from a detached HEAD that has broken or corrupted commits, we might die in two places: 1. Printing the "old HEAD was..." message. 2. Printing the list of orphaned commits. In both cases, we ignore the return value of parse_commit and feed the resulting commit to the pretty-print machinery, which will die() upon failing to read the commit object itself. Since both cases are ancillary to the real operation being performed, let's be more robust and keep going. This lets users more easily checkout away from broken history. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 367068e commit 3c62183

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/checkout.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ static void show_local_changes(struct object *head,
387387
static void describe_detached_head(const char *msg, struct commit *commit)
388388
{
389389
struct strbuf sb = STRBUF_INIT;
390-
parse_commit(commit);
391-
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
390+
if (!parse_commit(commit))
391+
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
392392
fprintf(stderr, "%s %s... %s\n", msg,
393393
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
394394
strbuf_release(&sb);
@@ -684,12 +684,12 @@ static int add_pending_uninteresting_ref(const char *refname,
684684

685685
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
686686
{
687-
parse_commit(commit);
688687
strbuf_addstr(sb, " ");
689688
strbuf_addstr(sb,
690689
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
691690
strbuf_addch(sb, ' ');
692-
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
691+
if (!parse_commit(commit))
692+
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
693693
strbuf_addch(sb, '\n');
694694
}
695695

0 commit comments

Comments
 (0)