From: Siddharth Shrimali Date: Sat, 21 Mar 2026 17:47:30 GMT Subject: [PATCH v2] backfill: handle unexpected arguments Message-ID: <20260321174730.34762-1-r.siddharth.shrimali@gmail.com> In-Reply-To: git backfill takes no non-option arguments. However, if extra arguments are passed with git backfill, parse_options() leaves them in argc and the command ignores them silently, giving the user no indication that something is wrong. Add a check after parse_options() to call usage_with_options() if any unexpected arguments remain. To ensure the user understands why the command failed, print an error message specifying the unknown argument before showing the usage string. This is consistent with how other Git commands such as git-bugreport handle this situation. Also, add a test in t5620 to ensure the unexpected arguments are rejected with the correct error message. Helped-by: Junio C Hamano Signed-off-by: Siddharth Shrimali --- Changes in v2: - Dropped the word "currently" from the commit message as per Junio's feedback. - Added an `error()` call before `usage_with_options()` to state which argument was unknown, following the pattern in `git bugreport`. - Added a test case in `t5620-backfill.sh` to verify the new error output. builtin/backfill.c | 5 +++++ t/t5620-backfill.sh | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/builtin/backfill.c b/builtin/backfill.c index e9a33e81be..5a333afde0 100644 --- a/builtin/backfill.c +++ b/builtin/backfill.c @@ -135,6 +135,11 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit argc = parse_options(argc, argv, prefix, options, builtin_backfill_usage, 0); + + if (argc) { + error(_("unknown argument `%s'"), argv[0]); + usage_with_options(builtin_backfill_usage, options); + } repo_config(repo, git_default_config, NULL); diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh index 58c81556e7..d74e1be74b 100755 --- a/t/t5620-backfill.sh +++ b/t/t5620-backfill.sh @@ -176,6 +176,11 @@ test_expect_success 'backfill --sparse without cone mode (negative)' ' test_line_count = 12 missing ' +test_expect_success 'backfill rejects unexpected arguments' ' + test_must_fail git -C backfill1 backfill unexpected-arg 2>err && + grep "unknown argument .*unexpected-arg" err +' + . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd -- 2.51.2