git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given
@ 2021-05-18  8:15 Denton Liu
  2021-05-19  1:25 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Denton Liu @ 2021-05-18  8:15 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Eric Sunshine

When `git stash show` is given no arguments, it will pass `--stat` to
`git diff` by default. When any argument is given, `--stat` is no longer
passed by default.

When `git stash show` learned the `--include-untracked` and
`--only-untracked` options, it failed to retain the same behaviour of
not passing `--stat` by default.

This isn't necessarily incorrect since with other arguments, they're
passed through directly to `git diff` which means it wouldn't make sense
to pass `--stat` as well. With `--include-untracked` and
`--only-untracked`, they are handled by `git stash show` directly
meaning we don't necessarily have this conflict. However, this would be
unintuitive for users since the existing behaviour seems to be that if
any arguments are given, `--stat` will not be given by default.

Don't setup the default diff output format if `--include-untracked` or
`--only-untracked` are given.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
This is based on 'dl/stash-show-untracked-fixup'.

 builtin/stash.c                    |  3 +-
 t/t3903-stash.sh                   | 18 ++++++++++++
 t/t3905-stash-include-untracked.sh | 46 +++++++++++-------------------
 3 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/builtin/stash.c b/builtin/stash.c
index 82e4829d44..675261b7f5 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -841,6 +841,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
 			      UNTRACKED_ONLY, PARSE_OPT_NONEG),
 		OPT_END()
 	};
+	int old_argc = argc;
 
 	init_diff_ui_defaults();
 	git_config(git_diff_ui_config, NULL);
@@ -867,7 +868,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
 	 * The config settings are applied only if there are not passed
 	 * any options.
 	 */
