]> granicus.if.org Git - git/commitdiff
stash: default listing to working-tree diff
authorJeff King <peff@peff.net>
Wed, 6 Aug 2014 18:35:25 +0000 (14:35 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Aug 2014 21:37:28 +0000 (14:37 -0700)
When you list stashes, you can provide arbitrary git-log
options to change the display. However, adding just "-p"
does nothing, because each stash is actually a merge commit.

This implementation detail is easy to forget, leading to
confused users who think "-p" is not working. We can make
this easier by defaulting to "--first-parent -m", which will
show the diff against the working tree. This omits the
index portion of the stash entirely, but it's simple and it
matches what "git stash show" provides.

People who are more clueful about stash's true form can use
"--cc" to override the "-m", and the "--first-parent" will
then do nothing. For diffs, it only affects non-combined
diffs, so "--cc" overrides it. And for the traversal, we are
walking the linear reflog anyway, so we do not even care
about the parents.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-stash.sh
t/t3903-stash.sh

index 4798bcf0e51b705005215e9a6339310defe16d03..091c95cac8209e4de0dc5c642c0f3ab6c46f5393 100755 (executable)
@@ -296,7 +296,7 @@ have_stash () {
 
 list_stash () {
        have_stash || return 0
-       git log --format="%gd: %gs" -g "$@" $ref_stash --
+       git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
 }
 
 show_stash () {
index 5b79b216e2e3bb837e58828a2e9a292cb2d7cc53..1e29962fad30edb263cd07b6586f1b1a962c88cf 100755 (executable)
@@ -685,4 +685,46 @@ test_expect_success 'handle stash specification with spaces' '
        grep pig file
 '
 
+test_expect_success 'setup stash with index and worktree changes' '
+       git stash clear &&
+       git reset --hard &&
+       echo index >file &&
+       git add file &&
+       echo working >file &&
+       git stash
+'
+
+test_expect_success 'stash list implies --first-parent -m' '
+       cat >expect <<-\EOF &&
+       stash@{0}: WIP on master: b27a2bc subdir
+
+       diff --git a/file b/file
+       index 257cc56..d26b33d 100644
+       --- a/file
+       +++ b/file
+       @@ -1 +1 @@
+       -foo
+       +working
+       EOF
+       git stash list -p >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'stash list --cc shows combined diff' '
+       cat >expect <<-\EOF &&
+       stash@{0}: WIP on master: b27a2bc subdir
+
+       diff --cc file
+       index 257cc56,9015a7a..d26b33d
+       --- a/file
+       +++ b/file
+       @@@ -1,1 -1,1 +1,1 @@@
+       - foo
+        -index
+       ++working
+       EOF
+       git stash list -p --cc >actual &&
+       test_cmp expect actual
+'
+
 test_done