stash show: learn stash.showIncludeUntracked

The previous commit teaches `git stash show --include-untracked`. It may be desirable for a user to be able to always enable the --include-untracked behavior. Teach the stash.showIncludeUntracked config option which allows users to do this in a similar manner to stash.showPatch. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Mar 3, 2021 at 03:16 UTC 0af760e26191acd3c5957841461ff224b80b43f7
4 files changed +17 -2
Documentation/config/stash.txt
+5
@@ -5,6 +5,11 @@ stash.useBuiltin::
5 is always used. Setting this will emit a warning, to alert any
6 remaining users that setting this now does nothing.
7
8 +stash.showIncludeUntracked::
9 + If this is set to true, the `git stash show` command without an
10 + option will show the untracked files of a stash entry. Defaults to
11 + false. See description of 'show' command in linkgit:git-stash[1].
12 +
13 stash.showPatch::
14 If this is set to true, the `git stash show` command without an
15 option will show the stash entry in patch form. Defaults to false.
Documentation/git-stash.txt
+2 -2
@@ -91,8 +91,8 @@ show [-u|--include-untracked|--only-untracked] [<diff-options>] [<stash>]::
91 By default, the command shows the diffstat, but it will accept any
92 format known to 'git diff' (e.g., `git stash show -p stash@{1}`
93 to view the second most recent entry in patch form).
94 - You can use stash.showStat and/or stash.showPatch config variables
95 - to change the default behavior.
94 + You can use stash.showIncludeUntracked, stash.showStat, and
95 + stash.showPatch config variables to change the default behavior.
96
97 pop [--index] [-q|--quiet] [<stash>]::
98
builtin/stash.c
+8
@@ -768,6 +768,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
768
769 static int show_stat = 1;
770 static int show_patch;
771 +static int show_include_untracked;
772 static int use_legacy_stash;
773
774 static int git_stash_config(const char *var, const char *value, void *cb)
@@ -780,6 +781,10 @@ static int git_stash_config(const char *var, const char *value, void *cb)
781 show_patch = git_config_bool(var, value);
782 return 0;
783 }
784 + if (!strcmp(var, "stash.showincludeuntracked")) {
785 + show_include_untracked = git_config_bool(var, value);
786 + return 0;
787 + }
788 if (!strcmp(var, "stash.usebuiltin")) {
789 use_legacy_stash = !git_config_bool(var, value);
790 return 0;
@@ -869,6 +874,9 @@ static int show_stash(int argc, const char **argv, const char *prefix)
874 if (show_patch)
875 rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
876
877 + if (show_include_untracked)
878 + show_untracked = UNTRACKED_INCLUDE;
879 +
880 if (!show_stat && !show_patch) {
881 free_stash_info(&info);
882 return 0;
t/t3905-stash-include-untracked.sh
+2
@@ -319,6 +319,8 @@ test_expect_success 'stash show --include-untracked shows untracked files' '
319 test_cmp expect actual &&
320 git stash show --only-untracked --include-untracked >actual &&
321 test_cmp expect actual &&
322 + git -c stash.showIncludeUntracked=true stash show >actual &&
323 + test_cmp expect actual &&
324
325 cat >expect <<-EOF &&
326 diff --git a/tracked b/tracked