t5620: test backfill's unknown argument handling

Before the recent changes to parse rev-list arguments inside of 'git backfill', the builtin would take arbitrary arguments without complaint (and ignore them). This was noticed and a patch was sent [1] which motivates this change. [1] https://lore.kernel.org/git/20260321031643.5185-1-r.siddharth.shrimali@gmail.com/ Note that the revision machinery can output an "ambiguous argument" warning if a value not starting with '--' is found and doesn't make sense as a reference or a pathspec. For unrecognized arguments starting with '--' we need to add logic into builtin/backfill.c to catch leftover arguments. Reported-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Mar 26, 2026 at 15:14 UTC 46d1f4cf4dcb8aaf799f78410af829e149086f36
2 files changed +11
builtin/backfill.c
+3
@@ -142,6 +142,9 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
142 repo_init_revisions(repo, &ctx.revs, prefix);
143 argc = setup_revisions(argc, argv, &ctx.revs, NULL);
144
145 + if (argc > 1)
146 + die(_("unrecognized argument: %s"), argv[1]);
147 +
148 repo_config(repo, git_default_config, NULL);
149
150 if (ctx.sparse < 0)
t/t5620-backfill.sh
+8
@@ -7,6 +7,14 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 +test_expect_success 'backfill rejects unexpected arguments' '
11 + test_must_fail git backfill unexpected-arg 2>err &&
12 + test_grep "ambiguous argument .*unexpected-arg" err &&
13 +
14 + test_must_fail git backfill --all --unexpected-arg --first-parent 2>err &&
15 + test_grep "unrecognized argument: --unexpected-arg" err
16 +'
17 +
18 # We create objects in the 'src' repo.
19 test_expect_success 'setup repo for object creation' '
20 echo "{print \$1}" >print_1.awk &&