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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 24, 2013 at 04:54 UTC
3c62183929080c17299d5b404eb092e3d53c161a
1 file changed
+4
-4
builtin/checkout.c
+4
-4
@@ -387,8 +387,8 @@ static void show_local_changes(struct object *head,
387
static void describe_detached_head(const char *msg, struct commit *commit)
388
{
389
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);
392
fprintf(stderr, "%s %s... %s\n", msg,
393
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
394
strbuf_release(&sb);
@@ -684,12 +684,12 @@ static int add_pending_uninteresting_ref(const char *refname,
684
685
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
686
{
687
- parse_commit(commit);
687
strbuf_addstr(sb, " ");
688
strbuf_addstr(sb,
689
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
690
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);
693
strbuf_addch(sb, '\n');
694
}
695