git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given
Date: Tue, 18 May 2021 01:15:38 -0700	[thread overview]
Message-ID: <76dfa90a32ae926f7477d5966109f81441eb2783.1621325684.git.liu.denton@gmail.com> (raw)

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


             reply	other threads:[~2021-05-18  8:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18  8:15 Denton Liu [this message]
2021-05-19  1:25 ` [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given Junio C Hamano
2021-05-19  9:23   ` Denton Liu
2021-05-19 22:17     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76dfa90a32ae926f7477d5966109f81441eb2783.1621325684.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).