stash: allow "stash show" diff output configurable
authorNamhyung Kim <namhyung@gmail.com>
Sat, 29 Aug 2015 15:25:57 +0000 (00:25 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 18:29:04 +0000 (11:29 -0700)
Some users might want to see diff (patch) output always rather than
diffstat when [s]he runs 'git stash show'. Although this can be
done with adding -p option, users are too lazy to type extra three
keys.

Add two variables that control to show diffstat and patch output
respectively. The stash.showStat is for diffstat and default is
true. The stat.showPatch is for the patch output and default is
false.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/git-stash.txt
git-stash.sh
index 43bb53c0477276d81af484cdb64855698b6a635b..c2f08aa18b97626352ebeeed466063dda5c0a06f 100644 (file)
@@ -2476,6 +2476,16 @@ status.submoduleSummary::
        submodule summary' command, which shows a similar output but does
        not honor these settings.
 
        submodule summary' command, which shows a similar output but does
        not honor these settings.
 
+stash.showPatch::
+       If this is set to true, the `git stash show` command without an
+       option will show the stash in patch form.  Defaults to false.
+       See description of 'show' command in linkgit:git-stash[1].
+
+stash.showStat::
+       If this is set to true, the `git stash show` command without an
+       option will show diffstat of the stash.  Defaults to true.
+       See description of 'show' command in linkgit:git-stash[1].
+
 submodule.<name>.path::
 submodule.<name>.url::
        The path within this project and URL for a submodule. These
 submodule.<name>.path::
 submodule.<name>.url::
        The path within this project and URL for a submodule. These
index 375213fe463fa3cd9cb7644cff60ee656c13dcd8..92df596e5fe9757fee399078e05e3ba44196fda3 100644 (file)
@@ -95,6 +95,8 @@ show [<stash>]::
        shows the latest one. 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 stash in patch form).
        shows the latest one. 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 stash in patch form).
+       You can use stash.showStat and/or stash.showPatch config variables
+       to change the default behavior.
 
 pop [--index] [-q|--quiet] [<stash>]::
 
 
 pop [--index] [-q|--quiet] [<stash>]::
 
index 8e9e2cd7d5697c1f2b7ccb8753d384d9f4461bef..92bc0e1ad821291512604d1e931e57e1a4a5d0f5 100755 (executable)
@@ -307,7 +307,25 @@ show_stash () {
        ALLOW_UNKNOWN_FLAGS=t
        assert_stash_like "$@"
 
        ALLOW_UNKNOWN_FLAGS=t
        assert_stash_like "$@"
 
-       git diff ${FLAGS:---stat} $b_commit $w_commit
+       if test -z "$FLAGS"
+       then
+               if test "$(git config --bool stash.showStat || echo true)" = "true"
+               then
+                       FLAGS=--stat
+               fi
+
+               if test "$(git config --bool stash.showPatch || echo false)" = "true"
+               then
+                       FLAGS=${FLAGS}${FLAGS:+ }-p
+               fi
+
+               if test -z "$FLAGS"
+               then
+                       return 0
+               fi
+       fi
+
+       git diff ${FLAGS} $b_commit $w_commit
 }
 
 show_help () {
 }
 
 show_help () {