Merge branch 'tg/stash-in-c-show-default-to-p-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Apr 2019 02:14:45 +0000 (11:14 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Apr 2019 02:14:45 +0000 (11:14 +0900)
A regression fix.

* tg/stash-in-c-show-default-to-p-fix:
stash: setup default diff output format if necessary

builtin/stash.c
t/t3903-stash.sh
index ca0b4cd33e0c968d80e9c4d3ab90472f7a16fc6e..8b82053f72db59d2217953ef2c811ba2be02b716 100644 (file)
@@ -761,6 +761,10 @@ static int show_stash(int argc, const char **argv, const char *prefix)
                free_stash_info(&info);
                usage_with_options(git_stash_show_usage, options);
        }
+       if (!rev.diffopt.output_format) {
+               rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+               diff_setup_done(&rev.diffopt);
+       }
 
        rev.diffopt.flags.recursive = 1;
        setup_diff_pager(&rev.diffopt);
index 97cc71fbaf6561995b75431c9e7b6173ba66902f..ea30d5f6a0f228971d29e257a89fca6ea594cecb 100755 (executable)
@@ -612,6 +612,24 @@ test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
        test_cmp expected actual
 '
 
+test_expect_success 'stash show --patience shows diff' '
+       git reset --hard &&
+       echo foo >>file &&
+       STASH_ID=$(git stash create) &&
+       git reset --hard &&
+       cat >expected <<-EOF &&
+       diff --git a/file b/file
+       index 7601807..71b52c4 100644
+       --- a/file
+       +++ b/file
+       @@ -1 +1,2 @@
+        baz
+       +foo
+       EOF
+       git stash show --patience ${STASH_ID} >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'drop: fail early if specified stash is not a stash ref' '
        git stash clear &&
        test_when_finished "git reset --hard HEAD && git stash clear" &&