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>

Øystein Walle committed May 5, 2021 at 16:52 UTC a1989cf7b8d062960b6f8de00435711c45b95285
2 files changed +6
builtin/add.c
+2
@@ -459,6 +459,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
459 if (patch_interactive)
460 add_interactive = 1;
461 if (add_interactive) {
462 + if (show_only)
463 + die(_("--dry-run is incompatible with --interactive/--patch"));
464 if (pathspec_from_file)
465 die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
466 exit(interactive_add(argv + 1, prefix, patch_interactive));
t/t3700-add.sh
+4
@@ -343,6 +343,10 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
343 test_cmp expect.err actual.err
344 '
345
346 +test_expect_success 'git add --dry-run --interactive should fail' '
347 + test_must_fail git add --dry-run --interactive
348 +'
349 +
350 test_expect_success 'git add empty string should fail' '
351 test_must_fail git add ""
352 '