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@xxxxxxxxx> --- 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