Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 6 | test_description='various format-patch tests' |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 7 | |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 11 | . ./test-lib.sh |
Tay Ray Chuan | 38a94bb | 2010-11-23 11:16:30 +0800 | [diff] [blame] | 12 | . "$TEST_DIRECTORY"/lib-terminal.sh |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 13 | |
| 14 | test_expect_success setup ' |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 15 | test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && |
Junio C Hamano | cd894ee | 2007-09-18 15:19:47 -0700 | [diff] [blame] | 16 | cat file >elif && |
| 17 | git add file elif && |
Ramkumar Ramachandra | 6426f2d | 2010-08-28 01:58:15 +0530 | [diff] [blame] | 18 | test_tick && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 19 | git commit -m Initial && |
| 20 | git checkout -b side && |
| 21 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 22 | test_write_lines 1 2 5 6 A B C 7 8 9 10 >file && |
Johannes Sixt | 1f55391 | 2009-02-28 21:12:57 +0100 | [diff] [blame] | 23 | test_chmod +x elif && |
Ramkumar Ramachandra | 6426f2d | 2010-08-28 01:58:15 +0530 | [diff] [blame] | 24 | test_tick && |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 25 | git commit -m "Side changes #1" && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 26 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 27 | test_write_lines D E F >>file && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 28 | git update-index file && |
Ramkumar Ramachandra | 6426f2d | 2010-08-28 01:58:15 +0530 | [diff] [blame] | 29 | test_tick && |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 30 | git commit -m "Side changes #2" && |
Junio C Hamano | 982b64e | 2006-06-28 22:48:34 -0700 | [diff] [blame] | 31 | git tag C2 && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 32 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 33 | test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 34 | git update-index file && |
Ramkumar Ramachandra | 6426f2d | 2010-08-28 01:58:15 +0530 | [diff] [blame] | 35 | test_tick && |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 36 | git commit -m "Side changes #3 with \\n backslash-n in it." && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 37 | |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 38 | git checkout main && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 39 | git diff-tree -p C2 >patch && |
| 40 | git apply --index <patch && |
Ramkumar Ramachandra | 6426f2d | 2010-08-28 01:58:15 +0530 | [diff] [blame] | 41 | test_tick && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 42 | git commit -m "Main accepts moral equivalent of #2" && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 43 | |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 44 | git checkout side && |
| 45 | git checkout -b patchid && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 46 | test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file2 && |
| 47 | test_write_lines 1 2 3 A 4 B C 7 8 9 10 D E F 5 6 >file3 && |
| 48 | test_write_lines 8 9 10 >file && |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 49 | git add file file2 file3 && |
| 50 | test_tick && |
| 51 | git commit -m "patchid 1" && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 52 | test_write_lines 4 A B 7 8 9 10 >file2 && |
| 53 | test_write_lines 8 9 10 5 6 >file3 && |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 54 | git add file2 file3 && |
| 55 | test_tick && |
| 56 | git commit -m "patchid 2" && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 57 | test_write_lines 10 5 6 >file && |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 58 | git add file && |
| 59 | test_tick && |
| 60 | git commit -m "patchid 3" && |
| 61 | |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 62 | git checkout main |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 63 | ' |
| 64 | |
Denton Liu | 0ab74e9 | 2019-08-27 00:04:58 -0400 | [diff] [blame] | 65 | test_expect_success 'format-patch --ignore-if-in-upstream' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 66 | git format-patch --stdout main..side >patch0 && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 67 | grep "^From " patch0 >from0 && |
| 68 | test_line_count = 3 from0 |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 69 | ' |
| 70 | |
Denton Liu | 0ab74e9 | 2019-08-27 00:04:58 -0400 | [diff] [blame] | 71 | test_expect_success 'format-patch --ignore-if-in-upstream' ' |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 72 | git format-patch --stdout \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 73 | --ignore-if-in-upstream main..side >patch1 && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 74 | grep "^From " patch1 >from1 && |
| 75 | test_line_count = 2 from1 |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 76 | ' |
| 77 | |
Denton Liu | 0ab74e9 | 2019-08-27 00:04:58 -0400 | [diff] [blame] | 78 | test_expect_success 'format-patch --ignore-if-in-upstream handles tags' ' |
Junio C Hamano | 9b7a61d | 2015-06-01 10:44:21 -0700 | [diff] [blame] | 79 | git tag -a v1 -m tag side && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 80 | git tag -a v2 -m tag main && |
Junio C Hamano | 9b7a61d | 2015-06-01 10:44:21 -0700 | [diff] [blame] | 81 | git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 82 | grep "^From " patch1 >from1 && |
| 83 | test_line_count = 2 from1 |
Junio C Hamano | 9b7a61d | 2015-06-01 10:44:21 -0700 | [diff] [blame] | 84 | ' |
| 85 | |
Ramkumar Ramachandra | 2c642ed | 2010-08-28 01:58:16 +0530 | [diff] [blame] | 86 | test_expect_success "format-patch doesn't consider merge commits" ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 87 | git checkout -b feature main && |
Ramkumar Ramachandra | 2c642ed | 2010-08-28 01:58:16 +0530 | [diff] [blame] | 88 | echo "Another line" >>file && |
| 89 | test_tick && |
Paolo Bonzini | 08dc260 | 2020-06-19 11:32:10 +0200 | [diff] [blame] | 90 | git commit -am "Feature branch change #1" && |
Ramkumar Ramachandra | 2c642ed | 2010-08-28 01:58:16 +0530 | [diff] [blame] | 91 | echo "Yet another line" >>file && |
| 92 | test_tick && |
Paolo Bonzini | 08dc260 | 2020-06-19 11:32:10 +0200 | [diff] [blame] | 93 | git commit -am "Feature branch change #2" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 94 | git checkout -b merger main && |
Ramkumar Ramachandra | 2c642ed | 2010-08-28 01:58:16 +0530 | [diff] [blame] | 95 | test_tick && |
Paolo Bonzini | 08dc260 | 2020-06-19 11:32:10 +0200 | [diff] [blame] | 96 | git merge --no-ff feature && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 97 | git format-patch -3 --stdout >patch && |
| 98 | grep "^From " patch >from && |
| 99 | test_line_count = 3 from |
Ramkumar Ramachandra | 2c642ed | 2010-08-28 01:58:16 +0530 | [diff] [blame] | 100 | ' |
| 101 | |
Denton Liu | 0ab74e9 | 2019-08-27 00:04:58 -0400 | [diff] [blame] | 102 | test_expect_success 'format-patch result applies' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 103 | git checkout -b rebuild-0 main && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 104 | git am -3 patch0 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 105 | git rev-list main.. >list && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 106 | test_line_count = 2 list |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 107 | ' |
| 108 | |
Denton Liu | 0ab74e9 | 2019-08-27 00:04:58 -0400 | [diff] [blame] | 109 | test_expect_success 'format-patch --ignore-if-in-upstream result applies' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 110 | git checkout -b rebuild-1 main && |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 111 | git am -3 patch1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 112 | git rev-list main.. >list && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 113 | test_line_count = 2 list |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 114 | ' |
| 115 | |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 116 | test_expect_success 'commit did not screw up the log message' ' |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 117 | git cat-file commit side >actual && |
| 118 | grep "^Side .* with .* backslash-n" actual |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 119 | ' |
| 120 | |
| 121 | test_expect_success 'format-patch did not screw up the log message' ' |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 122 | grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 && |
| 123 | grep "^Subject: .*Side changes #3 with .* backslash-n" patch1 |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 124 | ' |
| 125 | |
| 126 | test_expect_success 'replay did not screw up the log message' ' |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 127 | git cat-file commit rebuild-1 >actual && |
| 128 | grep "^Side .* with .* backslash-n" actual |
Junio C Hamano | 816366e | 2007-05-26 00:26:20 -0700 | [diff] [blame] | 129 | ' |
| 130 | |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 131 | test_expect_success 'extra headers' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 132 | git config format.headers "To: R E Cipient <rcipient@example.com> |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 133 | " && |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 134 | git config --add format.headers "Cc: S E Cipient <scipient@example.com> |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 135 | " && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 136 | git format-patch --stdout main..side >patch2 && |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 137 | sed -e "/^\$/q" patch2 >hdrs2 && |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 138 | grep "^To: R E Cipient <rcipient@example.com>\$" hdrs2 && |
| 139 | grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs2 |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 140 | ' |
| 141 | |
Daniel Barkalow | 7d22708 | 2008-02-19 02:40:31 -0500 | [diff] [blame] | 142 | test_expect_success 'extra headers without newlines' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 143 | git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" && |
| 144 | git config --add format.headers "Cc: S E Cipient <scipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 145 | git format-patch --stdout main..side >patch3 && |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 146 | sed -e "/^\$/q" patch3 >hdrs3 && |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 147 | grep "^To: R E Cipient <rcipient@example.com>\$" hdrs3 && |
| 148 | grep "^Cc: S E Cipient <scipient@example.com>\$" hdrs3 |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 149 | ' |
| 150 | |
Daniel Barkalow | 3ee79d9 | 2008-02-19 02:40:33 -0500 | [diff] [blame] | 151 | test_expect_success 'extra headers with multiple To:s' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 152 | git config --replace-all format.headers "To: R E Cipient <rcipient@example.com>" && |
| 153 | git config --add format.headers "To: S E Cipient <scipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 154 | git format-patch --stdout main..side >patch4 && |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 155 | sed -e "/^\$/q" patch4 >hdrs4 && |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 156 | grep "^To: R E Cipient <rcipient@example.com>,\$" hdrs4 && |
| 157 | grep "^ *S E Cipient <scipient@example.com>\$" hdrs4 |
Daniel Barkalow | a8d8173 | 2008-02-19 02:40:28 -0500 | [diff] [blame] | 158 | ' |
| 159 | |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 160 | test_expect_success 'additional command line cc (ascii)' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 161 | git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 162 | git format-patch --cc="S E Cipient <scipient@example.com>" --stdout main..side >patch5 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 163 | sed -e "/^\$/q" patch5 >hdrs5 && |
| 164 | grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 && |
| 165 | grep "^ *S E Cipient <scipient@example.com>\$" hdrs5 |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 166 | ' |
| 167 | |
| 168 | test_expect_failure 'additional command line cc (rfc822)' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 169 | git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 170 | git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout main..side >patch5 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 171 | sed -e "/^\$/q" patch5 >hdrs5 && |
| 172 | grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs5 && |
| 173 | grep "^ *\"S. E. Cipient\" <scipient@example.com>\$" hdrs5 |
Daniel Barkalow | 736cc67 | 2008-02-19 02:40:35 -0500 | [diff] [blame] | 174 | ' |
| 175 | |
Michael Hendricks | d7d9c2d | 2009-03-26 10:51:05 -0600 | [diff] [blame] | 176 | test_expect_success 'command line headers' ' |
Michael Hendricks | d7d9c2d | 2009-03-26 10:51:05 -0600 | [diff] [blame] | 177 | git config --unset-all format.headers && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 178 | git format-patch --add-header="Cc: R E Cipient <rcipient@example.com>" --stdout main..side >patch6 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 179 | sed -e "/^\$/q" patch6 >hdrs6 && |
| 180 | grep "^Cc: R E Cipient <rcipient@example.com>\$" hdrs6 |
Michael Hendricks | d7d9c2d | 2009-03-26 10:51:05 -0600 | [diff] [blame] | 181 | ' |
| 182 | |
| 183 | test_expect_success 'configuration headers and command line headers' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 184 | git config --replace-all format.headers "Cc: R E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 185 | git format-patch --add-header="Cc: S E Cipient <scipient@example.com>" --stdout main..side >patch7 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 186 | sed -e "/^\$/q" patch7 >hdrs7 && |
| 187 | grep "^Cc: R E Cipient <rcipient@example.com>,\$" hdrs7 && |
| 188 | grep "^ *S E Cipient <scipient@example.com>\$" hdrs7 |
Michael Hendricks | d7d9c2d | 2009-03-26 10:51:05 -0600 | [diff] [blame] | 189 | ' |
| 190 | |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 191 | test_expect_success 'command line To: header (ascii)' ' |
Steven Drake | ae6c098 | 2010-02-17 12:39:34 +1300 | [diff] [blame] | 192 | git config --unset-all format.headers && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 193 | git format-patch --to="R E Cipient <rcipient@example.com>" --stdout main..side >patch8 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 194 | sed -e "/^\$/q" patch8 >hdrs8 && |
| 195 | grep "^To: R E Cipient <rcipient@example.com>\$" hdrs8 |
Steven Drake | ae6c098 | 2010-02-17 12:39:34 +1300 | [diff] [blame] | 196 | ' |
| 197 | |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 198 | test_expect_failure 'command line To: header (rfc822)' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 199 | git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout main..side >patch8 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 200 | sed -e "/^\$/q" patch8 >hdrs8 && |
| 201 | grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs8 |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 202 | ' |
| 203 | |
| 204 | test_expect_failure 'command line To: header (rfc2047)' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 205 | git format-patch --to="R Ä Cipient <rcipient@example.com>" --stdout main..side >patch8 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 206 | sed -e "/^\$/q" patch8 >hdrs8 && |
| 207 | grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs8 |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 208 | ' |
| 209 | |
| 210 | test_expect_success 'configuration To: header (ascii)' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 211 | git config format.to "R E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 212 | git format-patch --stdout main..side >patch9 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 213 | sed -e "/^\$/q" patch9 >hdrs9 && |
| 214 | grep "^To: R E Cipient <rcipient@example.com>\$" hdrs9 |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 215 | ' |
| 216 | |
| 217 | test_expect_failure 'configuration To: header (rfc822)' ' |
Steven Drake | ae6c098 | 2010-02-17 12:39:34 +1300 | [diff] [blame] | 218 | git config format.to "R. E. Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 219 | git format-patch --stdout main..side >patch9 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 220 | sed -e "/^\$/q" patch9 >hdrs9 && |
| 221 | grep "^To: \"R. E. Cipient\" <rcipient@example.com>\$" hdrs9 |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 222 | ' |
| 223 | |
| 224 | test_expect_failure 'configuration To: header (rfc2047)' ' |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 225 | git config format.to "R Ä Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 226 | git format-patch --stdout main..side >patch9 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 227 | sed -e "/^\$/q" patch9 >hdrs9 && |
| 228 | grep "^To: =?UTF-8?q?R=20=C3=84=20Cipient?= <rcipient@example.com>\$" hdrs9 |
Steven Drake | ae6c098 | 2010-02-17 12:39:34 +1300 | [diff] [blame] | 229 | ' |
| 230 | |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 231 | # check_patch <patch>: Verify that <patch> looks like a half-sane |
| 232 | # patch email to avoid a false positive with !grep |
| 233 | check_patch () { |
| 234 | grep -e "^From:" "$1" && |
| 235 | grep -e "^Date:" "$1" && |
| 236 | grep -e "^Subject:" "$1" |
| 237 | } |
| 238 | |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 239 | test_expect_success 'format.from=false' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 240 | git -c format.from=false format-patch --stdout main..side >patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 241 | sed -e "/^\$/q" patch >hdrs && |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 242 | check_patch patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 243 | ! grep "^From: C O Mitter <committer@example.com>\$" hdrs |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 244 | ' |
| 245 | |
| 246 | test_expect_success 'format.from=true' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 247 | git -c format.from=true format-patch --stdout main..side >patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 248 | sed -e "/^\$/q" patch >hdrs && |
| 249 | check_patch hdrs && |
| 250 | grep "^From: C O Mitter <committer@example.com>\$" hdrs |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 251 | ' |
| 252 | |
| 253 | test_expect_success 'format.from with address' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 254 | git -c format.from="F R Om <from@example.com>" format-patch --stdout main..side >patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 255 | sed -e "/^\$/q" patch >hdrs && |
| 256 | check_patch hdrs && |
| 257 | grep "^From: F R Om <from@example.com>\$" hdrs |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 258 | ' |
| 259 | |
| 260 | test_expect_success '--no-from overrides format.from' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 261 | git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout main..side >patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 262 | sed -e "/^\$/q" patch >hdrs && |
| 263 | check_patch hdrs && |
| 264 | ! grep "^From: F R Om <from@example.com>\$" hdrs |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 265 | ' |
| 266 | |
| 267 | test_expect_success '--from overrides format.from' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 268 | git -c format.from="F R Om <from@example.com>" format-patch --from --stdout main..side >patch && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 269 | sed -e "/^\$/q" patch >hdrs && |
| 270 | check_patch hdrs && |
| 271 | ! grep "^From: F R Om <from@example.com>\$" hdrs |
Josh Triplett | 6bc6b6c | 2016-07-30 02:41:56 -0700 | [diff] [blame] | 272 | ' |
| 273 | |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 274 | test_expect_success '--no-to overrides config.to' ' |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 275 | git config --replace-all format.to \ |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 276 | "R E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 277 | git format-patch --no-to --stdout main..side >patch10 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 278 | sed -e "/^\$/q" patch10 >hdrs10 && |
| 279 | check_patch hdrs10 && |
| 280 | ! grep "^To: R E Cipient <rcipient@example.com>\$" hdrs10 |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 281 | ' |
| 282 | |
| 283 | test_expect_success '--no-to and --to replaces config.to' ' |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 284 | git config --replace-all format.to \ |
| 285 | "Someone <someone@out.there>" && |
| 286 | git format-patch --no-to --to="Someone Else <else@out.there>" \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 287 | --stdout main..side >patch11 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 288 | sed -e "/^\$/q" patch11 >hdrs11 && |
| 289 | check_patch hdrs11 && |
| 290 | ! grep "^To: Someone <someone@out.there>\$" hdrs11 && |
| 291 | grep "^To: Someone Else <else@out.there>\$" hdrs11 |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 292 | ' |
| 293 | |
| 294 | test_expect_success '--no-cc overrides config.cc' ' |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 295 | git config --replace-all format.cc \ |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 296 | "C E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 297 | git format-patch --no-cc --stdout main..side >patch12 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 298 | sed -e "/^\$/q" patch12 >hdrs12 && |
| 299 | check_patch hdrs12 && |
| 300 | ! grep "^Cc: C E Cipient <rcipient@example.com>\$" hdrs12 |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 301 | ' |
| 302 | |
Thomas Rast | 688f4f2 | 2011-08-29 22:10:48 +0200 | [diff] [blame] | 303 | test_expect_success '--no-add-header overrides config.headers' ' |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 304 | git config --replace-all format.headers \ |
Jan H. Schönherr | 25dc8da | 2012-10-18 16:43:34 +0200 | [diff] [blame] | 305 | "Header1: B E Cipient <rcipient@example.com>" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 306 | git format-patch --no-add-header --stdout main..side >patch13 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 307 | sed -e "/^\$/q" patch13 >hdrs13 && |
| 308 | check_patch hdrs13 && |
| 309 | ! grep "^Header1: B E Cipient <rcipient@example.com>\$" hdrs13 |
Stephen Boyd | c426003 | 2010-03-07 14:46:47 -0800 | [diff] [blame] | 310 | ' |
| 311 | |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 312 | test_expect_success 'multiple files' ' |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 313 | rm -rf patches/ && |
| 314 | git checkout side && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 315 | git format-patch -o patches/ main && |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 316 | ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch |
| 317 | ' |
| 318 | |
Junio C Hamano | 3baf58b | 2020-11-06 13:56:24 -0800 | [diff] [blame] | 319 | test_expect_success 'filename length limit' ' |
| 320 | test_when_finished "rm -f 000*" && |
| 321 | rm -rf 000[1-9]-*.patch && |
| 322 | for len in 15 25 35 |
| 323 | do |
| 324 | git format-patch --filename-max-length=$len -3 side && |
| 325 | max=$( |
| 326 | for patch in 000[1-9]-*.patch |
| 327 | do |
Eric Sunshine | cbe1d9d | 2021-12-09 00:11:13 -0500 | [diff] [blame] | 328 | echo "$patch" | wc -c || exit 1 |
Junio C Hamano | 3baf58b | 2020-11-06 13:56:24 -0800 | [diff] [blame] | 329 | done | |
| 330 | sort -nr | |
| 331 | head -n 1 |
| 332 | ) && |
| 333 | test $max -le $len || return 1 |
| 334 | done |
| 335 | ' |
| 336 | |
| 337 | test_expect_success 'filename length limit from config' ' |
| 338 | test_when_finished "rm -f 000*" && |
| 339 | rm -rf 000[1-9]-*.patch && |
| 340 | for len in 15 25 35 |
| 341 | do |
| 342 | git -c format.filenameMaxLength=$len format-patch -3 side && |
| 343 | max=$( |
| 344 | for patch in 000[1-9]-*.patch |
| 345 | do |
Eric Sunshine | cbe1d9d | 2021-12-09 00:11:13 -0500 | [diff] [blame] | 346 | echo "$patch" | wc -c || exit 1 |
Junio C Hamano | 3baf58b | 2020-11-06 13:56:24 -0800 | [diff] [blame] | 347 | done | |
| 348 | sort -nr | |
| 349 | head -n 1 |
| 350 | ) && |
| 351 | test $max -le $len || return 1 |
| 352 | done |
| 353 | ' |
| 354 | |
| 355 | test_expect_success 'filename limit applies only to basename' ' |
| 356 | test_when_finished "rm -rf patches/" && |
| 357 | rm -rf patches/ && |
| 358 | for len in 15 25 35 |
| 359 | do |
| 360 | git format-patch -o patches --filename-max-length=$len -3 side && |
| 361 | max=$( |
| 362 | for patch in patches/000[1-9]-*.patch |
| 363 | do |
Eric Sunshine | cbe1d9d | 2021-12-09 00:11:13 -0500 | [diff] [blame] | 364 | echo "${patch#patches/}" | wc -c || exit 1 |
Junio C Hamano | 3baf58b | 2020-11-06 13:56:24 -0800 | [diff] [blame] | 365 | done | |
| 366 | sort -nr | |
| 367 | head -n 1 |
| 368 | ) && |
| 369 | test $max -le $len || return 1 |
| 370 | done |
| 371 | ' |
| 372 | |
Junio C Hamano | 4aad08e | 2013-01-02 14:16:07 -0800 | [diff] [blame] | 373 | test_expect_success 'reroll count' ' |
| 374 | rm -fr patches && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 375 | git format-patch -o patches --cover-letter --reroll-count 4 main..side >list && |
Junio C Hamano | 4aad08e | 2013-01-02 14:16:07 -0800 | [diff] [blame] | 376 | ! grep -v "^patches/v4-000[0-3]-" list && |
| 377 | sed -n -e "/^Subject: /p" $(cat list) >subjects && |
| 378 | ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects |
| 379 | ' |
| 380 | |
Junio C Hamano | 7952ea6 | 2013-01-02 14:19:05 -0800 | [diff] [blame] | 381 | test_expect_success 'reroll count (-v)' ' |
| 382 | rm -fr patches && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 383 | git format-patch -o patches --cover-letter -v4 main..side >list && |
Junio C Hamano | 7952ea6 | 2013-01-02 14:19:05 -0800 | [diff] [blame] | 384 | ! grep -v "^patches/v4-000[0-3]-" list && |
| 385 | sed -n -e "/^Subject: /p" $(cat list) >subjects && |
| 386 | ! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects |
| 387 | ' |
| 388 | |
ZheNing Hu | db91988 | 2021-03-23 11:12:25 +0000 | [diff] [blame] | 389 | test_expect_success 'reroll count (-v) with a fractional number' ' |
| 390 | rm -fr patches && |
| 391 | git format-patch -o patches --cover-letter -v4.4 main..side >list && |
| 392 | ! grep -v "^patches/v4.4-000[0-3]-" list && |
| 393 | sed -n -e "/^Subject: /p" $(cat list) >subjects && |
| 394 | ! grep -v "^Subject: \[PATCH v4.4 [0-3]/3\] " subjects |
| 395 | ' |
| 396 | |
| 397 | test_expect_success 'reroll (-v) count with a non number' ' |
| 398 | rm -fr patches && |
| 399 | git format-patch -o patches --cover-letter -v4rev2 main..side >list && |
| 400 | ! grep -v "^patches/v4rev2-000[0-3]-" list && |
| 401 | sed -n -e "/^Subject: /p" $(cat list) >subjects && |
| 402 | ! grep -v "^Subject: \[PATCH v4rev2 [0-3]/3\] " subjects |
| 403 | ' |
| 404 | |
| 405 | test_expect_success 'reroll (-v) count with a non-pathname character' ' |
| 406 | rm -fr patches && |
| 407 | git format-patch -o patches --cover-letter -v4---..././../--1/.2// main..side >list && |
| 408 | ! grep -v "patches/v4-\.-\.-\.-1-\.2-000[0-3]-" list && |
| 409 | sed -n -e "/^Subject: /p" $(cat list) >subjects && |
| 410 | ! grep -v "^Subject: \[PATCH v4---\.\.\./\./\.\./--1/\.2// [0-3]/3\] " subjects |
| 411 | ' |
| 412 | |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 413 | check_threading () { |
| 414 | expect="$1" && |
| 415 | shift && |
Denton Liu | dd2b6b6 | 2019-08-27 00:05:12 -0400 | [diff] [blame] | 416 | git format-patch --stdout "$@" >patch && |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 417 | # Prints everything between the Message-ID and In-Reply-To, |
| 418 | # and replaces all Message-ID-lookalikes by a sequence number |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 419 | perl -ne ' |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 420 | if (/^(message-id|references|in-reply-to)/i) { |
| 421 | $printing = 1; |
| 422 | } elsif (/^\S/) { |
| 423 | $printing = 0; |
| 424 | } |
| 425 | if ($printing) { |
| 426 | $h{$1}=$i++ if (/<([^>]+)>/ and !exists $h{$1}); |
| 427 | for $k (keys %h) {s/$k/$h{$k}/}; |
| 428 | print; |
| 429 | } |
| 430 | print "---\n" if /^From /i; |
Denton Liu | dd2b6b6 | 2019-08-27 00:05:12 -0400 | [diff] [blame] | 431 | ' <patch >actual && |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 432 | test_cmp "$expect" actual |
| 433 | } |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 434 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 435 | cat >>expect.no-threading <<EOF |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 436 | --- |
| 437 | --- |
| 438 | --- |
| 439 | EOF |
| 440 | |
| 441 | test_expect_success 'no threading' ' |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 442 | git checkout side && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 443 | check_threading expect.no-threading main |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 444 | ' |
| 445 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 446 | cat >expect.thread <<EOF |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 447 | --- |
| 448 | Message-Id: <0> |
| 449 | --- |
| 450 | Message-Id: <1> |
| 451 | In-Reply-To: <0> |
| 452 | References: <0> |
| 453 | --- |
| 454 | Message-Id: <2> |
| 455 | In-Reply-To: <0> |
| 456 | References: <0> |
| 457 | EOF |
| 458 | |
| 459 | test_expect_success 'thread' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 460 | check_threading expect.thread --thread main |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 461 | ' |
| 462 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 463 | cat >expect.in-reply-to <<EOF |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 464 | --- |
| 465 | Message-Id: <0> |
| 466 | In-Reply-To: <1> |
| 467 | References: <1> |
| 468 | --- |
| 469 | Message-Id: <2> |
| 470 | In-Reply-To: <1> |
| 471 | References: <1> |
| 472 | --- |
| 473 | Message-Id: <3> |
| 474 | In-Reply-To: <1> |
| 475 | References: <1> |
| 476 | EOF |
| 477 | |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 478 | test_expect_success 'thread in-reply-to' ' |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 479 | check_threading expect.in-reply-to --in-reply-to="<test.message>" \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 480 | --thread main |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 481 | ' |
| 482 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 483 | cat >expect.cover-letter <<EOF |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 484 | --- |
| 485 | Message-Id: <0> |
| 486 | --- |
| 487 | Message-Id: <1> |
| 488 | In-Reply-To: <0> |
| 489 | References: <0> |
| 490 | --- |
| 491 | Message-Id: <2> |
| 492 | In-Reply-To: <0> |
| 493 | References: <0> |
| 494 | --- |
| 495 | Message-Id: <3> |
| 496 | In-Reply-To: <0> |
| 497 | References: <0> |
| 498 | EOF |
| 499 | |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 500 | test_expect_success 'thread cover-letter' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 501 | check_threading expect.cover-letter --cover-letter --thread main |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 502 | ' |
| 503 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 504 | cat >expect.cl-irt <<EOF |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 505 | --- |
| 506 | Message-Id: <0> |
| 507 | In-Reply-To: <1> |
| 508 | References: <1> |
| 509 | --- |
| 510 | Message-Id: <2> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 511 | In-Reply-To: <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 512 | References: <1> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 513 | <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 514 | --- |
| 515 | Message-Id: <3> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 516 | In-Reply-To: <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 517 | References: <1> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 518 | <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 519 | --- |
| 520 | Message-Id: <4> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 521 | In-Reply-To: <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 522 | References: <1> |
Thomas Rast | 2175c10 | 2009-02-19 22:26:32 +0100 | [diff] [blame] | 523 | <0> |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 524 | EOF |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 525 | |
Thomas Rast | 484cf6c | 2009-02-19 22:26:30 +0100 | [diff] [blame] | 526 | test_expect_success 'thread cover-letter in-reply-to' ' |
| 527 | check_threading expect.cl-irt --cover-letter \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 528 | --in-reply-to="<test.message>" --thread main |
Daniel Barkalow | a5a27c7 | 2008-02-18 22:56:13 -0500 | [diff] [blame] | 529 | ' |
| 530 | |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 531 | test_expect_success 'thread explicit shallow' ' |
| 532 | check_threading expect.cl-irt --cover-letter \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 533 | --in-reply-to="<test.message>" --thread=shallow main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 534 | ' |
| 535 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 536 | cat >expect.deep <<EOF |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 537 | --- |
| 538 | Message-Id: <0> |
| 539 | --- |
| 540 | Message-Id: <1> |
| 541 | In-Reply-To: <0> |
| 542 | References: <0> |
| 543 | --- |
| 544 | Message-Id: <2> |
| 545 | In-Reply-To: <1> |
| 546 | References: <0> |
| 547 | <1> |
| 548 | EOF |
| 549 | |
| 550 | test_expect_success 'thread deep' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 551 | check_threading expect.deep --thread=deep main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 552 | ' |
| 553 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 554 | cat >expect.deep-irt <<EOF |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 555 | --- |
| 556 | Message-Id: <0> |
| 557 | In-Reply-To: <1> |
| 558 | References: <1> |
| 559 | --- |
| 560 | Message-Id: <2> |
| 561 | In-Reply-To: <0> |
| 562 | References: <1> |
| 563 | <0> |
| 564 | --- |
| 565 | Message-Id: <3> |
| 566 | In-Reply-To: <2> |
| 567 | References: <1> |
| 568 | <0> |
| 569 | <2> |
| 570 | EOF |
| 571 | |
| 572 | test_expect_success 'thread deep in-reply-to' ' |
| 573 | check_threading expect.deep-irt --thread=deep \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 574 | --in-reply-to="<test.message>" main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 575 | ' |
| 576 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 577 | cat >expect.deep-cl <<EOF |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 578 | --- |
| 579 | Message-Id: <0> |
| 580 | --- |
| 581 | Message-Id: <1> |
| 582 | In-Reply-To: <0> |
| 583 | References: <0> |
| 584 | --- |
| 585 | Message-Id: <2> |
| 586 | In-Reply-To: <1> |
| 587 | References: <0> |
| 588 | <1> |
| 589 | --- |
| 590 | Message-Id: <3> |
| 591 | In-Reply-To: <2> |
| 592 | References: <0> |
| 593 | <1> |
| 594 | <2> |
| 595 | EOF |
| 596 | |
| 597 | test_expect_success 'thread deep cover-letter' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 598 | check_threading expect.deep-cl --cover-letter --thread=deep main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 599 | ' |
| 600 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 601 | cat >expect.deep-cl-irt <<EOF |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 602 | --- |
| 603 | Message-Id: <0> |
| 604 | In-Reply-To: <1> |
| 605 | References: <1> |
| 606 | --- |
| 607 | Message-Id: <2> |
| 608 | In-Reply-To: <0> |
| 609 | References: <1> |
| 610 | <0> |
| 611 | --- |
| 612 | Message-Id: <3> |
| 613 | In-Reply-To: <2> |
| 614 | References: <1> |
| 615 | <0> |
| 616 | <2> |
| 617 | --- |
| 618 | Message-Id: <4> |
| 619 | In-Reply-To: <3> |
| 620 | References: <1> |
| 621 | <0> |
| 622 | <2> |
| 623 | <3> |
| 624 | EOF |
| 625 | |
| 626 | test_expect_success 'thread deep cover-letter in-reply-to' ' |
| 627 | check_threading expect.deep-cl-irt --cover-letter \ |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 628 | --in-reply-to="<test.message>" --thread=deep main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 629 | ' |
| 630 | |
| 631 | test_expect_success 'thread via config' ' |
Jeff King | e810715 | 2011-09-19 15:15:45 -0400 | [diff] [blame] | 632 | test_config format.thread true && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 633 | check_threading expect.thread main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 634 | ' |
| 635 | |
| 636 | test_expect_success 'thread deep via config' ' |
Jeff King | e810715 | 2011-09-19 15:15:45 -0400 | [diff] [blame] | 637 | test_config format.thread deep && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 638 | check_threading expect.deep main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 639 | ' |
| 640 | |
| 641 | test_expect_success 'thread config + override' ' |
Jeff King | e810715 | 2011-09-19 15:15:45 -0400 | [diff] [blame] | 642 | test_config format.thread deep && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 643 | check_threading expect.thread --thread main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 644 | ' |
| 645 | |
| 646 | test_expect_success 'thread config + --no-thread' ' |
Jeff King | e810715 | 2011-09-19 15:15:45 -0400 | [diff] [blame] | 647 | test_config format.thread deep && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 648 | check_threading expect.no-threading --no-thread main |
Thomas Rast | 30984ed | 2009-02-19 22:26:33 +0100 | [diff] [blame] | 649 | ' |
| 650 | |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 651 | test_expect_success 'excessive subject' ' |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 652 | rm -rf patches/ && |
| 653 | git checkout side && |
brian m. carlson | bdee9cd | 2018-05-21 02:01:36 +0000 | [diff] [blame] | 654 | before=$(git hash-object file) && |
| 655 | before=$(git rev-parse --short $before) && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 656 | test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >>file && |
brian m. carlson | bdee9cd | 2018-05-21 02:01:36 +0000 | [diff] [blame] | 657 | after=$(git hash-object file) && |
| 658 | after=$(git rev-parse --short $after) && |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 659 | git update-index file && |
| 660 | git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 661 | git format-patch -o patches/ main..side && |
Daniel Barkalow | 7d81214 | 2008-02-18 22:56:02 -0500 | [diff] [blame] | 662 | ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch |
| 663 | ' |
| 664 | |
Junio C Hamano | 2fe95f4 | 2019-02-22 11:26:43 -0800 | [diff] [blame] | 665 | test_expect_success 'failure to write cover-letter aborts gracefully' ' |
| 666 | test_when_finished "rmdir 0000-cover-letter.patch" && |
| 667 | mkdir 0000-cover-letter.patch && |
| 668 | test_must_fail git format-patch --no-renames --cover-letter -1 |
| 669 | ' |
| 670 | |
Johannes Schindelin | 5d02294 | 2008-03-02 15:53:04 +0000 | [diff] [blame] | 671 | test_expect_success 'cover-letter inherits diff options' ' |
Johannes Schindelin | 5d02294 | 2008-03-02 15:53:04 +0000 | [diff] [blame] | 672 | git mv file foo && |
| 673 | git commit -m foo && |
Matthieu Moy | 5404c11 | 2016-02-25 09:59:21 +0100 | [diff] [blame] | 674 | git format-patch --no-renames --cover-letter -1 && |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 675 | check_patch 0000-cover-letter.patch && |
Stephen Boyd | 9524cf2 | 2010-01-26 15:08:31 -0800 | [diff] [blame] | 676 | ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch && |
Johannes Schindelin | 5d02294 | 2008-03-02 15:53:04 +0000 | [diff] [blame] | 677 | git format-patch --cover-letter -1 -M && |
Stephen Boyd | 9524cf2 | 2010-01-26 15:08:31 -0800 | [diff] [blame] | 678 | grep "file => foo .* 0 *\$" 0000-cover-letter.patch |
Johannes Schindelin | 5d02294 | 2008-03-02 15:53:04 +0000 | [diff] [blame] | 679 | ' |
Johannes Schindelin | 859c4fb | 2008-03-02 15:53:39 +0000 | [diff] [blame] | 680 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 681 | cat >expect <<EOF |
Johannes Schindelin | 859c4fb | 2008-03-02 15:53:39 +0000 | [diff] [blame] | 682 | This is an excessively long subject line for a message due to the |
| 683 | habit some projects have of not having a short, one-line subject at |
| 684 | the start of the commit message, but rather sticking a whole |
| 685 | paragraph right at the start as the only thing in the commit |
| 686 | message. It had better not become the filename for the patch. |
| 687 | foo |
| 688 | |
| 689 | EOF |
| 690 | |
| 691 | test_expect_success 'shortlog of cover-letter wraps overly-long onelines' ' |
Johannes Schindelin | 859c4fb | 2008-03-02 15:53:39 +0000 | [diff] [blame] | 692 | git format-patch --cover-letter -2 && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 693 | sed -e "1,/A U Thor/d" -e "/^\$/q" 0000-cover-letter.patch >output && |
Junio C Hamano | 3af8286 | 2008-05-23 22:28:56 -0700 | [diff] [blame] | 694 | test_cmp expect output |
Johannes Schindelin | 859c4fb | 2008-03-02 15:53:39 +0000 | [diff] [blame] | 695 | ' |
| 696 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 697 | cat >expect <<EOF |
brian m. carlson | bdee9cd | 2018-05-21 02:01:36 +0000 | [diff] [blame] | 698 | index $before..$after 100644 |
Jeff King | 68daa64 | 2008-08-24 22:10:29 -0400 | [diff] [blame] | 699 | --- a/file |
| 700 | +++ b/file |
| 701 | @@ -13,4 +13,20 @@ C |
| 702 | 10 |
| 703 | D |
| 704 | E |
| 705 | F |
| 706 | +5 |
| 707 | EOF |
| 708 | |
| 709 | test_expect_success 'format-patch respects -U' ' |
Jeff King | 68daa64 | 2008-08-24 22:10:29 -0400 | [diff] [blame] | 710 | git format-patch -U4 -2 && |
Jonathan Nieder | 6dd8883 | 2012-03-13 00:05:54 -0500 | [diff] [blame] | 711 | sed -e "1,/^diff/d" -e "/^+5/q" \ |
| 712 | <0001-This-is-an-excessively-long-subject-line-for-a-messa.patch \ |
| 713 | >output && |
Jeff King | 68daa64 | 2008-08-24 22:10:29 -0400 | [diff] [blame] | 714 | test_cmp expect output |
Jeff King | 68daa64 | 2008-08-24 22:10:29 -0400 | [diff] [blame] | 715 | ' |
| 716 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 717 | cat >expect <<EOF |
Jeff King | 1d46f2e | 2009-11-04 02:19:40 -0500 | [diff] [blame] | 718 | |
| 719 | diff --git a/file b/file |
brian m. carlson | bdee9cd | 2018-05-21 02:01:36 +0000 | [diff] [blame] | 720 | index $before..$after 100644 |
Jeff King | 1d46f2e | 2009-11-04 02:19:40 -0500 | [diff] [blame] | 721 | --- a/file |
| 722 | +++ b/file |
| 723 | @@ -14,3 +14,19 @@ C |
| 724 | D |
| 725 | E |
| 726 | F |
| 727 | +5 |
| 728 | EOF |
| 729 | |
| 730 | test_expect_success 'format-patch -p suppresses stat' ' |
Jeff King | 1d46f2e | 2009-11-04 02:19:40 -0500 | [diff] [blame] | 731 | git format-patch -p -2 && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 732 | sed -e "1,/^\$/d" -e "/^+5/q" 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch >output && |
Jeff King | 1d46f2e | 2009-11-04 02:19:40 -0500 | [diff] [blame] | 733 | test_cmp expect output |
Jeff King | 1d46f2e | 2009-11-04 02:19:40 -0500 | [diff] [blame] | 734 | ' |
| 735 | |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 736 | test_expect_success 'format-patch from a subdirectory (1)' ' |
| 737 | filename=$( |
| 738 | rm -rf sub && |
| 739 | mkdir -p sub/dir && |
| 740 | cd sub/dir && |
| 741 | git format-patch -1 |
| 742 | ) && |
| 743 | case "$filename" in |
| 744 | 0*) |
| 745 | ;; # ok |
| 746 | *) |
| 747 | echo "Oops? $filename" |
| 748 | false |
| 749 | ;; |
| 750 | esac && |
| 751 | test -f "$filename" |
| 752 | ' |
| 753 | |
| 754 | test_expect_success 'format-patch from a subdirectory (2)' ' |
| 755 | filename=$( |
| 756 | rm -rf sub && |
| 757 | mkdir -p sub/dir && |
| 758 | cd sub/dir && |
| 759 | git format-patch -1 -o .. |
| 760 | ) && |
| 761 | case "$filename" in |
| 762 | ../0*) |
| 763 | ;; # ok |
| 764 | *) |
| 765 | echo "Oops? $filename" |
| 766 | false |
| 767 | ;; |
| 768 | esac && |
| 769 | basename=$(expr "$filename" : ".*/\(.*\)") && |
| 770 | test -f "sub/$basename" |
| 771 | ' |
| 772 | |
| 773 | test_expect_success 'format-patch from a subdirectory (3)' ' |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 774 | rm -f 0* && |
| 775 | filename=$( |
| 776 | rm -rf sub && |
| 777 | mkdir -p sub/dir && |
| 778 | cd sub/dir && |
Jeff King | 91c8b82 | 2009-08-09 04:38:11 -0400 | [diff] [blame] | 779 | git format-patch -1 -o "$TRASH_DIRECTORY" |
Junio C Hamano | 9800a75 | 2009-01-12 15:18:02 -0800 | [diff] [blame] | 780 | ) && |
| 781 | basename=$(expr "$filename" : ".*/\(.*\)") && |
| 782 | test -f "$basename" |
| 783 | ' |
| 784 | |
Stephen Boyd | f044fe2 | 2009-05-16 02:24:45 -0700 | [diff] [blame] | 785 | test_expect_success 'format-patch --in-reply-to' ' |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 786 | git format-patch -1 --stdout --in-reply-to "baz@foo.bar" >patch8 && |
Stephen Boyd | f044fe2 | 2009-05-16 02:24:45 -0700 | [diff] [blame] | 787 | grep "^In-Reply-To: <baz@foo.bar>" patch8 && |
| 788 | grep "^References: <baz@foo.bar>" patch8 |
| 789 | ' |
| 790 | |
| 791 | test_expect_success 'format-patch --signoff' ' |
Junio C Hamano | 212620f | 2012-10-17 20:48:25 -0700 | [diff] [blame] | 792 | git format-patch -1 --signoff --stdout >out && |
| 793 | grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" out |
| 794 | ' |
| 795 | |
| 796 | test_expect_success 'format-patch --notes --signoff' ' |
| 797 | git notes --ref test add -m "test message" HEAD && |
| 798 | git format-patch -1 --signoff --stdout --notes=test >out && |
Junio C Hamano | bd1470b | 2012-10-17 21:27:22 -0700 | [diff] [blame] | 799 | # Three dashes must come after S-o-b |
Junio C Hamano | 212620f | 2012-10-17 20:48:25 -0700 | [diff] [blame] | 800 | ! sed "/^Signed-off-by: /q" out | grep "test message" && |
Junio C Hamano | bd1470b | 2012-10-17 21:27:22 -0700 | [diff] [blame] | 801 | sed "1,/^Signed-off-by: /d" out | grep "test message" && |
| 802 | # Notes message must come after three dashes |
| 803 | ! sed "/^---$/q" out | grep "test message" && |
| 804 | sed "1,/^---$/d" out | grep "test message" |
Stephen Boyd | f044fe2 | 2009-05-16 02:24:45 -0700 | [diff] [blame] | 805 | ' |
| 806 | |
Denton Liu | 13cdf78 | 2019-05-16 19:14:14 -0400 | [diff] [blame] | 807 | test_expect_success 'format-patch notes output control' ' |
| 808 | git notes add -m "notes config message" HEAD && |
| 809 | test_when_finished git notes remove HEAD && |
| 810 | |
| 811 | git format-patch -1 --stdout >out && |
| 812 | ! grep "notes config message" out && |
| 813 | git format-patch -1 --stdout --notes >out && |
| 814 | grep "notes config message" out && |
| 815 | git format-patch -1 --stdout --no-notes >out && |
| 816 | ! grep "notes config message" out && |
| 817 | git format-patch -1 --stdout --notes --no-notes >out && |
| 818 | ! grep "notes config message" out && |
| 819 | git format-patch -1 --stdout --no-notes --notes >out && |
| 820 | grep "notes config message" out && |
| 821 | |
| 822 | test_config format.notes true && |
| 823 | git format-patch -1 --stdout >out && |
| 824 | grep "notes config message" out && |
| 825 | git format-patch -1 --stdout --notes >out && |
| 826 | grep "notes config message" out && |
| 827 | git format-patch -1 --stdout --no-notes >out && |
| 828 | ! grep "notes config message" out && |
| 829 | git format-patch -1 --stdout --notes --no-notes >out && |
| 830 | ! grep "notes config message" out && |
| 831 | git format-patch -1 --stdout --no-notes --notes >out && |
| 832 | grep "notes config message" out |
| 833 | ' |
| 834 | |
| 835 | test_expect_success 'format-patch with multiple notes refs' ' |
| 836 | git notes --ref note1 add -m "this is note 1" HEAD && |
| 837 | test_when_finished git notes --ref note1 remove HEAD && |
| 838 | git notes --ref note2 add -m "this is note 2" HEAD && |
| 839 | test_when_finished git notes --ref note2 remove HEAD && |
| 840 | |
| 841 | git format-patch -1 --stdout >out && |
| 842 | ! grep "this is note 1" out && |
| 843 | ! grep "this is note 2" out && |
| 844 | git format-patch -1 --stdout --notes=note1 >out && |
| 845 | grep "this is note 1" out && |
| 846 | ! grep "this is note 2" out && |
| 847 | git format-patch -1 --stdout --notes=note2 >out && |
| 848 | ! grep "this is note 1" out && |
| 849 | grep "this is note 2" out && |
| 850 | git format-patch -1 --stdout --notes=note1 --notes=note2 >out && |
| 851 | grep "this is note 1" out && |
| 852 | grep "this is note 2" out && |
| 853 | |
| 854 | test_config format.notes note1 && |
| 855 | git format-patch -1 --stdout >out && |
| 856 | grep "this is note 1" out && |
| 857 | ! grep "this is note 2" out && |
| 858 | git format-patch -1 --stdout --no-notes >out && |
| 859 | ! grep "this is note 1" out && |
| 860 | ! grep "this is note 2" out && |
| 861 | git format-patch -1 --stdout --notes=note2 >out && |
| 862 | grep "this is note 1" out && |
| 863 | grep "this is note 2" out && |
| 864 | git format-patch -1 --stdout --no-notes --notes=note2 >out && |
| 865 | ! grep "this is note 1" out && |
| 866 | grep "this is note 2" out && |
| 867 | |
| 868 | git config --add format.notes note2 && |
| 869 | git format-patch -1 --stdout >out && |
| 870 | grep "this is note 1" out && |
| 871 | grep "this is note 2" out && |
| 872 | git format-patch -1 --stdout --no-notes >out && |
| 873 | ! grep "this is note 1" out && |
| 874 | ! grep "this is note 2" out |
| 875 | ' |
| 876 | |
Denton Liu | 8164c96 | 2019-12-09 05:10:46 -0800 | [diff] [blame] | 877 | test_expect_success 'format-patch with multiple notes refs in config' ' |
| 878 | test_when_finished "test_unconfig format.notes" && |
| 879 | |
| 880 | git notes --ref note1 add -m "this is note 1" HEAD && |
| 881 | test_when_finished git notes --ref note1 remove HEAD && |
| 882 | git notes --ref note2 add -m "this is note 2" HEAD && |
| 883 | test_when_finished git notes --ref note2 remove HEAD && |
| 884 | |
| 885 | git config format.notes note1 && |
| 886 | git format-patch -1 --stdout >out && |
| 887 | grep "this is note 1" out && |
| 888 | ! grep "this is note 2" out && |
| 889 | git config format.notes note2 && |
| 890 | git format-patch -1 --stdout >out && |
| 891 | ! grep "this is note 1" out && |
| 892 | grep "this is note 2" out && |
| 893 | git config --add format.notes note1 && |
| 894 | git format-patch -1 --stdout >out && |
| 895 | grep "this is note 1" out && |
| 896 | grep "this is note 2" out && |
| 897 | |
| 898 | git config --replace-all format.notes note1 && |
| 899 | git config --add format.notes false && |
| 900 | git format-patch -1 --stdout >out && |
| 901 | ! grep "this is note 1" out && |
| 902 | ! grep "this is note 2" out && |
| 903 | git config --add format.notes note2 && |
| 904 | git format-patch -1 --stdout >out && |
| 905 | ! grep "this is note 1" out && |
| 906 | grep "this is note 2" out |
| 907 | ' |
| 908 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 909 | echo "fatal: --name-only does not make sense" >expect.name-only |
| 910 | echo "fatal: --name-status does not make sense" >expect.name-status |
| 911 | echo "fatal: --check does not make sense" >expect.check |
Björn Gustavsson | 02bc5b0 | 2009-11-07 10:51:56 +0100 | [diff] [blame] | 912 | |
Junio C Hamano | 68b2a00 | 2011-04-12 16:27:11 -0700 | [diff] [blame] | 913 | test_expect_success 'options no longer allowed for format-patch' ' |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 914 | test_must_fail git format-patch --name-only 2>output && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 915 | test_cmp expect.name-only output && |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 916 | test_must_fail git format-patch --name-status 2>output && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 917 | test_cmp expect.name-status output && |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 918 | test_must_fail git format-patch --check 2>output && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 919 | test_cmp expect.check output |
Denton Liu | cb46c40 | 2019-08-27 00:04:55 -0400 | [diff] [blame] | 920 | ' |
Björn Gustavsson | 02bc5b0 | 2009-11-07 10:51:56 +0100 | [diff] [blame] | 921 | |
| 922 | test_expect_success 'format-patch --numstat should produce a patch' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 923 | git format-patch --numstat --stdout main..side >output && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 924 | grep "^diff --git a/" output >diff && |
| 925 | test_line_count = 5 diff |
Denton Liu | cb46c40 | 2019-08-27 00:04:55 -0400 | [diff] [blame] | 926 | ' |
Björn Gustavsson | 02bc5b0 | 2009-11-07 10:51:56 +0100 | [diff] [blame] | 927 | |
Felipe Contreras | 7e93d3b | 2009-11-26 21:12:00 +0200 | [diff] [blame] | 928 | test_expect_success 'format-patch -- <path>' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 929 | git format-patch main..side -- file 2>error && |
Felipe Contreras | 7e93d3b | 2009-11-26 21:12:00 +0200 | [diff] [blame] | 930 | ! grep "Use .--" error |
| 931 | ' |
| 932 | |
Kevin Ballard | 657ab61 | 2010-03-29 19:46:38 -0700 | [diff] [blame] | 933 | test_expect_success 'format-patch --ignore-if-in-upstream HEAD' ' |
| 934 | git format-patch --ignore-if-in-upstream HEAD |
| 935 | ' |
| 936 | |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 937 | test_expect_success 'get git version' ' |
| 938 | git_version=$(git --version) && |
| 939 | git_version=${git_version##* } |
| 940 | ' |
Josh Triplett | 480871e | 2016-09-07 18:12:01 -0700 | [diff] [blame] | 941 | |
| 942 | signature() { |
| 943 | printf "%s\n%s\n\n" "-- " "${1:-$git_version}" |
| 944 | } |
| 945 | |
| 946 | test_expect_success 'format-patch default signature' ' |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 947 | git format-patch --stdout -1 >patch && |
| 948 | tail -n 3 patch >output && |
Josh Triplett | 480871e | 2016-09-07 18:12:01 -0700 | [diff] [blame] | 949 | signature >expect && |
| 950 | test_cmp expect output |
| 951 | ' |
| 952 | |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 953 | test_expect_success 'format-patch --signature' ' |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 954 | git format-patch --stdout --signature="my sig" -1 >patch && |
| 955 | tail -n 3 patch >output && |
Josh Triplett | 480871e | 2016-09-07 18:12:01 -0700 | [diff] [blame] | 956 | signature "my sig" >expect && |
| 957 | test_cmp expect output |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 958 | ' |
| 959 | |
| 960 | test_expect_success 'format-patch with format.signature config' ' |
| 961 | git config format.signature "config sig" && |
| 962 | git format-patch --stdout -1 >output && |
| 963 | grep "config sig" output |
| 964 | ' |
| 965 | |
| 966 | test_expect_success 'format-patch --signature overrides format.signature' ' |
| 967 | git config format.signature "config sig" && |
| 968 | git format-patch --stdout --signature="overrides" -1 >output && |
| 969 | ! grep "config sig" output && |
| 970 | grep "overrides" output |
| 971 | ' |
| 972 | |
| 973 | test_expect_success 'format-patch --no-signature ignores format.signature' ' |
| 974 | git config format.signature "config sig" && |
| 975 | git format-patch --stdout --signature="my sig" --no-signature \ |
| 976 | -1 >output && |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 977 | check_patch output && |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 978 | ! grep "config sig" output && |
| 979 | ! grep "my sig" output && |
| 980 | ! grep "^-- \$" output |
| 981 | ' |
| 982 | |
| 983 | test_expect_success 'format-patch --signature --cover-letter' ' |
| 984 | git config --unset-all format.signature && |
| 985 | git format-patch --stdout --signature="my sig" --cover-letter \ |
| 986 | -1 >output && |
Denton Liu | 6bd26f5 | 2019-08-27 00:05:10 -0400 | [diff] [blame] | 987 | grep "my sig" output >sig && |
| 988 | test_line_count = 2 sig |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 989 | ' |
| 990 | |
Stefano Lattarini | 41ccfdd | 2013-04-12 00:36:10 +0200 | [diff] [blame] | 991 | test_expect_success 'format.signature="" suppresses signatures' ' |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 992 | git config format.signature "" && |
| 993 | git format-patch --stdout -1 >output && |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 994 | check_patch output && |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 995 | ! grep "^-- \$" output |
| 996 | ' |
| 997 | |
Stefano Lattarini | 41ccfdd | 2013-04-12 00:36:10 +0200 | [diff] [blame] | 998 | test_expect_success 'format-patch --no-signature suppresses signatures' ' |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 999 | git config --unset-all format.signature && |
| 1000 | git format-patch --stdout --no-signature -1 >output && |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 1001 | check_patch output && |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 1002 | ! grep "^-- \$" output |
| 1003 | ' |
| 1004 | |
Stefano Lattarini | 41ccfdd | 2013-04-12 00:36:10 +0200 | [diff] [blame] | 1005 | test_expect_success 'format-patch --signature="" suppresses signatures' ' |
Thomas Rast | 2fdb5c6 | 2011-08-29 22:10:47 +0200 | [diff] [blame] | 1006 | git format-patch --stdout --signature="" -1 >output && |
Thomas Rast | cc663d1 | 2011-08-29 22:10:46 +0200 | [diff] [blame] | 1007 | check_patch output && |
Stephen Boyd | 6622d9c | 2010-06-15 22:59:25 -0700 | [diff] [blame] | 1008 | ! grep "^-- \$" output |
| 1009 | ' |
| 1010 | |
Jeremiah Mahler | 7022650 | 2014-05-23 21:08:14 -0700 | [diff] [blame] | 1011 | test_expect_success 'prepare mail-signature input' ' |
| 1012 | cat >mail-signature <<-\EOF |
| 1013 | |
| 1014 | Test User <test.email@kernel.org> |
| 1015 | http://git.kernel.org/cgit/git/git.git |
| 1016 | |
| 1017 | git.kernel.org/?p=git/git.git;a=summary |
| 1018 | |
| 1019 | EOF |
| 1020 | ' |
| 1021 | |
| 1022 | test_expect_success '--signature-file=file works' ' |
| 1023 | git format-patch --stdout --signature-file=mail-signature -1 >output && |
| 1024 | check_patch output && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1025 | sed -e "1,/^-- \$/d" output >actual && |
Jeremiah Mahler | 7022650 | 2014-05-23 21:08:14 -0700 | [diff] [blame] | 1026 | { |
| 1027 | cat mail-signature && echo |
| 1028 | } >expect && |
| 1029 | test_cmp expect actual |
| 1030 | ' |
| 1031 | |
| 1032 | test_expect_success 'format.signaturefile works' ' |
| 1033 | test_config format.signaturefile mail-signature && |
| 1034 | git format-patch --stdout -1 >output && |
| 1035 | check_patch output && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1036 | sed -e "1,/^-- \$/d" output >actual && |
Jeremiah Mahler | 7022650 | 2014-05-23 21:08:14 -0700 | [diff] [blame] | 1037 | { |
| 1038 | cat mail-signature && echo |
| 1039 | } >expect && |
| 1040 | test_cmp expect actual |
| 1041 | ' |
| 1042 | |
| 1043 | test_expect_success '--no-signature suppresses format.signaturefile ' ' |
| 1044 | test_config format.signaturefile mail-signature && |
| 1045 | git format-patch --stdout --no-signature -1 >output && |
| 1046 | check_patch output && |
| 1047 | ! grep "^-- \$" output |
| 1048 | ' |
| 1049 | |
| 1050 | test_expect_success '--signature-file overrides format.signaturefile' ' |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 1051 | cat >other-mail-signature <<-\EOF && |
Jeremiah Mahler | 7022650 | 2014-05-23 21:08:14 -0700 | [diff] [blame] | 1052 | Use this other signature instead of mail-signature. |
| 1053 | EOF |
| 1054 | test_config format.signaturefile mail-signature && |
| 1055 | git format-patch --stdout \ |
| 1056 | --signature-file=other-mail-signature -1 >output && |
| 1057 | check_patch output && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1058 | sed -e "1,/^-- \$/d" output >actual && |
Jeremiah Mahler | 7022650 | 2014-05-23 21:08:14 -0700 | [diff] [blame] | 1059 | { |
| 1060 | cat other-mail-signature && echo |
| 1061 | } >expect && |
| 1062 | test_cmp expect actual |
| 1063 | ' |
| 1064 | |
| 1065 | test_expect_success '--signature overrides format.signaturefile' ' |
| 1066 | test_config format.signaturefile mail-signature && |
| 1067 | git format-patch --stdout --signature="my sig" -1 >output && |
| 1068 | check_patch output && |
| 1069 | grep "my sig" output |
| 1070 | ' |
| 1071 | |
Tay Ray Chuan | 38a94bb | 2010-11-23 11:16:30 +0800 | [diff] [blame] | 1072 | test_expect_success TTY 'format-patch --stdout paginates' ' |
| 1073 | rm -f pager_used && |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame] | 1074 | test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all && |
Tay Ray Chuan | 38a94bb | 2010-11-23 11:16:30 +0800 | [diff] [blame] | 1075 | test_path_is_file pager_used |
| 1076 | ' |
| 1077 | |
| 1078 | test_expect_success TTY 'format-patch --stdout pagination can be disabled' ' |
| 1079 | rm -f pager_used && |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame] | 1080 | test_terminal env GIT_PAGER="wc >pager_used" git --no-pager format-patch --stdout --all && |
| 1081 | test_terminal env GIT_PAGER="wc >pager_used" git -c "pager.format-patch=false" format-patch --stdout --all && |
Tay Ray Chuan | 38a94bb | 2010-11-23 11:16:30 +0800 | [diff] [blame] | 1082 | test_path_is_missing pager_used && |
| 1083 | test_path_is_missing .git/pager_used |
| 1084 | ' |
| 1085 | |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1086 | test_expect_success 'format-patch handles multi-line subjects' ' |
| 1087 | rm -rf patches/ && |
| 1088 | echo content >>file && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 1089 | test_write_lines one two three >msg && |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1090 | git add file && |
| 1091 | git commit -F msg && |
| 1092 | git format-patch -o patches -1 && |
| 1093 | grep ^Subject: patches/0001-one.patch >actual && |
| 1094 | echo "Subject: [PATCH] one two three" >expect && |
| 1095 | test_cmp expect actual |
| 1096 | ' |
| 1097 | |
| 1098 | test_expect_success 'format-patch handles multi-line encoded subjects' ' |
| 1099 | rm -rf patches/ && |
| 1100 | echo content >>file && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 1101 | test_write_lines en två tre >msg && |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1102 | git add file && |
| 1103 | git commit -F msg && |
| 1104 | git format-patch -o patches -1 && |
| 1105 | grep ^Subject: patches/0001-en.patch >actual && |
| 1106 | echo "Subject: [PATCH] =?UTF-8?q?en=20tv=C3=A5=20tre?=" >expect && |
| 1107 | test_cmp expect actual |
| 1108 | ' |
| 1109 | |
| 1110 | M8="foo bar " |
| 1111 | M64=$M8$M8$M8$M8$M8$M8$M8$M8 |
| 1112 | M512=$M64$M64$M64$M64$M64$M64$M64$M64 |
| 1113 | cat >expect <<'EOF' |
| 1114 | Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo |
Jan H. Schönherr | 7a76e68 | 2012-10-18 16:43:29 +0200 | [diff] [blame] | 1115 | bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar |
| 1116 | foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo |
| 1117 | bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar |
| 1118 | foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo |
| 1119 | bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar |
| 1120 | foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1121 | EOF |
Jan H. Schönherr | 7a76e68 | 2012-10-18 16:43:29 +0200 | [diff] [blame] | 1122 | test_expect_success 'format-patch wraps extremely long subject (ascii)' ' |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1123 | echo content >>file && |
| 1124 | git add file && |
| 1125 | git commit -m "$M512" && |
| 1126 | git format-patch --stdout -1 >patch && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1127 | sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject && |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1128 | test_cmp expect subject |
| 1129 | ' |
| 1130 | |
| 1131 | M8="föö bar " |
| 1132 | M64=$M8$M8$M8$M8$M8$M8$M8$M8 |
| 1133 | M512=$M64$M64$M64$M64$M64$M64$M64$M64 |
| 1134 | cat >expect <<'EOF' |
Jan H. Schönherr | 94f6cdf | 2012-10-18 16:43:30 +0200 | [diff] [blame] | 1135 | Subject: [PATCH] =?UTF-8?q?f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?= |
| 1136 | =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= |
| 1137 | =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?= |
| 1138 | =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?= |
Kirill Smelkov | 6cd3c05 | 2013-03-07 14:55:07 +0400 | [diff] [blame] | 1139 | =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= |
| 1140 | =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?= |
Jan H. Schönherr | 94f6cdf | 2012-10-18 16:43:30 +0200 | [diff] [blame] | 1141 | =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= |
| 1142 | =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?= |
| 1143 | =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?= |
Kirill Smelkov | 6cd3c05 | 2013-03-07 14:55:07 +0400 | [diff] [blame] | 1144 | =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= |
| 1145 | =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?= |
Jan H. Schönherr | 94f6cdf | 2012-10-18 16:43:30 +0200 | [diff] [blame] | 1146 | =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= |
| 1147 | =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?= |
| 1148 | =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?= |
Kirill Smelkov | 6cd3c05 | 2013-03-07 14:55:07 +0400 | [diff] [blame] | 1149 | =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= |
| 1150 | =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?= |
| 1151 | =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= |
| 1152 | =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?= |
| 1153 | =?UTF-8?q?bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6?= |
| 1154 | =?UTF-8?q?=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= |
| 1155 | =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f?= |
| 1156 | =?UTF-8?q?=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= |
| 1157 | =?UTF-8?q?=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20?= |
| 1158 | =?UTF-8?q?bar?= |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1159 | EOF |
Jan H. Schönherr | 94f6cdf | 2012-10-18 16:43:30 +0200 | [diff] [blame] | 1160 | test_expect_success 'format-patch wraps extremely long subject (rfc2047)' ' |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1161 | rm -rf patches/ && |
| 1162 | echo content >>file && |
| 1163 | git add file && |
| 1164 | git commit -m "$M512" && |
| 1165 | git format-patch --stdout -1 >patch && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1166 | sed -n "/^Subject/p; /^ /p; /^$/q" patch >subject && |
Jeff King | a1f6baa | 2011-02-23 04:58:41 -0500 | [diff] [blame] | 1167 | test_cmp expect subject |
| 1168 | ' |
| 1169 | |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1170 | check_author() { |
| 1171 | echo content >>file && |
| 1172 | git add file && |
| 1173 | GIT_AUTHOR_NAME=$1 git commit -m author-check && |
| 1174 | git format-patch --stdout -1 >patch && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1175 | sed -n "/^From: /p; /^ /p; /^$/q" patch >actual && |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1176 | test_cmp expect actual |
| 1177 | } |
| 1178 | |
| 1179 | cat >expect <<'EOF' |
| 1180 | From: "Foo B. Bar" <author@example.com> |
| 1181 | EOF |
Jan H. Schönherr | 0fcec2c | 2012-10-18 16:43:32 +0200 | [diff] [blame] | 1182 | test_expect_success 'format-patch quotes dot in from-headers' ' |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1183 | check_author "Foo B. Bar" |
| 1184 | ' |
| 1185 | |
| 1186 | cat >expect <<'EOF' |
| 1187 | From: "Foo \"The Baz\" Bar" <author@example.com> |
| 1188 | EOF |
Jan H. Schönherr | 0fcec2c | 2012-10-18 16:43:32 +0200 | [diff] [blame] | 1189 | test_expect_success 'format-patch quotes double-quote in from-headers' ' |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1190 | check_author "Foo \"The Baz\" Bar" |
| 1191 | ' |
| 1192 | |
| 1193 | cat >expect <<'EOF' |
Jan H. Schönherr | 0fcec2c | 2012-10-18 16:43:32 +0200 | [diff] [blame] | 1194 | From: =?UTF-8?q?F=C3=B6o=20Bar?= <author@example.com> |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1195 | EOF |
Jan H. Schönherr | 0fcec2c | 2012-10-18 16:43:32 +0200 | [diff] [blame] | 1196 | test_expect_success 'format-patch uses rfc2047-encoded from-headers when necessary' ' |
| 1197 | check_author "Föo Bar" |
| 1198 | ' |
| 1199 | |
| 1200 | cat >expect <<'EOF' |
| 1201 | From: =?UTF-8?q?F=C3=B6o=20B=2E=20Bar?= <author@example.com> |
| 1202 | EOF |
Jan H. Schönherr | 41dd00b | 2012-10-18 16:43:33 +0200 | [diff] [blame] | 1203 | test_expect_success 'rfc2047-encoded from-headers leave no rfc822 specials' ' |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1204 | check_author "Föo B. Bar" |
| 1205 | ' |
| 1206 | |
Jan H. Schönherr | 7a76e68 | 2012-10-18 16:43:29 +0200 | [diff] [blame] | 1207 | cat >expect <<EOF |
| 1208 | From: foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_ |
| 1209 | <author@example.com> |
| 1210 | EOF |
| 1211 | test_expect_success 'format-patch wraps moderately long from-header (ascii)' ' |
| 1212 | check_author "foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_" |
| 1213 | ' |
| 1214 | |
| 1215 | cat >expect <<'EOF' |
| 1216 | From: Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar |
| 1217 | Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo |
| 1218 | Bar Foo Bar Foo Bar Foo Bar <author@example.com> |
| 1219 | EOF |
| 1220 | test_expect_success 'format-patch wraps extremely long from-header (ascii)' ' |
| 1221 | check_author "Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" |
| 1222 | ' |
| 1223 | |
| 1224 | cat >expect <<'EOF' |
| 1225 | From: "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar |
| 1226 | Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo |
| 1227 | Bar Foo Bar Foo Bar Foo Bar" <author@example.com> |
| 1228 | EOF |
| 1229 | test_expect_success 'format-patch wraps extremely long from-header (rfc822)' ' |
| 1230 | check_author "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" |
| 1231 | ' |
| 1232 | |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1233 | cat >expect <<'EOF' |
Jan H. Schönherr | 94f6cdf | 2012-10-18 16:43:30 +0200 | [diff] [blame] | 1234 | From: =?UTF-8?q?Fo=C3=B6=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo?= |
| 1235 | =?UTF-8?q?=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20?= |
| 1236 | =?UTF-8?q?Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar?= |
| 1237 | =?UTF-8?q?=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20Foo=20Bar=20?= |
| 1238 | =?UTF-8?q?Foo=20Bar=20Foo=20Bar?= <author@example.com> |
| 1239 | EOF |
| 1240 | test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' ' |
| 1241 | check_author "Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" |
| 1242 | ' |
| 1243 | |
| 1244 | cat >expect <<'EOF' |
Emma Brooks | 19d097e | 2020-04-08 04:31:38 +0000 | [diff] [blame] | 1245 | From: Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar |
| 1246 | Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo |
| 1247 | Bar Foo Bar Foo Bar Foo Bar <author@example.com> |
| 1248 | EOF |
| 1249 | test_expect_success 'format-patch wraps extremely long from-header (non-ASCII without Q-encoding)' ' |
| 1250 | echo content >>file && |
| 1251 | git add file && |
| 1252 | GIT_AUTHOR_NAME="Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" \ |
| 1253 | git commit -m author-check && |
| 1254 | git format-patch --no-encode-email-headers --stdout -1 >patch && |
| 1255 | sed -n "/^From: /p; /^ /p; /^$/q" patch >actual && |
| 1256 | test_cmp expect actual |
| 1257 | ' |
| 1258 | |
| 1259 | cat >expect <<'EOF' |
| 1260 | Subject: [PATCH] Foö |
| 1261 | EOF |
| 1262 | test_expect_success 'subject lines are unencoded with --no-encode-email-headers' ' |
| 1263 | echo content >>file && |
| 1264 | git add file && |
| 1265 | git commit -m "Foö" && |
| 1266 | git format-patch --no-encode-email-headers -1 --stdout >patch && |
| 1267 | grep ^Subject: patch >actual && |
| 1268 | test_cmp expect actual |
| 1269 | ' |
| 1270 | |
| 1271 | cat >expect <<'EOF' |
| 1272 | Subject: [PATCH] Foö |
| 1273 | EOF |
| 1274 | test_expect_success 'subject lines are unencoded with format.encodeEmailHeaders=false' ' |
| 1275 | echo content >>file && |
| 1276 | git add file && |
| 1277 | git commit -m "Foö" && |
| 1278 | git config format.encodeEmailHeaders false && |
| 1279 | git format-patch -1 --stdout >patch && |
| 1280 | grep ^Subject: patch >actual && |
| 1281 | test_cmp expect actual |
| 1282 | ' |
| 1283 | |
| 1284 | cat >expect <<'EOF' |
| 1285 | Subject: [PATCH] =?UTF-8?q?Fo=C3=B6?= |
| 1286 | EOF |
| 1287 | test_expect_success '--encode-email-headers overrides format.encodeEmailHeaders' ' |
| 1288 | echo content >>file && |
| 1289 | git add file && |
| 1290 | git commit -m "Foö" && |
| 1291 | git config format.encodeEmailHeaders false && |
| 1292 | git format-patch --encode-email-headers -1 --stdout >patch && |
| 1293 | grep ^Subject: patch >actual && |
| 1294 | test_cmp expect actual |
| 1295 | ' |
| 1296 | |
| 1297 | cat >expect <<'EOF' |
Jeff King | 4d03c18 | 2011-04-08 18:40:36 -0400 | [diff] [blame] | 1298 | Subject: header with . in it |
| 1299 | EOF |
| 1300 | test_expect_success 'subject lines do not have 822 atom-quoting' ' |
| 1301 | echo content >>file && |
| 1302 | git add file && |
| 1303 | git commit -m "header with . in it" && |
| 1304 | git format-patch -k -1 --stdout >patch && |
| 1305 | grep ^Subject: patch >actual && |
| 1306 | test_cmp expect actual |
| 1307 | ' |
| 1308 | |
Jeff King | e7af8e4 | 2011-05-30 10:19:05 -0400 | [diff] [blame] | 1309 | cat >expect <<'EOF' |
| 1310 | Subject: [PREFIX 1/1] header with . in it |
| 1311 | EOF |
| 1312 | test_expect_success 'subject prefixes have space prepended' ' |
| 1313 | git format-patch -n -1 --stdout --subject-prefix=PREFIX >patch && |
| 1314 | grep ^Subject: patch >actual && |
| 1315 | test_cmp expect actual |
| 1316 | ' |
| 1317 | |
| 1318 | cat >expect <<'EOF' |
| 1319 | Subject: [1/1] header with . in it |
| 1320 | EOF |
| 1321 | test_expect_success 'empty subject prefix does not have extra space' ' |
| 1322 | git format-patch -n -1 --stdout --subject-prefix= >patch && |
| 1323 | grep ^Subject: patch >actual && |
| 1324 | test_cmp expect actual |
| 1325 | ' |
| 1326 | |
Josh Triplett | 68e83a5 | 2016-09-19 21:23:25 -0700 | [diff] [blame] | 1327 | test_expect_success '--rfc' ' |
| 1328 | cat >expect <<-\EOF && |
| 1329 | Subject: [RFC PATCH 1/1] header with . in it |
| 1330 | EOF |
| 1331 | git format-patch -n -1 --stdout --rfc >patch && |
| 1332 | grep ^Subject: patch >actual && |
| 1333 | test_cmp expect actual |
| 1334 | ' |
| 1335 | |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1336 | test_expect_success '--from=ident notices bogus ident' ' |
| 1337 | test_must_fail git format-patch -1 --stdout --from=foo >patch |
| 1338 | ' |
| 1339 | |
| 1340 | test_expect_success '--from=ident replaces author' ' |
| 1341 | git format-patch -1 --stdout --from="Me <me@example.com>" >patch && |
| 1342 | cat >expect <<-\EOF && |
| 1343 | From: Me <me@example.com> |
| 1344 | |
| 1345 | From: A U Thor <author@example.com> |
| 1346 | |
| 1347 | EOF |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1348 | sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1349 | test_cmp expect patch.head |
| 1350 | ' |
| 1351 | |
| 1352 | test_expect_success '--from uses committer ident' ' |
| 1353 | git format-patch -1 --stdout --from >patch && |
| 1354 | cat >expect <<-\EOF && |
| 1355 | From: C O Mitter <committer@example.com> |
| 1356 | |
| 1357 | From: A U Thor <author@example.com> |
| 1358 | |
| 1359 | EOF |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1360 | sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1361 | test_cmp expect patch.head |
| 1362 | ' |
| 1363 | |
Jeff King | 662cc30 | 2013-09-20 06:16:28 -0400 | [diff] [blame] | 1364 | test_expect_success '--from omits redundant in-body header' ' |
| 1365 | git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch && |
| 1366 | cat >expect <<-\EOF && |
| 1367 | From: A U Thor <author@example.com> |
| 1368 | |
| 1369 | EOF |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1370 | sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && |
Jeff King | 662cc30 | 2013-09-20 06:16:28 -0400 | [diff] [blame] | 1371 | test_cmp expect patch.head |
| 1372 | ' |
| 1373 | |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1374 | test_expect_success 'in-body headers trigger content encoding' ' |
Jeff King | d2554c7 | 2016-06-01 03:04:26 -0400 | [diff] [blame] | 1375 | test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic && |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1376 | test_when_finished "git reset --hard HEAD^" && |
| 1377 | git format-patch -1 --stdout --from >patch && |
| 1378 | cat >expect <<-\EOF && |
| 1379 | From: C O Mitter <committer@example.com> |
| 1380 | Content-Type: text/plain; charset=UTF-8 |
| 1381 | |
| 1382 | From: éxötìc <author@example.com> |
| 1383 | |
| 1384 | EOF |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 1385 | sed -ne "/^From:/p; /^$/p; /^Content-Type/p; /^---$/q" patch >patch.head && |
Jeff King | a908047 | 2013-07-03 03:08:22 -0400 | [diff] [blame] | 1386 | test_cmp expect patch.head |
| 1387 | ' |
| 1388 | |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1389 | append_signoff() |
| 1390 | { |
| 1391 | C=$(git commit-tree HEAD^^{tree} -p HEAD) && |
| 1392 | git format-patch --stdout --signoff $C^..$C >append_signoff.patch && |
| 1393 | sed -n -e "1,/^---$/p" append_signoff.patch | |
| 1394 | egrep -n "^Subject|Sign|^$" |
| 1395 | } |
| 1396 | |
| 1397 | test_expect_success 'signoff: commit with no body' ' |
| 1398 | append_signoff </dev/null >actual && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1399 | cat <<-\EOF | sed "s/EOL$//" >expect && |
| 1400 | 4:Subject: [PATCH] EOL |
| 1401 | 8: |
| 1402 | 9:Signed-off-by: C O Mitter <committer@example.com> |
| 1403 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1404 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1405 | ' |
| 1406 | |
| 1407 | test_expect_success 'signoff: commit with only subject' ' |
| 1408 | echo subject | append_signoff >actual && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1409 | cat >expect <<-\EOF && |
| 1410 | 4:Subject: [PATCH] subject |
| 1411 | 8: |
| 1412 | 9:Signed-off-by: C O Mitter <committer@example.com> |
| 1413 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1414 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1415 | ' |
| 1416 | |
| 1417 | test_expect_success 'signoff: commit with only subject that does not end with NL' ' |
| 1418 | printf subject | append_signoff >actual && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1419 | cat >expect <<-\EOF && |
| 1420 | 4:Subject: [PATCH] subject |
| 1421 | 8: |
| 1422 | 9:Signed-off-by: C O Mitter <committer@example.com> |
| 1423 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1424 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1425 | ' |
| 1426 | |
| 1427 | test_expect_success 'signoff: no existing signoffs' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1428 | append_signoff <<-\EOF >actual && |
| 1429 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1430 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1431 | body |
| 1432 | EOF |
| 1433 | cat >expect <<-\EOF && |
| 1434 | 4:Subject: [PATCH] subject |
| 1435 | 8: |
| 1436 | 10: |
| 1437 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1438 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1439 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1440 | ' |
| 1441 | |
| 1442 | test_expect_success 'signoff: no existing signoffs and no trailing NL' ' |
| 1443 | printf "subject\n\nbody" | append_signoff >actual && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1444 | cat >expect <<-\EOF && |
| 1445 | 4:Subject: [PATCH] subject |
| 1446 | 8: |
| 1447 | 10: |
| 1448 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1449 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1450 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1451 | ' |
| 1452 | |
| 1453 | test_expect_success 'signoff: some random signoff' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1454 | append_signoff <<-\EOF >actual && |
| 1455 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1456 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1457 | body |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1458 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1459 | Signed-off-by: my@house |
| 1460 | EOF |
| 1461 | cat >expect <<-\EOF && |
| 1462 | 4:Subject: [PATCH] subject |
| 1463 | 8: |
| 1464 | 10: |
| 1465 | 11:Signed-off-by: my@house |
| 1466 | 12:Signed-off-by: C O Mitter <committer@example.com> |
| 1467 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1468 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1469 | ' |
| 1470 | |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1471 | test_expect_success 'signoff: misc conforming footer elements' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1472 | append_signoff <<-\EOF >actual && |
| 1473 | subject |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1474 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1475 | body |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1476 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1477 | Signed-off-by: my@house |
| 1478 | (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709) |
| 1479 | Tested-by: Some One <someone@example.com> |
| 1480 | Bug: 1234 |
| 1481 | EOF |
| 1482 | cat >expect <<-\EOF && |
| 1483 | 4:Subject: [PATCH] subject |
| 1484 | 8: |
| 1485 | 10: |
| 1486 | 11:Signed-off-by: my@house |
| 1487 | 15:Signed-off-by: C O Mitter <committer@example.com> |
| 1488 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1489 | test_cmp expect actual |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1490 | ' |
| 1491 | |
| 1492 | test_expect_success 'signoff: some random signoff-alike' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1493 | append_signoff <<-\EOF >actual && |
| 1494 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1495 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1496 | body |
| 1497 | Fooled-by-me: my@house |
| 1498 | EOF |
| 1499 | cat >expect <<-\EOF && |
| 1500 | 4:Subject: [PATCH] subject |
| 1501 | 8: |
| 1502 | 11: |
| 1503 | 12:Signed-off-by: C O Mitter <committer@example.com> |
| 1504 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1505 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1506 | ' |
| 1507 | |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1508 | test_expect_success 'signoff: not really a signoff' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1509 | append_signoff <<-\EOF >actual && |
| 1510 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1511 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1512 | I want to mention about Signed-off-by: here. |
| 1513 | EOF |
| 1514 | cat >expect <<-\EOF && |
| 1515 | 4:Subject: [PATCH] subject |
| 1516 | 8: |
| 1517 | 9:I want to mention about Signed-off-by: here. |
| 1518 | 10: |
| 1519 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1520 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1521 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1522 | ' |
| 1523 | |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1524 | test_expect_success 'signoff: not really a signoff (2)' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1525 | append_signoff <<-\EOF >actual && |
| 1526 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1527 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1528 | My unfortunate |
| 1529 | Signed-off-by: example happens to be wrapped here. |
| 1530 | EOF |
| 1531 | cat >expect <<-\EOF && |
| 1532 | 4:Subject: [PATCH] subject |
| 1533 | 8: |
| 1534 | 10:Signed-off-by: example happens to be wrapped here. |
| 1535 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1536 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1537 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1538 | ' |
| 1539 | |
Brandon Casey | 959a262 | 2013-02-12 02:17:39 -0800 | [diff] [blame] | 1540 | test_expect_success 'signoff: valid S-o-b paragraph in the middle' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1541 | append_signoff <<-\EOF >actual && |
| 1542 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1543 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1544 | Signed-off-by: my@house |
| 1545 | Signed-off-by: your@house |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1546 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1547 | A lot of houses. |
| 1548 | EOF |
| 1549 | cat >expect <<-\EOF && |
| 1550 | 4:Subject: [PATCH] subject |
| 1551 | 8: |
| 1552 | 9:Signed-off-by: my@house |
| 1553 | 10:Signed-off-by: your@house |
| 1554 | 11: |
| 1555 | 13: |
| 1556 | 14:Signed-off-by: C O Mitter <committer@example.com> |
| 1557 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1558 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1559 | ' |
| 1560 | |
| 1561 | test_expect_success 'signoff: the same signoff at the end' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1562 | append_signoff <<-\EOF >actual && |
| 1563 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1564 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1565 | body |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1566 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1567 | Signed-off-by: C O Mitter <committer@example.com> |
| 1568 | EOF |
| 1569 | cat >expect <<-\EOF && |
| 1570 | 4:Subject: [PATCH] subject |
| 1571 | 8: |
| 1572 | 10: |
| 1573 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1574 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1575 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1576 | ' |
| 1577 | |
| 1578 | test_expect_success 'signoff: the same signoff at the end, no trailing NL' ' |
| 1579 | printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" | |
| 1580 | append_signoff >actual && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1581 | cat >expect <<-\EOF && |
| 1582 | 4:Subject: [PATCH] subject |
| 1583 | 8: |
| 1584 | 9:Signed-off-by: C O Mitter <committer@example.com> |
| 1585 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1586 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1587 | ' |
| 1588 | |
| 1589 | test_expect_success 'signoff: the same signoff NOT at the end' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1590 | append_signoff <<-\EOF >actual && |
| 1591 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1592 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1593 | body |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1594 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1595 | Signed-off-by: C O Mitter <committer@example.com> |
| 1596 | Signed-off-by: my@house |
| 1597 | EOF |
| 1598 | cat >expect <<-\EOF && |
| 1599 | 4:Subject: [PATCH] subject |
| 1600 | 8: |
| 1601 | 10: |
| 1602 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1603 | 12:Signed-off-by: my@house |
| 1604 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1605 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1606 | ' |
| 1607 | |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 1608 | test_expect_success 'signoff: tolerate garbage in conforming footer' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1609 | append_signoff <<-\EOF >actual && |
| 1610 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1611 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1612 | body |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1613 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1614 | Tested-by: my@house |
| 1615 | Some Trash |
| 1616 | Signed-off-by: C O Mitter <committer@example.com> |
| 1617 | EOF |
| 1618 | cat >expect <<-\EOF && |
| 1619 | 4:Subject: [PATCH] subject |
| 1620 | 8: |
| 1621 | 10: |
| 1622 | 13:Signed-off-by: C O Mitter <committer@example.com> |
| 1623 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1624 | test_cmp expect actual |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 1625 | ' |
| 1626 | |
| 1627 | test_expect_success 'signoff: respect trailer config' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1628 | append_signoff <<-\EOF >actual && |
| 1629 | subject |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 1630 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1631 | Myfooter: x |
| 1632 | Some Trash |
| 1633 | EOF |
| 1634 | cat >expect <<-\EOF && |
| 1635 | 4:Subject: [PATCH] subject |
| 1636 | 8: |
| 1637 | 11: |
| 1638 | 12:Signed-off-by: C O Mitter <committer@example.com> |
| 1639 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1640 | test_cmp expect actual && |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 1641 | |
| 1642 | test_config trailer.Myfooter.ifexists add && |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1643 | append_signoff <<-\EOF >actual && |
| 1644 | subject |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 1645 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1646 | Myfooter: x |
| 1647 | Some Trash |
| 1648 | EOF |
| 1649 | cat >expect <<-\EOF && |
| 1650 | 4:Subject: [PATCH] subject |
| 1651 | 8: |
| 1652 | 11:Signed-off-by: C O Mitter <committer@example.com> |
| 1653 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1654 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1655 | ' |
| 1656 | |
| 1657 | test_expect_success 'signoff: footer begins with non-signoff without @ sign' ' |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1658 | append_signoff <<-\EOF >actual && |
| 1659 | subject |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1660 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1661 | body |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1662 | |
Denton Liu | 460609c | 2019-08-27 00:05:03 -0400 | [diff] [blame] | 1663 | Reviewed-id: Noone |
| 1664 | Tested-by: my@house |
| 1665 | Change-id: Ideadbeef |
| 1666 | Signed-off-by: C O Mitter <committer@example.com> |
| 1667 | Bug: 1234 |
| 1668 | EOF |
| 1669 | cat >expect <<-\EOF && |
| 1670 | 4:Subject: [PATCH] subject |
| 1671 | 8: |
| 1672 | 10: |
| 1673 | 14:Signed-off-by: C O Mitter <committer@example.com> |
| 1674 | EOF |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 1675 | test_cmp expect actual |
Nguyễn Thái Ngọc Duy | 79133a6 | 2013-02-12 02:17:37 -0800 | [diff] [blame] | 1676 | ' |
| 1677 | |
Pang Yan Han | 787570c | 2011-09-13 01:46:41 +0800 | [diff] [blame] | 1678 | test_expect_success 'format patch ignores color.ui' ' |
| 1679 | test_unconfig color.ui && |
| 1680 | git format-patch --stdout -1 >expect && |
| 1681 | test_config color.ui always && |
| 1682 | git format-patch --stdout -1 >actual && |
| 1683 | test_cmp expect actual |
| 1684 | ' |
| 1685 | |
Laurent Arnoud | c28ded8 | 2020-05-22 12:46:18 +0200 | [diff] [blame] | 1686 | test_expect_success 'format patch respects diff.relative' ' |
| 1687 | rm -rf subdir && |
| 1688 | mkdir subdir && |
| 1689 | echo other content >subdir/file2 && |
| 1690 | git add subdir/file2 && |
| 1691 | git commit -F msg && |
| 1692 | test_unconfig diff.relative && |
| 1693 | git format-patch --relative=subdir --stdout -1 >expect && |
| 1694 | test_config diff.relative true && |
| 1695 | git -C subdir format-patch --stdout -1 >actual && |
| 1696 | test_cmp expect actual |
| 1697 | ' |
| 1698 | |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1699 | test_expect_success 'cover letter with invalid --cover-from-description and config' ' |
| 1700 | test_config branch.rebuild-1.description "config subject |
| 1701 | |
| 1702 | body" && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1703 | test_must_fail git format-patch --cover-letter --cover-from-description garbage main && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1704 | test_config format.coverFromDescription garbage && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1705 | test_must_fail git format-patch --cover-letter main |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1706 | ' |
| 1707 | |
| 1708 | test_expect_success 'cover letter with format.coverFromDescription = default' ' |
| 1709 | test_config branch.rebuild-1.description "config subject |
| 1710 | |
| 1711 | body" && |
| 1712 | test_config format.coverFromDescription default && |
| 1713 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1714 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1715 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1716 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1717 | grep "^config subject$" actual && |
| 1718 | grep "^body$" actual |
| 1719 | ' |
| 1720 | |
| 1721 | test_expect_success 'cover letter with --cover-from-description default' ' |
| 1722 | test_config branch.rebuild-1.description "config subject |
| 1723 | |
| 1724 | body" && |
| 1725 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1726 | git format-patch --stdout --cover-letter --cover-from-description default main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1727 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1728 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1729 | grep "^config subject$" actual && |
| 1730 | grep "^body$" actual |
| 1731 | ' |
| 1732 | |
| 1733 | test_expect_success 'cover letter with format.coverFromDescription = none' ' |
| 1734 | test_config branch.rebuild-1.description "config subject |
| 1735 | |
| 1736 | body" && |
| 1737 | test_config format.coverFromDescription none && |
| 1738 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1739 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1740 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1741 | grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1742 | ! grep "^config subject$" actual && |
| 1743 | ! grep "^body$" actual |
| 1744 | ' |
| 1745 | |
| 1746 | test_expect_success 'cover letter with --cover-from-description none' ' |
| 1747 | test_config branch.rebuild-1.description "config subject |
| 1748 | |
| 1749 | body" && |
| 1750 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1751 | git format-patch --stdout --cover-letter --cover-from-description none main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1752 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1753 | grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1754 | ! grep "^config subject$" actual && |
| 1755 | ! grep "^body$" actual |
| 1756 | ' |
| 1757 | |
| 1758 | test_expect_success 'cover letter with format.coverFromDescription = message' ' |
| 1759 | test_config branch.rebuild-1.description "config subject |
| 1760 | |
| 1761 | body" && |
| 1762 | test_config format.coverFromDescription message && |
| 1763 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1764 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1765 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1766 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1767 | grep "^config subject$" actual && |
| 1768 | grep "^body$" actual |
| 1769 | ' |
| 1770 | |
| 1771 | test_expect_success 'cover letter with --cover-from-description message' ' |
| 1772 | test_config branch.rebuild-1.description "config subject |
| 1773 | |
| 1774 | body" && |
| 1775 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1776 | git format-patch --stdout --cover-letter --cover-from-description message main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1777 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1778 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1779 | grep "^config subject$" actual && |
| 1780 | grep "^body$" actual |
| 1781 | ' |
| 1782 | |
| 1783 | test_expect_success 'cover letter with format.coverFromDescription = subject' ' |
| 1784 | test_config branch.rebuild-1.description "config subject |
| 1785 | |
| 1786 | body" && |
| 1787 | test_config format.coverFromDescription subject && |
| 1788 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1789 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1790 | grep "^Subject: \[PATCH 0/2\] config subject$" actual && |
| 1791 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1792 | ! grep "^config subject$" actual && |
| 1793 | grep "^body$" actual |
| 1794 | ' |
| 1795 | |
| 1796 | test_expect_success 'cover letter with --cover-from-description subject' ' |
| 1797 | test_config branch.rebuild-1.description "config subject |
| 1798 | |
| 1799 | body" && |
| 1800 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1801 | git format-patch --stdout --cover-letter --cover-from-description subject main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1802 | grep "^Subject: \[PATCH 0/2\] config subject$" actual && |
| 1803 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1804 | ! grep "^config subject$" actual && |
| 1805 | grep "^body$" actual |
| 1806 | ' |
| 1807 | |
| 1808 | test_expect_success 'cover letter with format.coverFromDescription = auto (short subject line)' ' |
| 1809 | test_config branch.rebuild-1.description "config subject |
| 1810 | |
| 1811 | body" && |
| 1812 | test_config format.coverFromDescription auto && |
| 1813 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1814 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1815 | grep "^Subject: \[PATCH 0/2\] config subject$" actual && |
| 1816 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1817 | ! grep "^config subject$" actual && |
| 1818 | grep "^body$" actual |
| 1819 | ' |
| 1820 | |
| 1821 | test_expect_success 'cover letter with --cover-from-description auto (short subject line)' ' |
| 1822 | test_config branch.rebuild-1.description "config subject |
| 1823 | |
| 1824 | body" && |
| 1825 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1826 | git format-patch --stdout --cover-letter --cover-from-description auto main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1827 | grep "^Subject: \[PATCH 0/2\] config subject$" actual && |
| 1828 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1829 | ! grep "^config subject$" actual && |
| 1830 | grep "^body$" actual |
| 1831 | ' |
| 1832 | |
| 1833 | test_expect_success 'cover letter with format.coverFromDescription = auto (long subject line)' ' |
| 1834 | test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects |
| 1835 | |
| 1836 | body" && |
| 1837 | test_config format.coverFromDescription auto && |
| 1838 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1839 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1840 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1841 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1842 | grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual && |
| 1843 | grep "^body$" actual |
| 1844 | ' |
| 1845 | |
| 1846 | test_expect_success 'cover letter with --cover-from-description auto (long subject line)' ' |
| 1847 | test_config branch.rebuild-1.description "this is a really long first line and it is over 100 characters long which is the threshold for long subjects |
| 1848 | |
| 1849 | body" && |
| 1850 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1851 | git format-patch --stdout --cover-letter --cover-from-description auto main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1852 | grep "^Subject: \[PATCH 0/2\] \*\*\* SUBJECT HERE \*\*\*$" actual && |
| 1853 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1854 | grep "^this is a really long first line and it is over 100 characters long which is the threshold for long subjects$" actual && |
| 1855 | grep "^body$" actual |
| 1856 | ' |
| 1857 | |
| 1858 | test_expect_success 'cover letter with command-line --cover-from-description overrides config' ' |
| 1859 | test_config branch.rebuild-1.description "config subject |
| 1860 | |
| 1861 | body" && |
| 1862 | test_config format.coverFromDescription none && |
| 1863 | git checkout rebuild-1 && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1864 | git format-patch --stdout --cover-letter --cover-from-description subject main >actual && |
Denton Liu | bf8e65b | 2019-10-15 02:06:40 -0700 | [diff] [blame] | 1865 | grep "^Subject: \[PATCH 0/2\] config subject$" actual && |
| 1866 | ! grep "^\*\*\* BLURB HERE \*\*\*$" actual && |
| 1867 | ! grep "^config subject$" actual && |
| 1868 | grep "^body$" actual |
| 1869 | ' |
| 1870 | |
Nguyễn Thái Ngọc Duy | e216cc4 | 2013-01-03 21:03:09 +0700 | [diff] [blame] | 1871 | test_expect_success 'cover letter using branch description (1)' ' |
| 1872 | git checkout rebuild-1 && |
| 1873 | test_config branch.rebuild-1.description hello && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1874 | git format-patch --stdout --cover-letter main >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1875 | grep hello actual |
Nguyễn Thái Ngọc Duy | e216cc4 | 2013-01-03 21:03:09 +0700 | [diff] [blame] | 1876 | ' |
| 1877 | |
| 1878 | test_expect_success 'cover letter using branch description (2)' ' |
| 1879 | git checkout rebuild-1 && |
| 1880 | test_config branch.rebuild-1.description hello && |
| 1881 | git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1882 | grep hello actual |
Nguyễn Thái Ngọc Duy | e216cc4 | 2013-01-03 21:03:09 +0700 | [diff] [blame] | 1883 | ' |
| 1884 | |
| 1885 | test_expect_success 'cover letter using branch description (3)' ' |
| 1886 | git checkout rebuild-1 && |
| 1887 | test_config branch.rebuild-1.description hello && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1888 | git format-patch --stdout --cover-letter ^main rebuild-1 >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1889 | grep hello actual |
Nguyễn Thái Ngọc Duy | e216cc4 | 2013-01-03 21:03:09 +0700 | [diff] [blame] | 1890 | ' |
| 1891 | |
Nguyễn Thái Ngọc Duy | 20b630a | 2013-01-03 21:03:10 +0700 | [diff] [blame] | 1892 | test_expect_success 'cover letter using branch description (4)' ' |
| 1893 | git checkout rebuild-1 && |
| 1894 | test_config branch.rebuild-1.description hello && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1895 | git format-patch --stdout --cover-letter main.. >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1896 | grep hello actual |
Nguyễn Thái Ngọc Duy | 20b630a | 2013-01-03 21:03:10 +0700 | [diff] [blame] | 1897 | ' |
| 1898 | |
| 1899 | test_expect_success 'cover letter using branch description (5)' ' |
| 1900 | git checkout rebuild-1 && |
| 1901 | test_config branch.rebuild-1.description hello && |
| 1902 | git format-patch --stdout --cover-letter -2 HEAD >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1903 | grep hello actual |
Nguyễn Thái Ngọc Duy | 20b630a | 2013-01-03 21:03:10 +0700 | [diff] [blame] | 1904 | ' |
| 1905 | |
Nguyễn Thái Ngọc Duy | 5ee29ae | 2013-01-03 23:16:37 +0700 | [diff] [blame] | 1906 | test_expect_success 'cover letter using branch description (6)' ' |
| 1907 | git checkout rebuild-1 && |
| 1908 | test_config branch.rebuild-1.description hello && |
| 1909 | git format-patch --stdout --cover-letter -2 >actual && |
Denton Liu | f2e2fa8 | 2019-08-27 00:05:05 -0400 | [diff] [blame] | 1910 | grep hello actual |
Nguyễn Thái Ngọc Duy | 5ee29ae | 2013-01-03 23:16:37 +0700 | [diff] [blame] | 1911 | ' |
| 1912 | |
Felipe Contreras | 80d35ca | 2013-04-07 12:46:20 -0500 | [diff] [blame] | 1913 | test_expect_success 'cover letter with nothing' ' |
| 1914 | git format-patch --stdout --cover-letter >actual && |
| 1915 | test_line_count = 0 actual |
| 1916 | ' |
| 1917 | |
Felipe Contreras | 2a4c260 | 2013-04-07 12:46:23 -0500 | [diff] [blame] | 1918 | test_expect_success 'cover letter auto' ' |
| 1919 | mkdir -p tmp && |
| 1920 | test_when_finished "rm -rf tmp; |
| 1921 | git config --unset format.coverletter" && |
| 1922 | |
| 1923 | git config format.coverletter auto && |
| 1924 | git format-patch -o tmp -1 >list && |
| 1925 | test_line_count = 1 list && |
| 1926 | git format-patch -o tmp -2 >list && |
| 1927 | test_line_count = 3 list |
| 1928 | ' |
| 1929 | |
| 1930 | test_expect_success 'cover letter auto user override' ' |
| 1931 | mkdir -p tmp && |
| 1932 | test_when_finished "rm -rf tmp; |
| 1933 | git config --unset format.coverletter" && |
| 1934 | |
| 1935 | git config format.coverletter auto && |
| 1936 | git format-patch -o tmp --cover-letter -1 >list && |
| 1937 | test_line_count = 2 list && |
| 1938 | git format-patch -o tmp --cover-letter -2 >list && |
| 1939 | test_line_count = 3 list && |
| 1940 | git format-patch -o tmp --no-cover-letter -1 >list && |
| 1941 | test_line_count = 1 list && |
| 1942 | git format-patch -o tmp --no-cover-letter -2 >list && |
| 1943 | test_line_count = 2 list |
| 1944 | ' |
| 1945 | |
brian m. carlson | 3a30aa1 | 2015-12-15 01:52:04 +0000 | [diff] [blame] | 1946 | test_expect_success 'format-patch --zero-commit' ' |
| 1947 | git format-patch --zero-commit --stdout v2..v1 >patch2 && |
| 1948 | grep "^From " patch2 | sort | uniq >actual && |
brian m. carlson | 8125a58 | 2018-05-13 02:24:13 +0000 | [diff] [blame] | 1949 | echo "From $ZERO_OID Mon Sep 17 00:00:00 2001" >expect && |
brian m. carlson | 3a30aa1 | 2015-12-15 01:52:04 +0000 | [diff] [blame] | 1950 | test_cmp expect actual |
| 1951 | ' |
| 1952 | |
brian m. carlson | 06dfc9e | 2015-12-15 01:52:05 +0000 | [diff] [blame] | 1953 | test_expect_success 'From line has expected format' ' |
| 1954 | git format-patch --stdout v2..v1 >patch2 && |
| 1955 | grep "^From " patch2 >from && |
brian m. carlson | 2ece6ad | 2018-05-13 02:24:15 +0000 | [diff] [blame] | 1956 | grep "^From $OID_REGEX Mon Sep 17 00:00:00 2001$" patch2 >filtered && |
brian m. carlson | 06dfc9e | 2015-12-15 01:52:05 +0000 | [diff] [blame] | 1957 | test_cmp from filtered |
| 1958 | ' |
| 1959 | |
Bert Wesarg | edefc31 | 2019-10-11 10:36:41 +0200 | [diff] [blame] | 1960 | test_expect_success 'format-patch -o with no leading directories' ' |
| 1961 | rm -fr patches && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1962 | git format-patch -o patches main..side && |
| 1963 | count=$(git rev-list --count main..side) && |
Bert Wesarg | edefc31 | 2019-10-11 10:36:41 +0200 | [diff] [blame] | 1964 | ls patches >list && |
| 1965 | test_line_count = $count list |
| 1966 | ' |
| 1967 | |
| 1968 | test_expect_success 'format-patch -o with leading existing directories' ' |
Bert Wesarg | 19c29e5 | 2019-10-21 15:23:42 +0200 | [diff] [blame] | 1969 | rm -rf existing-dir && |
| 1970 | mkdir existing-dir && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1971 | git format-patch -o existing-dir/patches main..side && |
| 1972 | count=$(git rev-list --count main..side) && |
Bert Wesarg | 19c29e5 | 2019-10-21 15:23:42 +0200 | [diff] [blame] | 1973 | ls existing-dir/patches >list && |
Bert Wesarg | edefc31 | 2019-10-11 10:36:41 +0200 | [diff] [blame] | 1974 | test_line_count = $count list |
| 1975 | ' |
| 1976 | |
| 1977 | test_expect_success 'format-patch -o with leading non-existing directories' ' |
Bert Wesarg | 19c29e5 | 2019-10-21 15:23:42 +0200 | [diff] [blame] | 1978 | rm -rf non-existing-dir && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1979 | git format-patch -o non-existing-dir/patches main..side && |
| 1980 | count=$(git rev-list --count main..side) && |
Bert Wesarg | 19c29e5 | 2019-10-21 15:23:42 +0200 | [diff] [blame] | 1981 | test_path_is_dir non-existing-dir && |
| 1982 | ls non-existing-dir/patches >list && |
Bert Wesarg | edefc31 | 2019-10-11 10:36:41 +0200 | [diff] [blame] | 1983 | test_line_count = $count list |
| 1984 | ' |
| 1985 | |
Alexander Kuleshov | bc6bf2d | 2016-01-13 06:20:11 -0700 | [diff] [blame] | 1986 | test_expect_success 'format-patch format.outputDirectory option' ' |
| 1987 | test_config format.outputDirectory patches && |
| 1988 | rm -fr patches && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1989 | git format-patch main..side && |
| 1990 | count=$(git rev-list --count main..side) && |
Denton Liu | 756fb0d | 2019-10-08 02:14:11 -0700 | [diff] [blame] | 1991 | ls patches >list && |
| 1992 | test_line_count = $count list |
Alexander Kuleshov | bc6bf2d | 2016-01-13 06:20:11 -0700 | [diff] [blame] | 1993 | ' |
| 1994 | |
| 1995 | test_expect_success 'format-patch -o overrides format.outputDirectory' ' |
| 1996 | test_config format.outputDirectory patches && |
| 1997 | rm -fr patches patchset && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 1998 | git format-patch main..side -o patchset && |
Alexander Kuleshov | bc6bf2d | 2016-01-13 06:20:11 -0700 | [diff] [blame] | 1999 | test_path_is_missing patches && |
| 2000 | test_path_is_dir patchset |
| 2001 | ' |
| 2002 | |
Jeff King | 4c6f781 | 2020-11-04 14:28:31 -0500 | [diff] [blame] | 2003 | test_expect_success 'format-patch forbids multiple outputs' ' |
Jeff King | dc1672d | 2020-11-04 14:28:36 -0500 | [diff] [blame] | 2004 | rm -fr outfile outdir && |
Jeff King | 4c6f781 | 2020-11-04 14:28:31 -0500 | [diff] [blame] | 2005 | test_must_fail \ |
Jeff King | dc1672d | 2020-11-04 14:28:36 -0500 | [diff] [blame] | 2006 | git format-patch --stdout --output-directory=outdir && |
| 2007 | test_must_fail \ |
| 2008 | git format-patch --stdout --output=outfile && |
| 2009 | test_must_fail \ |
| 2010 | git format-patch --output=outfile --output-directory=outdir |
Jeff King | 4c6f781 | 2020-11-04 14:28:31 -0500 | [diff] [blame] | 2011 | ' |
| 2012 | |
| 2013 | test_expect_success 'configured outdir does not conflict with output options' ' |
Jeff King | dc1672d | 2020-11-04 14:28:36 -0500 | [diff] [blame] | 2014 | rm -fr outfile outdir && |
Jeff King | 4c6f781 | 2020-11-04 14:28:31 -0500 | [diff] [blame] | 2015 | test_config format.outputDirectory outdir && |
| 2016 | git format-patch --stdout && |
Jeff King | dc1672d | 2020-11-04 14:28:36 -0500 | [diff] [blame] | 2017 | test_path_is_missing outdir && |
| 2018 | git format-patch --output=outfile && |
Jeff King | 4c6f781 | 2020-11-04 14:28:31 -0500 | [diff] [blame] | 2019 | test_path_is_missing outdir |
| 2020 | ' |
| 2021 | |
Jeff King | dc1672d | 2020-11-04 14:28:36 -0500 | [diff] [blame] | 2022 | test_expect_success 'format-patch --output' ' |
| 2023 | rm -fr outfile && |
| 2024 | git format-patch -3 --stdout HEAD >expect && |
| 2025 | git format-patch -3 --output=outfile HEAD && |
| 2026 | test_cmp expect outfile |
| 2027 | ' |
| 2028 | |
| 2029 | test_expect_success 'format-patch --cover-letter --output' ' |
| 2030 | rm -fr outfile && |
| 2031 | git format-patch --cover-letter -3 --stdout HEAD >expect && |
| 2032 | git format-patch --cover-letter -3 --output=outfile HEAD && |
| 2033 | test_cmp expect outfile |
| 2034 | ' |
| 2035 | |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2036 | test_expect_success 'format-patch --base' ' |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 2037 | git checkout patchid && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2038 | |
| 2039 | git format-patch --stdout --base=HEAD~3 -1 >patch && |
| 2040 | tail -n 7 patch >actual1 && |
| 2041 | |
| 2042 | git format-patch --stdout --base=HEAD~3 HEAD~.. >patch && |
| 2043 | tail -n 7 patch >actual2 && |
| 2044 | |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2045 | echo >expect && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2046 | git rev-parse HEAD~3 >commit-id-base && |
| 2047 | echo "base-commit: $(cat commit-id-base)" >>expect && |
| 2048 | |
| 2049 | git show --patch HEAD~2 >patch && |
| 2050 | git patch-id --stable <patch >patch.id.raw && |
| 2051 | awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect && |
| 2052 | |
| 2053 | git show --patch HEAD~1 >patch && |
| 2054 | git patch-id --stable <patch >patch.id.raw && |
| 2055 | awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>expect && |
| 2056 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 2057 | signature >>expect && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2058 | test_cmp expect actual1 && |
| 2059 | test_cmp expect actual2 && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2060 | |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 2061 | echo >fail && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2062 | echo "base-commit: $(cat commit-id-base)" >>fail && |
| 2063 | |
| 2064 | git show --patch HEAD~2 >patch && |
| 2065 | git patch-id --unstable <patch >patch.id.raw && |
| 2066 | awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail && |
| 2067 | |
| 2068 | git show --patch HEAD~1 >patch && |
| 2069 | git patch-id --unstable <patch >patch.id.raw && |
| 2070 | awk "{print \"prerequisite-patch-id:\", \$1}" <patch.id.raw >>fail && |
| 2071 | |
Denton Liu | 92014b6 | 2019-08-27 00:05:00 -0400 | [diff] [blame] | 2072 | signature >>fail && |
Stephen Boyd | 6f93d26 | 2019-04-26 16:51:56 -0700 | [diff] [blame] | 2073 | ! test_cmp fail actual1 && |
| 2074 | ! test_cmp fail actual2 |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2075 | ' |
| 2076 | |
| 2077 | test_expect_success 'format-patch --base errors out when base commit is in revision list' ' |
| 2078 | test_must_fail git format-patch --base=HEAD -2 && |
| 2079 | test_must_fail git format-patch --base=HEAD~1 -2 && |
| 2080 | git format-patch --stdout --base=HEAD~2 -2 >patch && |
| 2081 | grep "^base-commit:" patch >actual && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2082 | git rev-parse HEAD~2 >commit-id-base && |
| 2083 | echo "base-commit: $(cat commit-id-base)" >expect && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2084 | test_cmp expect actual |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2085 | ' |
| 2086 | |
| 2087 | test_expect_success 'format-patch --base errors out when base commit is not ancestor of revision list' ' |
| 2088 | # For history as below: |
| 2089 | # |
| 2090 | # ---Q---P---Z---Y---*---X |
| 2091 | # \ / |
| 2092 | # ------------W |
| 2093 | # |
| 2094 | # If "format-patch Z..X" is given, P and Z can not be specified as the base commit |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2095 | git checkout -b topic1 main && |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2096 | git rev-parse HEAD >commit-id-base && |
| 2097 | test_commit P && |
| 2098 | git rev-parse HEAD >commit-id-P && |
| 2099 | test_commit Z && |
| 2100 | git rev-parse HEAD >commit-id-Z && |
| 2101 | test_commit Y && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2102 | git checkout -b topic2 main && |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2103 | test_commit W && |
| 2104 | git merge topic1 && |
| 2105 | test_commit X && |
| 2106 | test_must_fail git format-patch --base=$(cat commit-id-P) -3 && |
| 2107 | test_must_fail git format-patch --base=$(cat commit-id-Z) -3 && |
| 2108 | git format-patch --stdout --base=$(cat commit-id-base) -3 >patch && |
| 2109 | grep "^base-commit:" patch >actual && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2110 | echo "base-commit: $(cat commit-id-base)" >expect && |
| 2111 | test_cmp expect actual |
Xiaolong Ye | fa2ab86 | 2016-04-26 15:51:22 +0800 | [diff] [blame] | 2112 | ' |
| 2113 | |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2114 | test_expect_success 'format-patch --base=auto' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2115 | git checkout -b upstream main && |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2116 | git checkout -b local upstream && |
| 2117 | git branch --set-upstream-to=upstream && |
| 2118 | test_commit N1 && |
| 2119 | test_commit N2 && |
| 2120 | git format-patch --stdout --base=auto -2 >patch && |
| 2121 | grep "^base-commit:" patch >actual && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2122 | git rev-parse upstream >commit-id-base && |
| 2123 | echo "base-commit: $(cat commit-id-base)" >expect && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2124 | test_cmp expect actual |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2125 | ' |
| 2126 | |
| 2127 | test_expect_success 'format-patch errors out when history involves criss-cross' ' |
| 2128 | # setup criss-cross history |
| 2129 | # |
| 2130 | # B---M1---D |
| 2131 | # / \ / |
| 2132 | # A X |
| 2133 | # \ / \ |
| 2134 | # C---M2---E |
| 2135 | # |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2136 | git checkout main && |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2137 | test_commit A && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2138 | git checkout -b xb main && |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2139 | test_commit B && |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2140 | git checkout -b xc main && |
Xiaolong Ye | 3de6651 | 2016-04-26 15:51:23 +0800 | [diff] [blame] | 2141 | test_commit C && |
| 2142 | git checkout -b xbc xb -- && |
| 2143 | git merge xc && |
| 2144 | git checkout -b xcb xc -- && |
| 2145 | git branch --set-upstream-to=xbc && |
| 2146 | git merge xb && |
| 2147 | git checkout xbc && |
| 2148 | test_commit D && |
| 2149 | git checkout xcb && |
| 2150 | test_commit E && |
| 2151 | test_must_fail git format-patch --base=auto -1 |
| 2152 | ' |
| 2153 | |
Jacob Keller | 7efba5f | 2020-10-01 14:46:53 -0700 | [diff] [blame] | 2154 | test_expect_success 'format-patch format.useAutoBase whenAble history involves criss-cross' ' |
| 2155 | test_config format.useAutoBase whenAble && |
| 2156 | git format-patch -1 >patch && |
| 2157 | ! grep "^base-commit:" patch |
| 2158 | ' |
| 2159 | |
Denton Liu | 700e006 | 2019-12-04 13:25:00 -0800 | [diff] [blame] | 2160 | test_expect_success 'format-patch format.useAutoBase option' ' |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2161 | git checkout local && |
Denton Liu | 700e006 | 2019-12-04 13:25:00 -0800 | [diff] [blame] | 2162 | test_config format.useAutoBase true && |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2163 | git format-patch --stdout -1 >patch && |
| 2164 | grep "^base-commit:" patch >actual && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2165 | git rev-parse upstream >commit-id-base && |
| 2166 | echo "base-commit: $(cat commit-id-base)" >expect && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2167 | test_cmp expect actual |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2168 | ' |
| 2169 | |
Jacob Keller | 7efba5f | 2020-10-01 14:46:53 -0700 | [diff] [blame] | 2170 | test_expect_success 'format-patch format.useAutoBase option with whenAble' ' |
| 2171 | git checkout local && |
| 2172 | test_config format.useAutoBase whenAble && |
| 2173 | git format-patch --stdout -1 >patch && |
| 2174 | grep "^base-commit:" patch >actual && |
| 2175 | git rev-parse upstream >commit-id-base && |
| 2176 | echo "base-commit: $(cat commit-id-base)" >expect && |
| 2177 | test_cmp expect actual |
| 2178 | ' |
| 2179 | |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2180 | test_expect_success 'format-patch --base overrides format.useAutoBase' ' |
Denton Liu | 700e006 | 2019-12-04 13:25:00 -0800 | [diff] [blame] | 2181 | test_config format.useAutoBase true && |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2182 | git format-patch --stdout --base=HEAD~1 -1 >patch && |
| 2183 | grep "^base-commit:" patch >actual && |
Denton Liu | 854b5cb | 2019-08-27 00:05:15 -0400 | [diff] [blame] | 2184 | git rev-parse HEAD~1 >commit-id-base && |
| 2185 | echo "base-commit: $(cat commit-id-base)" >expect && |
Denton Liu | b562a54 | 2019-08-27 00:04:52 -0400 | [diff] [blame] | 2186 | test_cmp expect actual |
Xiaolong Ye | bb52995 | 2016-04-26 15:51:24 +0800 | [diff] [blame] | 2187 | ' |
| 2188 | |
Denton Liu | 945dc55 | 2019-12-04 13:25:06 -0800 | [diff] [blame] | 2189 | test_expect_success 'format-patch --no-base overrides format.useAutoBase' ' |
| 2190 | test_config format.useAutoBase true && |
| 2191 | git format-patch --stdout --no-base -1 >patch && |
| 2192 | ! grep "^base-commit:" patch |
| 2193 | ' |
| 2194 | |
Jacob Keller | 7efba5f | 2020-10-01 14:46:53 -0700 | [diff] [blame] | 2195 | test_expect_success 'format-patch --no-base overrides format.useAutoBase whenAble' ' |
| 2196 | test_config format.useAutoBase whenAble && |
| 2197 | git format-patch --stdout --no-base -1 >patch && |
| 2198 | ! grep "^base-commit:" patch |
| 2199 | ' |
| 2200 | |
Josh Triplett | 480871e | 2016-09-07 18:12:01 -0700 | [diff] [blame] | 2201 | test_expect_success 'format-patch --base with --attach' ' |
| 2202 | git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch && |
| 2203 | sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \ |
| 2204 | patch >actual && |
| 2205 | test_write_lines 1 2 >expect && |
| 2206 | test_cmp expect actual |
| 2207 | ' |
brian m. carlson | 50cd54e | 2018-05-02 02:20:52 +0000 | [diff] [blame] | 2208 | test_expect_success 'format-patch --attach cover-letter only is non-multipart' ' |
| 2209 | test_when_finished "rm -fr patches" && |
| 2210 | git format-patch -o patches --cover-letter --attach=mimemime --base=HEAD~ -1 && |
| 2211 | ! egrep "^--+mimemime" patches/0000*.patch && |
| 2212 | egrep "^--+mimemime$" patches/0001*.patch >output && |
| 2213 | test_line_count = 2 output && |
| 2214 | egrep "^--+mimemime--$" patches/0001*.patch >output && |
| 2215 | test_line_count = 1 output |
| 2216 | ' |
Josh Triplett | 480871e | 2016-09-07 18:12:01 -0700 | [diff] [blame] | 2217 | |
Eric Wong | 9f23e04 | 2016-06-05 04:46:39 +0000 | [diff] [blame] | 2218 | test_expect_success 'format-patch --pretty=mboxrd' ' |
| 2219 | sp=" " && |
| 2220 | cat >msg <<-INPUT_END && |
| 2221 | mboxrd should escape the body |
| 2222 | |
| 2223 | From could trip up a loose mbox parser |
| 2224 | >From extra escape for reversibility |
| 2225 | >>From extra escape for reversibility 2 |
| 2226 | from lower case not escaped |
| 2227 | Fromm bad speling not escaped |
| 2228 | From with leading space not escaped |
| 2229 | |
| 2230 | F |
| 2231 | From |
| 2232 | From$sp |
| 2233 | From $sp |
| 2234 | From $sp |
| 2235 | INPUT_END |
| 2236 | |
| 2237 | cat >expect <<-INPUT_END && |
| 2238 | >From could trip up a loose mbox parser |
| 2239 | >>From extra escape for reversibility |
| 2240 | >>>From extra escape for reversibility 2 |
| 2241 | from lower case not escaped |
| 2242 | Fromm bad speling not escaped |
| 2243 | From with leading space not escaped |
| 2244 | |
| 2245 | F |
| 2246 | From |
| 2247 | From |
| 2248 | From |
| 2249 | From |
| 2250 | INPUT_END |
| 2251 | |
| 2252 | C=$(git commit-tree HEAD^^{tree} -p HEAD <msg) && |
| 2253 | git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >patch && |
| 2254 | git grep -h --no-index -A11 \ |
| 2255 | "^>From could trip up a loose mbox parser" patch >actual && |
| 2256 | test_cmp expect actual |
| 2257 | ' |
| 2258 | |
Eric Sunshine | 126facf | 2018-07-22 05:57:05 -0400 | [diff] [blame] | 2259 | test_expect_success 'interdiff: setup' ' |
Johannes Schindelin | 8f37854 | 2020-11-18 23:44:27 +0000 | [diff] [blame] | 2260 | git checkout -b boop main && |
Eric Sunshine | 126facf | 2018-07-22 05:57:05 -0400 | [diff] [blame] | 2261 | test_commit fnorp blorp && |
| 2262 | test_commit fleep blorp |
| 2263 | ' |
| 2264 | |
| 2265 | test_expect_success 'interdiff: cover-letter' ' |
| 2266 | sed "y/q/ /" >expect <<-\EOF && |
| 2267 | +fleep |
| 2268 | --q |
| 2269 | EOF |
| 2270 | git format-patch --cover-letter --interdiff=boop~2 -1 boop && |
| 2271 | test_i18ngrep "^Interdiff:$" 0000-cover-letter.patch && |
Eric Sunshine | ee6cbf7 | 2018-07-22 05:57:09 -0400 | [diff] [blame] | 2272 | test_i18ngrep ! "^Interdiff:$" 0001-fleep.patch && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 2273 | sed "1,/^@@ /d; /^-- $/q" 0000-cover-letter.patch >actual && |
Eric Sunshine | 126facf | 2018-07-22 05:57:05 -0400 | [diff] [blame] | 2274 | test_cmp expect actual |
| 2275 | ' |
| 2276 | |
Eric Sunshine | 5ac290f | 2018-07-22 05:57:06 -0400 | [diff] [blame] | 2277 | test_expect_success 'interdiff: reroll-count' ' |
| 2278 | git format-patch --cover-letter --interdiff=boop~2 -v2 -1 boop && |
| 2279 | test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch |
| 2280 | ' |
| 2281 | |
ZheNing Hu | db91988 | 2021-03-23 11:12:25 +0000 | [diff] [blame] | 2282 | test_expect_success 'interdiff: reroll-count with a non-integer' ' |
| 2283 | git format-patch --cover-letter --interdiff=boop~2 -v2.2 -1 boop && |
| 2284 | test_i18ngrep "^Interdiff:$" v2.2-0000-cover-letter.patch |
| 2285 | ' |
| 2286 | |
| 2287 | test_expect_success 'interdiff: reroll-count with a integer' ' |
| 2288 | git format-patch --cover-letter --interdiff=boop~2 -v2 -1 boop && |
| 2289 | test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch |
| 2290 | ' |
| 2291 | |
Eric Sunshine | ee6cbf7 | 2018-07-22 05:57:09 -0400 | [diff] [blame] | 2292 | test_expect_success 'interdiff: solo-patch' ' |
| 2293 | cat >expect <<-\EOF && |
| 2294 | +fleep |
| 2295 | |
| 2296 | EOF |
| 2297 | git format-patch --interdiff=boop~2 -1 boop && |
| 2298 | test_i18ngrep "^Interdiff:$" 0001-fleep.patch && |
Denton Liu | c6ec6da | 2019-08-27 00:05:07 -0400 | [diff] [blame] | 2299 | sed "1,/^ @@ /d; /^$/q" 0001-fleep.patch >actual && |
Eric Sunshine | ee6cbf7 | 2018-07-22 05:57:09 -0400 | [diff] [blame] | 2300 | test_cmp expect actual |
| 2301 | ' |
| 2302 | |
Junio C Hamano | ece3c67 | 2006-06-26 15:40:09 -0700 | [diff] [blame] | 2303 | test_done |