From: Trieu Huynh <vikingtc4@gmail.com>
To: git@vger.kernel.org
Cc: Trieu Huynh <vikingtc4@gmail.com>
Subject: [GSoC PATCH v2] backfill: error out when HEAD cannot be parsed
Date: Fri, 3 Apr 2026 02:13:58 +0700 [thread overview]
Message-ID: <20260402191359.11304-1-viking4@gmail.com> (raw)
From: Trieu Huynh <vikingtc4@gmail.com>
handle_revision_arg() returns non-zero on failure, but do_backfill()
ignores the return value. On an empty repo with no commits, HEAD is
unborn and handle_revision_arg() fails, but backfill silently
continues with an empty revision walk and exists with a zero return
code.
Check the return value and propagate the error, consistent with
how builtin/pack-objects.c handles handle_revision_arg() failures.
Add a test to verify that backfill on an empty repository fails
with a clear error message.
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
Changes in v2:
- Update commit msg (Point out by Karthik Nayak <karthik.188@gmail.com>)
- Use test_grep instead of grep (Point out by Tian Yuchen <cat@malon.dev>)
builtin/backfill.c | 3 ++-
t/t5620-backfill.sh | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/builtin/backfill.c b/builtin/backfill.c
index e9a33e81be..ca49e188df 100644
--- a/builtin/backfill.c
+++ b/builtin/backfill.c
@@ -92,7 +92,8 @@ static int do_backfill(struct backfill_context *ctx)
}
repo_init_revisions(ctx->repo, &revs, "");
- handle_revision_arg("HEAD", &revs, 0, 0);
+ if (handle_revision_arg("HEAD", &revs, 0, 0))
+ return error(_("unable to parse HEAD revision"));
info.blobs = 1;
info.tags = info.commits = info.trees = 0;
diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh
index 58c81556e7..066ee17d39 100755
--- a/t/t5620-backfill.sh
+++ b/t/t5620-backfill.sh
@@ -77,6 +77,12 @@ test_expect_success 'do partial clone 2, backfill min batch size' '
test_line_count = 0 revs2
'
+test_expect_success 'backfill on empty repo fails gracefully' '
+ git init empty-repo &&
+ test_must_fail git -C empty-repo backfill 2>err &&
+ test_grep "unable to parse HEAD" err
+'
+
test_expect_success 'backfill --sparse without sparse-checkout fails' '
git init not-sparse &&
test_must_fail git -C not-sparse backfill --sparse 2>err &&
--
2.43.0
next reply other threads:[~2026-04-02 19:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 19:13 Trieu Huynh [this message]
2026-04-02 19:56 ` [GSoC PATCH v2] backfill: error out when HEAD cannot be parsed Junio C Hamano
2026-04-02 20:09 ` Junio C Hamano
2026-04-03 17:24 ` Trieu Huynh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260402191359.11304-1-viking4@gmail.com \
--to=vikingtc4@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox