git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:55 UTC

[PATCH v2] backfill: handle unexpected arguments

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Mar 21, 2026, 17:47 UTC
Message-ID
<20260321174730.34762-1-r.siddharth.shrimali@gmail.com>
In-Reply-To
<xmqq341tdbal.fsf@gitster.g>

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 <gitster@pobox.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 12 in “backfill: handle unexpected arguments”
  1. backfill: handle unexpected argumentsSiddharth Shrimali, Mar 21, 2026
  2. Junio C HamanoMar 21, 2026
  3. Junio C HamanoMar 21, 2026
  4. backfill: handle unexpected argumentsSiddharth Shrimali, Mar 21, 2026
  5. Junio C HamanoMar 22, 2026
  6. backfill: handle unexpected argumentsSiddharth Shrimali, Mar 22, 2026
  7. Phillip WoodMar 22, 2026
  8. Junio C HamanoMar 22, 2026
  9. Derrick StoleeMar 22, 2026
  10. Junio C HamanoMar 23, 2026
  11. Derrick StoleeMar 23, 2026
  12. Siddharth ShrimaliMar 23, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.