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

Re: [PATCH] backfill: handle unexpected arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2026, 04:42 UTC
Message-ID
<xmqqtsu9dc9m.fsf@gitster.g>
In-Reply-To
<20260321031643.5185-1-r.siddharth.shrimali@gmail.com>
Siddharth Shrimali <r.siddharth.shrimali@gmail.com> writes:
> 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 currently ignores them silently,
> giving the user no indication that something is wrong.

Well written. If you drop unnecessary "currently", it would be perfect ;-).

> Add a check after parse_options() to call usage_with_options()
> if any unexpected arguments remain. This prints the correct usage
> and exits with an error, consistent with how other Git commands
> such as git-gc and git-repack handle this situation.
I am not sure if this is a good idea.

When parse_options() finds an unrecognised option, you would get usage-with-options help, so without explicitly telling the user "Hey, you have an extra argument that I do not expect at the end of the command line" and giving only the same usage-with-options help, the user would not know why they are seeing the help message, as it is totally unclear what mistake they made in their command line.

"git bugreport" is also a command that does not take any positional arguments on its command line. Study how it complains about an unwanted argument, and follow its example, perhaps?

Thanks.
Show 18 quoted lines
> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
> ---
>  builtin/backfill.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/builtin/backfill.c b/builtin/backfill.c
> index e9a33e81be..0eb171478a 100644
> --- a/builtin/backfill.c
> +++ b/builtin/backfill.c
> @@ -135,6 +135,9 @@ 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)
> +		usage_with_options(builtin_backfill_usage, options);
>  
>  	repo_config(repo, git_default_config, NULL);
Previous: Siddharth ShrimaliNext: Junio C Hamano
Message 2 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.