git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] add: die if both --dry-run and --interactive are given
@ 2021-05-05 14:52 Øystein Walle
  2021-05-06  1:05 ` ZheNing Hu
  2021-05-06 14:10 ` Øystein Walle
  0 siblings, 2 replies; 4+ messages in thread
From: Øystein Walle @ 2021-05-05 14:52 UTC (permalink / raw)
  To: git; +Cc: Øystein Walle

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add: die if both --dry-run and --interactive are given
  2021-05-05 14:52 [PATCH] add: die if both --dry-run and --interactive are given Øystein Walle
@ 2021-05-06  1:05 ` ZheNing Hu
  2021-05-06 14:10 ` Øystein Walle
  1 sibling, 0 replies; 4+ messages in thread
From: ZheNing Hu @ 2021-05-06  1:05 UTC (permalink / raw)
  To: Øystein Walle; +Cc: Git List

Hi, Øystein Walle,

Øystein Walle <oystwa@gmail.com> 于2021年5月5日周三 下午10:53写道:
>
> 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
>

Thank you for solving this confusion of mine. For the time being,
it is an easier solution to make the two flags mutually exclusive.
But if we need to make `git add -i` support `--dry-run` in the future,
maybe we should passed the parameter `DRY_RUN` (maybe an
environment  variable) to the sub-process `git -add--interactive.perl`
and finally this feature may be implemented in `git apply`.

Reported-by: ZheNing Hu <adlternative@gmail.com>

Thanks!
--
ZheNing Hu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add: die if both --dry-run and --interactive are given
  2021-05-05 14:52 [PATCH] add: die if both --dry-run and --interactive are given Øystein Walle
  2021-05-06  1:05 ` ZheNing Hu
@ 2021-05-06 14:10 ` Øystein Walle
  2021-05-06 21:14   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Øystein Walle @ 2021-05-06 14:10 UTC (permalink / raw)
  To: oystwa, gitster; +Cc: git

Hi, Junio and thanks for accepting the patch.

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

I just noticed a minor spelling error here: "appropriate" should be
"appropriately". I can send a v2 if that's easier for you.

Øsse

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add: die if both --dry-run and --interactive are given
  2021-05-06 14:10 ` Øystein Walle
@ 2021-05-06 21:14   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2021-05-06 21:14 UTC (permalink / raw)
  To: Øystein Walle; +Cc: git

Øystein Walle <oystwa@gmail.com> writes:

> Hi, Junio and thanks for accepting the patch.
>
>> The interactive machinery does not obey --dry-run. Die appropriate if
>> both flags are passed.
>
> I just noticed a minor spelling error here: "appropriate" should be
> "appropriately". I can send a v2 if that's easier for you.

Thanks, will locally amend---no need to resend.

Thanks for contributing.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-06 21:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 14:52 [PATCH] add: die if both --dry-run and --interactive are given Øystein Walle
2021-05-06  1:05 ` ZheNing Hu
2021-05-06 14:10 ` Øystein Walle
2021-05-06 21:14   ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git