{"thread":{"id":"55721","subject":"[PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given","startedAt":"2021-05-18T08:15:50Z","lastAt":"2021-05-19T22:17:57Z","messageCount":4,"participants":["Denton Liu","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"424843","messageId":"76dfa90a32ae926f7477d5966109f81441eb2783.1621325684.git.liu.denton@gmail.com","threadId":"55721","inReplyTo":null,"subject":"[PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2021-05-18T08:15:38Z","receivedAt":"2021-05-18T08:15:50Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"When `git stash show` is given no arguments, it will pass `--stat` to\n`git diff` by default. When any argument is given, `--stat` is no longer\npassed by default.\n\nWhen `git stash show` learned the `--include-untracked` and\n`--only-untracked` options, it failed to retain the same behaviour of\nnot passing `--stat` by default.\n\nThis isn't necessarily incorrect since with other arguments, they're\npassed through directly to `git diff` which means it wouldn't make sense\nto pass `--stat` as well. With `--include-untracked` and\n`--only-untracked`, they are handled by `git stash show` directly\nmeaning we don't necessarily have this conflict. However, this would be\nunintuitive for users since the existing behaviour seems to be that if\nany arguments are given, `--stat` will not be given by default.\n\nDon't setup the default diff output format if `--include-untracked` or\n`--only-untracked` are given.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\nThis is based on 'dl/stash-show-untracked-fixup'.\n\n builtin/stash.c                    |  3 +-\n t/t3903-stash.sh                   | 18 ++++++++++++\n t/t3905-stash-include-untracked.sh | 46 +++++++++++-------------------\n 3 files changed, 37 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin/stash.c b/builtin/stash.c\nindex 82e4829d44..675261b7f5 100644\n--- a/builtin/stash.c\n+++ b/builtin/stash.c\n@@ -841,6 +841,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)\n \t\t\t      UNTRACKED_ONLY, PARSE_OPT_NONEG),\n \t\tOPT_END()\n \t};\n+\tint old_argc = argc;\n \n \tinit_diff_ui_defaults();\n \tgit_config(git_diff_ui_config, NULL);\n@@ -867,7 +868,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)\n \t * The config settings are applied only if there are not passed\n \t * any options.\n \t */\n-\tif (revision_args.nr == 1) {\n+\tif (revision_args.nr == 1 && argc == old_argc) {\n \t\tif (show_stat)\n \t\t\trev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT;\n \ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 84b039e573..5bc286e251 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -655,6 +655,24 @@ test_expect_success 'stash show --patience shows diff' '\n \tdiff_cmp expected actual\n '\n \n+test_expect_success 'stash show --include-untracked shows diff' '\n+\tgit reset --hard &&\n+\techo foo >>file &&\n+\tSTASH_ID=$(git stash create) &&\n+\tgit reset --hard &&\n+\tcat >expected <<-EOF &&\n+\tdiff --git a/file b/file\n+\tindex 7601807..71b52c4 100644\n+\t--- a/file\n+\t+++ b/file\n+\t@@ -1 +1,2 @@\n+\t baz\n+\t+foo\n+\tEOF\n+\tgit stash show --include-untracked ${STASH_ID} >actual &&\n+\tdiff_cmp expected actual\n+'\n+\n test_expect_success 'drop: fail early if specified stash is not a stash ref' '\n \tgit stash clear &&\n \ttest_when_finished \"git reset --hard HEAD && git stash clear\" &&\ndiff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh\nindex 1c9765928d..892cf7d8c9 100755\n--- a/t/t3905-stash-include-untracked.sh\n+++ b/t/t3905-stash-include-untracked.sh\n@@ -307,9 +307,12 @@ test_expect_success 'stash show --include-untracked shows untracked files' '\n \tgit stash -u &&\n \n \tcat >expect <<-EOF &&\n-\t tracked   | 0\n-\t untracked | 0\n-\t 2 files changed, 0 insertions(+), 0 deletions(-)\n+\tdiff --git a/tracked b/tracked\n+\tnew file mode 100644\n+\tindex 0000000..$empty_blob_oid\n+\tdiff --git a/untracked b/untracked\n+\tnew file mode 100644\n+\tindex 0000000..$empty_blob_oid\n \tEOF\n \tgit stash show --include-untracked >actual &&\n \ttest_cmp expect actual &&\n@@ -319,20 +322,13 @@ test_expect_success 'stash show --include-untracked shows untracked files' '\n \ttest_cmp expect actual &&\n \tgit stash show --only-untracked --include-untracked >actual &&\n \ttest_cmp expect actual &&\n-\tgit -c stash.showIncludeUntracked=true stash show >actual &&\n-\ttest_cmp expect actual &&\n \n \tcat >expect <<-EOF &&\n-\tdiff --git a/tracked b/tracked\n-\tnew file mode 100644\n-\tindex 0000000..$empty_blob_oid\n-\tdiff --git a/untracked b/untracked\n-\tnew file mode 100644\n-\tindex 0000000..$empty_blob_oid\n+\t tracked   | 0\n+\t untracked | 0\n+\t 2 files changed, 0 insertions(+), 0 deletions(-)\n \tEOF\n-\tgit stash show -p --include-untracked >actual &&\n-\ttest_cmp expect actual &&\n-\tgit stash show --include-untracked -p >actual &&\n+\tgit -c stash.showIncludeUntracked=true stash show >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -346,24 +342,15 @@ test_expect_success 'stash show --only-untracked only shows untracked files' '\n \tgit stash -u &&\n \n \tcat >expect <<-EOF &&\n-\t untracked | 0\n-\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tdiff --git a/untracked b/untracked\n+\tnew file mode 100644\n+\tindex 0000000..$empty_blob_oid\n \tEOF\n \tgit stash show --only-untracked >actual &&\n \ttest_cmp expect actual &&\n \tgit stash show --no-include-untracked --only-untracked >actual &&\n \ttest_cmp expect actual &&\n \tgit stash show --include-untracked --only-untracked >actual &&\n-\ttest_cmp expect actual &&\n-\n-\tcat >expect <<-EOF &&\n-\tdiff --git a/untracked b/untracked\n-\tnew file mode 100644\n-\tindex 0000000..$empty_blob_oid\n-\tEOF\n-\tgit stash show -p --only-untracked >actual &&\n-\ttest_cmp expect actual &&\n-\tgit stash show --only-untracked -p >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -376,8 +363,9 @@ test_expect_success 'stash show --no-include-untracked cancels --{include,only}-\n \tgit stash -u &&\n \n \tcat >expect <<-EOF &&\n-\t tracked | 0\n-\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\tdiff --git a/tracked b/tracked\n+\tnew file mode 100644\n+\tindex 0000000..$empty_blob_oid\n \tEOF\n \tgit stash show --only-untracked --no-include-untracked >actual &&\n \ttest_cmp expect actual &&\n@@ -412,7 +400,7 @@ test_expect_success 'stash show --{include,only}-untracked on stashes without un\n \tgit add tracked &&\n \tgit stash &&\n \n-\tgit stash show >expect &&\n+\tgit stash show -p >expect &&\n \tgit stash show --include-untracked >actual &&\n \ttest_cmp expect actual &&\n \n-- \n2.32.0.rc0.171.g09c0ee21fe\n\n"},{"id":"424911","messageId":"xmqq35uj1pmd.fsf@gitster.g","threadId":"55721","inReplyTo":"76dfa90a32ae926f7477d5966109f81441eb2783.1621325684.git.liu.denton@gmail.com","subject":"Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-19T01:25:30Z","receivedAt":"2021-05-19T01:25:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> When `git stash show` is given no arguments, it will pass `--stat` to\n> `git diff` by default. When any argument is given, `--stat` is no longer\n> passed by default.\n>\n> When `git stash show` learned the `--include-untracked` and\n> `--only-untracked` options, it failed to retain the same behaviour of\n> not passing `--stat` by default.\n>\n> This isn't necessarily incorrect since with other arguments, they're\n> passed through directly to `git diff` which means it wouldn't make sense\n> to pass `--stat` as well. With `--include-untracked` and\n> `--only-untracked`, they are handled by `git stash show` directly\n> meaning we don't necessarily have this conflict. However, this would be\n> unintuitive for users since the existing behaviour seems to be that if\n> any arguments are given, `--stat` will not be given by default.\n\nBut even for users who do not care about the implementation, the\noptions that affect \"What to show\" and \"How to show them\" are easily\ndistinguishable at the conceptual level, no?  When showing stash\nwithout telling the command what or how to show, we omit untracked\npart by default, and we show only diffstat by default.  When we tell\nit to show also/only untracked, it is unclear if it is confusing or\nnatural to average users if that affects how the chosen part of the\nstash gets shown.\n\nShowing untracked will be a new feature in the upcoming release, so\nwe may want to either (1) revert the whole thing before we can agree\non the desired behaviour or (2) clarify in the document that what to\nshow and how to show them are two orthogonal axes with their own\ndefault that are orthogonal to avoid the \"confusion\" you are trying\nto address with this patch.\n\n"},{"id":"424926","messageId":"YKTZIOOe+IW41MXp@generichostname","threadId":"55721","inReplyTo":"xmqq35uj1pmd.fsf@gitster.g","subject":"Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2021-05-19T09:23:44Z","receivedAt":"2021-05-19T09:23:49Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Hi Junio,\n\nOn Wed, May 19, 2021 at 10:25:30AM +0900, Junio C Hamano wrote:\n> Denton Liu <liu.denton@gmail.com> writes:\n> \n> > When `git stash show` is given no arguments, it will pass `--stat` to\n> > `git diff` by default. When any argument is given, `--stat` is no longer\n> > passed by default.\n> >\n> > When `git stash show` learned the `--include-untracked` and\n> > `--only-untracked` options, it failed to retain the same behaviour of\n> > not passing `--stat` by default.\n> >\n> > This isn't necessarily incorrect since with other arguments, they're\n> > passed through directly to `git diff` which means it wouldn't make sense\n> > to pass `--stat` as well. With `--include-untracked` and\n> > `--only-untracked`, they are handled by `git stash show` directly\n> > meaning we don't necessarily have this conflict. However, this would be\n> > unintuitive for users since the existing behaviour seems to be that if\n> > any arguments are given, `--stat` will not be given by default.\n> \n> But even for users who do not care about the implementation, the\n> options that affect \"What to show\" and \"How to show them\" are easily\n> distinguishable at the conceptual level, no?  When showing stash\n> without telling the command what or how to show, we omit untracked\n> part by default, and we show only diffstat by default.  When we tell\n> it to show also/only untracked, it is unclear if it is confusing or\n> natural to average users if that affects how the chosen part of the\n> stash gets shown.\n> \n> Showing untracked will be a new feature in the upcoming release, so\n> we may want to either (1) revert the whole thing before we can agree\n> on the desired behaviour or (2) clarify in the document that what to\n> show and how to show them are two orthogonal axes with their own\n> default that are orthogonal to avoid the \"confusion\" you are trying\n> to address with this patch.\n\nI could be convinced either way and I was erring on the side of caution\nby proposing this patch. I'm okay with the status quo so we can keep the\nbehaviour as is, unless someone objects in which case we should revert\npending more discussion.\n\nI'll send a follow-up patch later this week clarifying the docs.\n\nThanks,\nDenton\n"},{"id":"424996","messageId":"xmqqbl96xt9q.fsf@gitster.g","threadId":"55721","inReplyTo":"YKTZIOOe+IW41MXp@generichostname","subject":"Re: [PATCH] stash show: don't setup default diff output format if --{include,only}-untracked given","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-05-19T22:17:53Z","receivedAt":"2021-05-19T22:17:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> I could be convinced either way and I was erring on the side of caution\n> by proposing this patch. I'm okay with the status quo so we can keep the\n> behaviour as is, unless someone objects in which case we should revert\n> pending more discussion.\n\nI do not know if \"--stat\" is a good default for \"git stash show\",\nwith or without \"-u\", to begin with, but if the default varies\nbetween \"git stash show\" and \"git stash show -u\", it would be like\n\"git diff\" and \"git diff HEAD\" using different defaults depending on\nwhat is being compared.  And from that point of view, I did find\nthat the patch takes the behaviour in a less consistent and more\nconfusing direction.\n\n> I'll send a follow-up patch later this week clarifying the docs.\n\nThanks.\n"}]}