stash: default listing to working-tree diff

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>

Jeff King committed Aug 6, 2014 at 14:35 UTC 288c67caf64af111aeb7c45cb8b6ba586a61c724
2 files changed +43 -1
git-stash.sh
+1 -1
@@ -296,7 +296,7 @@ have_stash () {
296
297 list_stash () {
298 have_stash || return 0
299 - git log --format="%gd: %gs" -g "$@" $ref_stash --
299 + git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
300 }
301
302 show_stash () {
t/t3903-stash.sh
+42
@@ -685,4 +685,46 @@ test_expect_success 'handle stash specification with spaces' '
685 grep pig file
686 '
687
688 +test_expect_success 'setup stash with index and worktree changes' '
689 + git stash clear &&
690 + git reset --hard &&
691 + echo index >file &&
692 + git add file &&
693 + echo working >file &&
694 + git stash
695 +'
696 +
697 +test_expect_success 'stash list implies --first-parent -m' '
698 + cat >expect <<-\EOF &&
699 + stash@{0}: WIP on master: b27a2bc subdir
700 +
701 + diff --git a/file b/file
702 + index 257cc56..d26b33d 100644
703 + --- a/file
704 + +++ b/file
705 + @@ -1 +1 @@
706 + -foo
707 + +working
708 + EOF
709 + git stash list -p >actual &&
710 + test_cmp expect actual
711 +'
712 +
713 +test_expect_success 'stash list --cc shows combined diff' '
714 + cat >expect <<-\EOF &&
715 + stash@{0}: WIP on master: b27a2bc subdir
716 +
717 + diff --cc file
718 + index 257cc56,9015a7a..d26b33d
719 + --- a/file
720 + +++ b/file
721 + @@@ -1,1 -1,1 +1,1 @@@
722 + - foo
723 + -index
724 + ++working
725 + EOF
726 + git stash list -p --cc >actual &&
727 + test_cmp expect actual
728 +'
729 +
730 test_done