Skip to content

Commit 3086c06

Browse files
namhyunggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a17c56c commit 3086c06

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Documentation/config.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,16 @@ status.submoduleSummary::
24762476
submodule summary' command, which shows a similar output but does
24772477
not honor these settings.
24782478

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+
24792489
submodule.<name>.path::
24802490
submodule.<name>.url::
24812491
The path within this project and URL for a submodule. These

Documentation/git-stash.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ show [<stash>]::
9595
shows the latest one. By default, the command shows the diffstat, but
9696
it will accept any format known to 'git diff' (e.g., `git stash show
9797
-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.
98100

99101
pop [--index] [-q|--quiet] [<stash>]::
100102

git-stash.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,25 @@ show_stash () {
307307
ALLOW_UNKNOWN_FLAGS=t
308308
assert_stash_like "$@"
309309

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
311329
}
312330

313331
show_help () {

0 commit comments

Comments
 (0)