-	if (revision_args.nr == 1) {
+	if (revision_args.nr == 1 && argc == old_argc) {
 		if (show_stat)
 			rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT;
 
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 84b039e573..5bc286e251 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -655,6 +655,24 @@ test_expect_success 'stash show --patience shows diff' '
 	diff_cmp expected actual
 '
 
+test_expect_success 'stash show --include-untracked shows diff' '
+	git reset --hard &&
+	echo foo >>file &&
+	STASH_ID=$(git stash create) &&
+	git reset --hard &&
+	cat >expected <<-EOF &&
+	diff --git a/file b/file
+	index 7601807..71b52c4 100644
+	--- a/file
+	+++ b/file
+	@@ -1 +1,2 @@
+	 baz
+	+foo
+	EOF
+	git stash show --include-untracked ${STASH_ID} >actual &&
+	diff_cmp expected actual
+'
+
 test_expect_success 'drop: fail early if specified stash is not a stash ref' '
 	git stash clear &&
 	test_when_finished "git reset --hard HEAD && git stash clear" &&
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 1c9765928d..892cf7d8c9 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -307,9 +307,12 @@ test_expect_success 'stash show --include-untracked shows untracked files' '
 	git stash -u &&
 
 	cat >expect <<-EOF &&
-	 tracked   | 0
-	 untracked | 0
-	 2 files changed, 0 insertions(+), 0 deletions(-)
+	diff --git a/tracked b/tracked
+	new file mode 100644
+	index 0000000..$empty_blob_oid
+	diff --git a/untracked b/untracked
+	new file mode 100644
+	index 0000000..$empty_blob_oid
 	EOF
 	git stash show --include-untracked >actual &&
 	test_cmp expect actual &&
@@ -319,20 +322,13 @@ test_expect_success 'stash show --include-untracked shows untracked files' '
 	test_cmp expect actual &&
 	git stash show --only-untracked --include-untracked >actual &&
 	test_cmp expect actual &&
-	git -c stash.showIncludeUntracked=true stash show >actual &&
-	test_cmp expect actual &&
 
 	cat >expect <<-EOF &&
-	diff --git a/tracked b/tracked
-	new file mode 100644
-	index 0000000..$empty_blob_oid
-	diff --git a/untracked b/untracked
-	new file mode 100644
-	index 0000000..$empty_blob_oid
+	 tracked   | 0
+	 untracked | 0
+	 2 files changed, 0 insertions(+), 0 deletions(-)
 	EOF
-	git stash show -p --include-untracked >actual &&
-	test_cmp expect actual &&
-	git stash show --include-untracked -p >actual &&
+	git -c stash.showIncludeUntracked=true stash show >actual &&
 	test_cmp expect actual
 '
 
@@ -346,24 +342,15 @@ test_expect_success 'stash show --only-untracked only shows untracked files' '
 	git stash -u &&
 
 	cat >expect <<-EOF &&
-	 untracked | 0
-	 1 file changed, 0 insertions(+), 0 deletions(-)
+	diff --git a/untracked b/untracked
+	new file mode 100644
+	index 0000000..$empty_blob_oid
 	EOF
 	git stash show --only-untracked >actual &&
 	test_cmp expect actual &&
 	git stash show --no-include-untracked --only-untracked >actual &&
 	test_cmp expect actual &&
 	git stash show --include-untracked --only-untracked >actual &&
-	test_cmp expect actual &&
-
-	cat >expect <<-EOF &&
-	diff --git a/untracked b/untracked
-	new file mode 100644
-	index 0000000..$empty_blob_oid
-	EOF
-	git stash show -p --only-untracked >actual &&
-	test_cmp expect actual &&
-	git stash show --only-untracked -p >actual &&
 	test_cmp expect actual
 '
 
@@ -376,8 +363,9 @@ test_expect_success 'stash show --no-include-untracked cancels --{include,only}-
 	git stash -u &&
 
 	cat >expect <<-EOF &&
-	 tracked | 0
-	 1 file changed, 0 insertions(+), 0 deletions(-)
+	diff --git a/tracked b/tracked
+	new file mode 100644
+	index 0000000..$empty_blob_oid
 	EOF
 	git stash show --only-untracked --no-include-untracked >actual &&
 	test_cmp expect actual &&
@@ -412,7 +400,7 @@ test_expect_success 'stash show --{include,only}-untracked on stashes without un
 	git add tracked &&
 	git stash &&
 
-	git stash show >expect &&
+	git stash show -p >expect &&
 	git stash show --include-untracked >actual &&
 	test_cmp expect actual &&
 
-- 
2.32.0.rc0.171.g09c0ee21fe


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

* Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given
  2021-05-18  8:15 [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given Denton Liu
@ 2021-05-19  1:25 ` Junio C Hamano
  2021-05-19  9:23   ` Denton Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2021-05-19  1:25 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine

Denton Liu <liu.denton@gmail.com> writes:

> When `git stash show` is given no arguments, it will pass `--stat` to
> `git diff` by default. When any argument is given, `--stat` is no longer
> passed by default.
>
> When `git stash show` learned the `--include-untracked` and
> `--only-untracked` options, it failed to retain the same behaviour of
> not passing `--stat` by default.
>
> This isn't necessarily incorrect since with other arguments, they're
> passed through directly to `git diff` which means it wouldn't make sense
> to pass `--stat` as well. With `--include-untracked` and
> `--only-untracked`, they are handled by `git stash show` directly
> meaning we don't necessarily have this conflict. However, this would be
> unintuitive for users since the existing behaviour seems to be that if
> any arguments are given, `--stat` will not be given by default.

But even for users who do not care about the implementation, the
options that affect "What to show" and "How to show them" are easily
distinguishable at the conceptual level, no?  When showing stash
without telling the command what or how to show, we omit untracked
part by default, and we show only diffstat by default.  When we tell
it to show also/only untracked, it is unclear if it is confusing or
natural to average users if that affects how the chosen part of the
stash gets shown.

Showing untracked will be a new feature in the upcoming release, so
we may want to either (1) revert the whole thing before we can agree
on the desired behaviour or (2) clarify in the document that what to
show and how to show them are two orthogonal axes with their own
default that are orthogonal to avoid the "confusion" you are trying
to address with this patch.


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

* Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given
  2021-05-19  1:25 ` Junio C Hamano
@ 2021-05-19  9:23   ` Denton Liu
  2021-05-19 22:17     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Denton Liu @ 2021-05-19  9:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine

Hi Junio,

On Wed, May 19, 2021 at 10:25:30AM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > When `git stash show` is given no arguments, it will pass `--stat` to
> > `git diff` by default. When any argument is given, `--stat` is no longer
> > passed by default.
> >
> > When `git stash show` learned the `--include-untracked` and
> > `--only-untracked` options, it failed to retain the same behaviour of
> > not passing `--stat` by default.
> >
> > This isn't necessarily incorrect since with other arguments, they're
> > passed through directly to `git diff` which means it wouldn't make sense
> > to pass `--stat` as well. With `--include-untracked` and
> > `--only-untracked`, they are handled by `git stash show` directly
> > meaning we don't necessarily have this conflict. However, this would be
> > unintuitive for users since the existing behaviour seems to be that if
> > any arguments are given, `--stat` will not be given by default.
> 
> But even for users who do not care about the implementation, the
> options that affect "What to show" and "How to show them" are easily
> distinguishable at the conceptual level, no?  When showing stash
> without telling the command what or how to show, we omit untracked
> part by default, and we show only diffstat by default.  When we tell
> it to show also/only untracked, it is unclear if it is confusing or
> natural to average users if that affects how the chosen part of the
> stash gets shown.
> 
> Showing untracked will be a new feature in the upcoming release, so
> we may want to either (1) revert the whole thing before we can agree
> on the desired behaviour or (2) clarify in the document that what to
> show and how to show them are two orthogonal axes with their own
> default that are orthogonal to avoid the "confusion" you are trying
> to address with this patch.

I could be convinced either way and I was erring on the side of caution
by proposing this patch. I'm okay with the status quo so we can keep the
behaviour as is, unless someone objects in which case we should revert
pending more discussion.

I'll send a follow-up patch later this week clarifying the docs.

Thanks,
Denton

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

* Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given
  2021-05-19  9:23   ` Denton Liu
@ 2021-05-19 22:17     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2021-05-19 22:17 UTC (permalink / raw)
  To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine

Denton Liu <liu.denton@gmail.com> writes:

> I could be convinced either way and I was erring on the side of caution
> by proposing this patch. I'm okay with the status quo so we can keep the
> behaviour as is, unless someone objects in which case we should revert
> pending more discussion.

I do not know if "--stat" is a good default for "git stash show",
with or without "-u", to begin with, but if the default varies
between "git stash show" and "git stash show -u", it would be like
"git diff" and "git diff HEAD" using different defaults depending on
what is being compared.  And from that point of view, I did find
that the patch takes the behaviour in a less consistent and more
confusing direction.

> I'll send a follow-up patch later this week clarifying the docs.

Thanks.

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

end of thread, other threads:[~2021-05-19 22:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18  8:15 [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given Denton Liu
2021-05-19  1:25 ` Junio C Hamano
2021-05-19  9:23   ` Denton Liu
2021-05-19 22:17     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).