]> Kevux Git Server - rit/commitdiff
stash show: use stash.showIncludeUntracked even when diff options given
authorDenton Liu <liu.denton@gmail.com>
Fri, 21 May 2021 10:37:47 +0000 (03:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 22 May 2021 08:56:46 +0000 (17:56 +0900)
If options pertaining to how the diff is displayed is provided to
`git stash show`, the command will ignore the stash.showIncludeUntracked
configuration variable, defaulting to not showing any untracked files.
This is unintuitive behaviour since the format of the diff output and
whether or not to display untracked files are orthogonal.

Use stash.showIncludeUntracked even when diff options are given. Of
course, this is still overridable via the command-line options.

Update the documentation to explicitly say which configuration variables
will be overridden when a diff options are given.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/stash.txt
Documentation/git-stash.txt
builtin/stash.c
t/t3905-stash-include-untracked.sh

index 413f907..9ed7752 100644 (file)
@@ -6,9 +6,9 @@ stash.useBuiltin::
        remaining users that setting this now does nothing.
 
 stash.showIncludeUntracked::
-       If this is set to true, the `git stash show` command without an
-       option will show the untracked files of a stash entry.  Defaults to
-       false. See description of 'show' command in linkgit:git-stash[1].
+       If this is set to true, the `git stash show` command will show
+       the untracked files of a stash entry.  Defaults to false. See
+       description of 'show' command in linkgit:git-stash[1].
 
 stash.showPatch::
        If this is set to true, the `git stash show` command without an
index a8c8c32..be6084c 100644 (file)
@@ -91,8 +91,10 @@ show [-u|--include-untracked|--only-untracked] [<diff-options>] [<stash>]::
        By default, the command shows the diffstat, but it will accept any
        format known to 'git diff' (e.g., `git stash show -p stash@{1}`
        to view the second most recent entry in patch form).
-       You can use stash.showIncludeUntracked, stash.showStat, and
-       stash.showPatch config variables to change the default behavior.
+       If no `<diff-option>` is provided, the default behavior will be given
+       by the `stash.showStat`, and `stash.showPatch` config variables. You
+       can also use `stash.showIncludeUntracked` to set whether
+       `--include-untracked` is enabled by default.
 
 pop [--index] [-q|--quiet] [<stash>]::
 
index 82e4829..864b6c1 100644 (file)
@@ -831,7 +831,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
                UNTRACKED_NONE,
                UNTRACKED_INCLUDE,
                UNTRACKED_ONLY
-       } show_untracked = UNTRACKED_NONE;
+       } show_untracked = show_include_untracked ? UNTRACKED_INCLUDE : UNTRACKED_NONE;
        struct option options[] = {
                OPT_SET_INT('u', "include-untracked", &show_untracked,
                            N_("include untracked files in the stash"),
@@ -874,9 +874,6 @@ static int show_stash(int argc, const char **argv, const char *prefix)
                if (show_patch)
                        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 
-               if (show_include_untracked)
-                       show_untracked = UNTRACKED_INCLUDE;
-
                if (!show_stat && !show_patch) {
                        free_stash_info(&info);
                        return 0;
index 1c97659..f7fafcd 100755 (executable)
@@ -333,6 +333,8 @@ test_expect_success 'stash show --include-untracked shows untracked files' '
        git stash show -p --include-untracked >actual &&
        test_cmp expect actual &&
        git stash show --include-untracked -p >actual &&
+       test_cmp expect actual &&
+       git -c stash.showIncludeUntracked=true stash show -p >actual &&
        test_cmp expect actual
 '