]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5620: test backfill's unknown argument handling
authorDerrick Stolee <stolee@gmail.com>
Thu, 26 Mar 2026 15:14:54 +0000 (15:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2026 16:38:07 +0000 (09:38 -0700)
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>
builtin/backfill.c
t/t5620-backfill.sh

index b98b0b591fe3d10777a3659691f25220951a43cf..2c5ce56fb7ddcb5276560c4e7f249d7450bf8c0c 100644 (file)
@@ -142,6 +142,9 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
        repo_init_revisions(repo, &ctx.revs, prefix);
        argc = setup_revisions(argc, argv, &ctx.revs, NULL);
 
+       if (argc > 1)
+               die(_("unrecognized argument: %s"), argv[1]);
+
        repo_config(repo, git_default_config, NULL);
 
        if (ctx.sparse < 0)
index c6f54ee91ccc6a1fad5c5370df9ab02746d04120..2c347a91fe6d9fc21ba656bc3a2b1a0830768299 100755 (executable)
@@ -7,6 +7,14 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
+test_expect_success 'backfill rejects unexpected arguments' '
+       test_must_fail git backfill unexpected-arg 2>err &&
+       test_grep "ambiguous argument .*unexpected-arg" err &&
+
+       test_must_fail git backfill --all --unexpected-arg --first-parent 2>err &&
+       test_grep "unrecognized argument: --unexpected-arg" err
+'
+
 # We create objects in the 'src' repo.
 test_expect_success 'setup repo for object creation' '
        echo "{print \$1}" >print_1.awk &&