add: die if both --dry-run and --interactive are given

The interactive machinery does not obey --dry-run. Die appropriately
if both flags are passed.

Signed-off-by: Øystein Walle <oystwa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Øystein Walle 2021-05-05 16:52:04 +02:00 committed by Junio C Hamano
parent 7e39198978
commit a1989cf7b8
2 changed files with 6 additions and 0 deletions

View File

@ -459,6 +459,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (patch_interactive)
add_interactive = 1;
if (add_interactive) {
if (show_only)
die(_("--dry-run is incompatible with --interactive/--patch"));
if (pathspec_from_file)
die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
exit(interactive_add(argv + 1, prefix, patch_interactive));

View File

@ -343,6 +343,10 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
test_cmp expect.err actual.err
'
test_expect_success 'git add --dry-run --interactive should fail' '
test_must_fail git add --dry-run --interactive
'
test_expect_success 'git add empty string should fail' '
test_must_fail git add ""
'