stash: allow "stash show" diff output configurable

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>

Namhyung Kim committed Aug 30, 2015 at 00:25 UTC 3086c064fbbf3c4d086f9d7c303d9aa76f5204b2
3 files changed +31 -1
Documentation/config.txt
+10
@@ -2476,6 +2476,16 @@ status.submoduleSummary::
2476 submodule summary' command, which shows a similar output but does
2477 not honor these settings.
2478
2479 +stash.showPatch::
2480 + If this is set to true, the `git stash show` command without an
2481 + option will show the stash in patch form. Defaults to false.
2482 + See description of 'show' command in linkgit:git-stash[1].
2483 +
2484 +stash.showStat::
2485 + If this is set to true, the `git stash show` command without an
2486 + option will show diffstat of the stash. Defaults to true.
2487 + See description of 'show' command in linkgit:git-stash[1].
2488 +
2489 submodule.<name>.path::
2490 submodule.<name>.url::
2491 The path within this project and URL for a submodule. These
Documentation/git-stash.txt
+2
@@ -95,6 +95,8 @@ show [<stash>]::
95 shows the latest one. By default, the command shows the diffstat, but
96 it will accept any format known to 'git diff' (e.g., `git stash show
97 -p stash@{1}` to view the second most recent stash in patch form).
98 + You can use stash.showStat and/or stash.showPatch config variables
99 + to change the default behavior.
100
101 pop [--index] [-q|--quiet] [<stash>]::
102
git-stash.sh
+19 -1
@@ -307,7 +307,25 @@ show_stash () {
307 ALLOW_UNKNOWN_FLAGS=t
308 assert_stash_like "$@"
309
310 - git diff ${FLAGS:---stat} $b_commit $w_commit
310 + if test -z "$FLAGS"
311 + then
312 + if test "$(git config --bool stash.showStat || echo true)" = "true"
313 + then
314 + FLAGS=--stat
315 + fi
316 +
317 + if test "$(git config --bool stash.showPatch || echo false)" = "true"
318 + then
319 + FLAGS=${FLAGS}${FLAGS:+ }-p
320 + fi
321 +
322 + if test -z "$FLAGS"
323 + then
324 + return 0
325 + fi
326 + fi
327 +
328 + git diff ${FLAGS} $b_commit $w_commit
329 }
330
331 show_help () {