git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] backfill: handle unexpected arguments

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Mar 22, 2026, 05:32 UTC
Message-ID
<20260322053207.60992-1-r.siddharth.shrimali@gmail.com>
In-Reply-To
<xmqqfr5sacps.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 report an error if any unexpected arguments remain. To ensure the user understands why the command failed, print an error message specifying the unknown argument followed by the short usage string. This matches the behavior of other Git commands such as git bugreport.

Also, add a test in t5620 to ensure the unexpected arguments are rejected with the correct error message and that the full option descriptions are not printed.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
Changes since v2:
- Replaced the backtick (`%s') with standard single quotes ('%s').
- Swapped `usage_with_options()` for `usage(builtin_backfill_usage[0])` 
  so the user only sees the short usage string instead of the full 
  option descriptions.
- Updated the test to also verify that the full option descriptions 
  are not printed.
 builtin/backfill.c  | 5 +++++
 t/t5620-backfill.sh | 6 ++++++
 2 files changed, 11 insertions(+)
diff --git a/builtin/backfill.c b/builtin/backfill.c
index e9a33e81be..6d90db3da0 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(builtin_backfill_usage[0]);
+	}
 
 	repo_config(repo, git_default_config, NULL);
 
diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh
index 58c81556e7..3f1eeb67e8 100755
--- a/t/t5620-backfill.sh
+++ b/t/t5620-backfill.sh
@@ -176,6 +176,12 @@ 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 >err 2>&1 &&
+	grep "unknown argument .*unexpected-arg" err &&
+	! grep "Minimum number of objects" err
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
-- 
2.51.2
Previous: Junio C HamanoNext: Phillip Wood
Message 6 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.