Skip to content

Commit ee233f2

Browse files
SiddharthShrimaligitster
authored andcommitted
backfill: handle unexpected arguments
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6e8d538 commit ee233f2

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

builtin/backfill.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit
136136
argc = parse_options(argc, argv, prefix, options, builtin_backfill_usage,
137137
0);
138138

139+
if (argc) {
140+
error(_("unknown argument '%s'"), argv[0]);
141+
usage(builtin_backfill_usage[0]);
142+
}
143+
139144
repo_config(repo, git_default_config, NULL);
140145

141146
if (ctx.sparse < 0)

t/t5620-backfill.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ test_expect_success 'backfill --sparse without cone mode (negative)' '
176176
test_line_count = 12 missing
177177
'
178178

179+
test_expect_success 'backfill rejects unexpected arguments' '
180+
test_must_fail git -C backfill1 backfill unexpected-arg >err 2>&1 &&
181+
grep "unknown argument .*unexpected-arg" err &&
182+
! grep "Minimum number of objects" err
183+
'
184+
179185
. "$TEST_DIRECTORY"/lib-httpd.sh
180186
start_httpd
181187

0 commit comments

Comments
 (0)