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

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

From
Øystein Walle <oystwa@gmail.com>
Date
May 5, 2021, 14:52 UTC
Message-ID
<20210505145204.51614-1-oystwa@gmail.com>

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

Signed-off-by: Øystein Walle <oystwa@gmail.com>
---
I think a better solution would be to allow this and improve the
interactive machinery to handle --dry-run. This is what I could muster
up at the moment.
 builtin/add.c  | 2 ++
 t/t3700-add.sh | 4 ++++
 2 files changed, 6 insertions(+)
diff --git a/builtin/add.c b/builtin/add.c
index ea762a41e3..6077eb189f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -457,6 +457,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));
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index b3b122ff97..171b323f50 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -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 ""
 '
-- 
2.27.0
Next: ZheNing Hu
Message 1 of 4 in “add: die if both --dry-run and --interactive are given”
  1. add: die if both --dry-run and --interactive are givenØystein Walle, May 5, 2021
  2. ZheNing HuMay 6, 2021
  3. Øystein WalleMay 6, 2021
  4. Junio C HamanoMay 6, 2021

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.