blob: 06c5fb56157f28359b47c04818e2a51f9098ee36 [file] [log] [blame]
Junio C Hamano30a95f32006-07-03 18:09:54 -07001#!/bin/sh
2#
3# Copyright (c) 2006, Junio C Hamano
4#
5
6test_description='fmt-merge-msg test'
7
Johannes Schindelin1550bb62020-11-18 23:44:36 +00008GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00009export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
Junio C Hamano30a95f32006-07-03 18:09:54 -070011. ./test-lib.sh
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +000012. "$TEST_DIRECTORY/lib-gpg.sh"
Junio C Hamano30a95f32006-07-03 18:09:54 -070013
Junio C Hamano30a95f32006-07-03 18:09:54 -070014test_expect_success setup '
15 echo one >one &&
16 git add one &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070017 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070018 git commit -m "Initial" &&
19
Stephen Boyd419fe5b2010-03-24 00:15:58 -070020 git clone . remote &&
21
Junio C Hamano30a95f32006-07-03 18:09:54 -070022 echo uno >one &&
23 echo dos >two &&
24 git add two &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070025 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070026 git commit -a -m "Second" &&
27
28 git checkout -b left &&
29
Stephen Boyd6183a6a2010-03-24 00:15:59 -070030 echo "c1" >one &&
31 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070032 git commit -a -m "Common #1" &&
33
Stephen Boyd6183a6a2010-03-24 00:15:59 -070034 echo "c2" >one &&
35 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070036 git commit -a -m "Common #2" &&
37
38 git branch right &&
39
Stephen Boyd6183a6a2010-03-24 00:15:59 -070040 echo "l3" >two &&
41 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070042 GIT_COMMITTER_NAME="Another Committer" \
43 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070044
Stephen Boyd6183a6a2010-03-24 00:15:59 -070045 echo "l4" >two &&
46 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070047 GIT_COMMITTER_NAME="Another Committer" \
48 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070049
Stephen Boyd6183a6a2010-03-24 00:15:59 -070050 echo "l5" >two &&
51 test_tick &&
Junio C Hamano418a1432012-03-13 10:00:00 -070052 GIT_COMMITTER_NAME="Another Committer" \
53 GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070054 git tag tag-l5 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070055
56 git checkout right &&
57
Stephen Boyd6183a6a2010-03-24 00:15:59 -070058 echo "r3" >three &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070059 git add three &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070060 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070061 git commit -a -m "Right #3" &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -070062 git tag tag-r3 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070063
Stephen Boyd6183a6a2010-03-24 00:15:59 -070064 echo "r4" >three &&
65 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070066 git commit -a -m "Right #4" &&
67
Stephen Boyd6183a6a2010-03-24 00:15:59 -070068 echo "r5" >three &&
69 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070070 git commit -a -m "Right #5" &&
71
Stephen Boyd6d6f6e62010-03-24 00:16:00 -070072 git checkout -b long &&
Jeff King70b39fb2019-07-19 17:56:23 -040073 test_commit_bulk --start=0 --message=%s --filename=one 30 &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -070074
Jonathan Niederd834c962010-08-17 01:57:40 -050075 git show-branch &&
76
77 apos="'\''"
Junio C Hamano30a95f32006-07-03 18:09:54 -070078'
79
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +000080test_expect_success GPG 'set up a signed tag' '
81 git tag -s -m signed-tag-msg signed-good-tag left
82'
83
Fabian Stelzer9d125462021-10-12 11:22:35 +020084test_expect_success GPGSSH 'created ssh signed commit and tag' '
85 test_config gpg.format ssh &&
86 git checkout -b signed-ssh &&
87 touch file &&
88 git add file &&
89 git commit -m "ssh signed" -S"${GPGSSH_KEY_PRIMARY}" &&
90 git tag -s -u"${GPGSSH_KEY_PRIMARY}" -m signed-ssh-tag-msg signed-good-ssh-tag left &&
91 git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left
92'
93
Jonathan Niederd834c962010-08-17 01:57:40 -050094test_expect_success 'message for merging local branch' '
Junio C Hamano21531922020-07-30 10:06:42 -070095 echo "Merge branch ${apos}left${apos}" >expected &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070096
Johannes Schindelin1550bb62020-11-18 23:44:36 +000097 git checkout main &&
Junio C Hamano30a95f32006-07-03 18:09:54 -070098 git fetch . left &&
99
100 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700101 test_cmp expected actual
Junio C Hamano30a95f32006-07-03 18:09:54 -0700102'
103
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +0000104test_expect_success GPG 'message for merging local tag signed by good key' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000105 git checkout main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +0000106 git fetch . signed-good-tag &&
107 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
108 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
109 grep "^# gpg: Signature made" actual &&
110 grep "^# gpg: Good signature from" actual
111'
112
113test_expect_success GPG 'message for merging local tag signed by unknown key' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000114 git checkout main &&
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +0000115 git fetch . signed-good-tag &&
116 GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
117 grep "^Merge tag ${apos}signed-good-tag${apos}" actual &&
118 grep "^# gpg: Signature made" actual &&
Carlo Marcelo Arenas Belón46022ca2020-05-29 01:20:08 -0700119 grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual
Hans Jerry Illikainenf1e3df32020-03-04 11:48:03 +0000120'
121
Fabian Stelzer9d125462021-10-12 11:22:35 +0200122test_expect_success GPGSSH 'message for merging local tag signed by good ssh key' '
123 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
124 git checkout main &&
125 git fetch . signed-good-ssh-tag &&
126 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
127 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
128 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
129'
130
131test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh key' '
132 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
133 git checkout main &&
134 git fetch . signed-untrusted-ssh-tag &&
135 git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 &&
136 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
137 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
138 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual
139'
Jonathan Niederd834c962010-08-17 01:57:40 -0500140test_expect_success 'message for merging external branch' '
Junio C Hamano21531922020-07-30 10:06:42 -0700141 echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700142
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000143 git checkout main &&
Johannes Sixt41141562009-03-13 23:35:24 +0100144 git fetch "$(pwd)" left &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700145
146 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
Junio C Hamano3af82862008-05-23 22:28:56 -0700147 test_cmp expected actual
Junio C Hamano30a95f32006-07-03 18:09:54 -0700148'
149
Jonathan Niederd834c962010-08-17 01:57:40 -0500150test_expect_success '[merge] summary/log configuration' '
151 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700152 Merge branch ${apos}left${apos}
Junio C Hamano30a95f32006-07-03 18:09:54 -0700153
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700154 # By Another Author (3) and A U Thor (2)
155 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500156 * left:
157 Left #5
158 Left #4
159 Left #3
160 Common #2
161 Common #1
162 EOF
Junio C Hamano30a95f32006-07-03 18:09:54 -0700163
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700164 test_config merge.log true &&
165 test_unconfig merge.summary &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200166
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000167 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700168 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200169 git fetch . left &&
170
Jonathan Niederd834c962010-08-17 01:57:40 -0500171 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200172
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700173 test_unconfig merge.log &&
174 test_config merge.summary true &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700175
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000176 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700177 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700178 git fetch . left &&
179
Jonathan Niederd834c962010-08-17 01:57:40 -0500180 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
181
182 test_cmp expected actual1 &&
183 test_cmp expected actual2
Junio C Hamano30a95f32006-07-03 18:09:54 -0700184'
185
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530186test_expect_success 'setup FETCH_HEAD' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000187 git checkout main &&
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530188 test_tick &&
189 git fetch . left
190'
191
192test_expect_success 'merge.log=3 limits shortlog length' '
193 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700194 Merge branch ${apos}left${apos}
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530195
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700196 # By Another Author (3) and A U Thor (2)
197 # Via Another Committer
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530198 * left: (5 commits)
199 Left #5
200 Left #4
201 Left #3
202 ...
203 EOF
204
205 git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
206 test_cmp expected actual
207'
208
209test_expect_success 'merge.log=5 shows all 5 commits' '
210 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700211 Merge branch ${apos}left${apos}
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530212
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700213 # By Another Author (3) and A U Thor (2)
214 # Via Another Committer
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530215 * left:
216 Left #5
217 Left #4
218 Left #3
219 Common #2
220 Common #1
221 EOF
222
223 git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
224 test_cmp expected actual
225'
226
Ralf Thielow9927ebe2013-04-07 17:25:43 +0200227test_expect_success '--log=5 with custom comment character' '
228 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700229 Merge branch ${apos}left${apos}
Ralf Thielow9927ebe2013-04-07 17:25:43 +0200230
Johannes Sixt16a794d2013-04-18 08:42:25 +0200231 x By Another Author (3) and A U Thor (2)
232 x Via Another Committer
Ralf Thielow9927ebe2013-04-07 17:25:43 +0200233 * left:
234 Left #5
235 Left #4
236 Left #3
237 Common #2
238 Common #1
239 EOF
240
Johannes Sixt16a794d2013-04-18 08:42:25 +0200241 git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
Ralf Thielow9927ebe2013-04-07 17:25:43 +0200242 test_cmp expected actual
243'
244
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530245test_expect_success 'merge.log=0 disables shortlog' '
Junio C Hamano21531922020-07-30 10:06:42 -0700246 echo "Merge branch ${apos}left${apos}" >expected &&
Ramkumar Ramachandrab928cbf2010-09-08 23:29:56 +0530247 git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
248 test_cmp expected actual
249'
250
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530251test_expect_success '--log=3 limits shortlog length' '
252 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700253 Merge branch ${apos}left${apos}
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530254
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700255 # By Another Author (3) and A U Thor (2)
256 # Via Another Committer
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530257 * left: (5 commits)
258 Left #5
259 Left #4
260 Left #3
261 ...
262 EOF
263
264 git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
265 test_cmp expected actual
266'
267
268test_expect_success '--log=5 shows all 5 commits' '
269 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700270 Merge branch ${apos}left${apos}
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530271
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700272 # By Another Author (3) and A U Thor (2)
273 # Via Another Committer
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530274 * left:
275 Left #5
276 Left #4
277 Left #3
278 Common #2
279 Common #1
280 EOF
281
282 git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
283 test_cmp expected actual
284'
285
286test_expect_success '--no-log disables shortlog' '
Junio C Hamano21531922020-07-30 10:06:42 -0700287 echo "Merge branch ${apos}left${apos}" >expected &&
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530288 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
289 test_cmp expected actual
290'
291
292test_expect_success '--log=0 disables shortlog' '
Junio C Hamano21531922020-07-30 10:06:42 -0700293 echo "Merge branch ${apos}left${apos}" >expected &&
Ramkumar Ramachandrabd2549c2010-09-08 23:29:57 +0530294 git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
295 test_cmp expected actual
296'
297
Jonathan Nieder21024402010-08-17 18:00:34 -0500298test_expect_success 'fmt-merge-msg -m' '
299 echo "Sync with left" >expected &&
300 cat >expected.log <<-EOF &&
301 Sync with left
302
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700303 # By Another Author (3) and A U Thor (2)
304 # Via Another Committer
Jonathan Nieder21024402010-08-17 18:00:34 -0500305 * ${apos}left${apos} of $(pwd):
306 Left #5
307 Left #4
308 Left #3
309 Common #2
310 Common #1
311 EOF
312
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700313 test_unconfig merge.log &&
314 test_unconfig merge.summary &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000315 git checkout main &&
Jonathan Nieder21024402010-08-17 18:00:34 -0500316 git fetch "$(pwd)" left &&
317 git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
318 git fmt-merge-msg --log -m "Sync with left" \
319 <.git/FETCH_HEAD >actual.log &&
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700320 test_config merge.log true &&
Jonathan Nieder21024402010-08-17 18:00:34 -0500321 git fmt-merge-msg -m "Sync with left" \
322 <.git/FETCH_HEAD >actual.log-config &&
323 git fmt-merge-msg --no-log -m "Sync with left" \
324 <.git/FETCH_HEAD >actual.nolog &&
325
326 test_cmp expected actual &&
327 test_cmp expected.log actual.log &&
328 test_cmp expected.log actual.log-config &&
329 test_cmp expected actual.nolog
330'
331
Jonathan Niederd834c962010-08-17 01:57:40 -0500332test_expect_success 'setup: expected shortlog for two branches' '
333 cat >expected <<-EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700334 Merge branches ${apos}left${apos} and ${apos}right${apos}
Junio C Hamano30a95f32006-07-03 18:09:54 -0700335
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700336 # By Another Author (3) and A U Thor (2)
337 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500338 * left:
339 Left #5
340 Left #4
341 Left #3
342 Common #2
343 Common #1
Junio C Hamano30a95f32006-07-03 18:09:54 -0700344
Jonathan Niederd834c962010-08-17 01:57:40 -0500345 * right:
346 Right #5
347 Right #4
348 Right #3
349 Common #2
350 Common #1
351 EOF
352'
Junio C Hamano30a95f32006-07-03 18:09:54 -0700353
Jonathan Niederd834c962010-08-17 01:57:40 -0500354test_expect_success 'shortlog for two branches' '
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700355 test_config merge.log true &&
356 test_unconfig merge.summary &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000357 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700358 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200359 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500360 git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200361
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700362 test_unconfig merge.log &&
363 test_config merge.summary true &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000364 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700365 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700366 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500367 git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700368
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700369 test_config merge.log yes &&
370 test_unconfig merge.summary &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000371 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700372 test_tick &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200373 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500374 git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
SZEDER Gábor6cd9cfe2008-04-06 03:23:45 +0200375
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700376 test_unconfig merge.log &&
377 test_config merge.summary yes &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000378 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700379 test_tick &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700380 git fetch . left right &&
Jonathan Niederd834c962010-08-17 01:57:40 -0500381 git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
Junio C Hamano30a95f32006-07-03 18:09:54 -0700382
Jonathan Niederd834c962010-08-17 01:57:40 -0500383 test_cmp expected actual1 &&
384 test_cmp expected actual2 &&
385 test_cmp expected actual3 &&
386 test_cmp expected actual4
Junio C Hamano30a95f32006-07-03 18:09:54 -0700387'
388
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700389test_expect_success 'merge-msg -F' '
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700390 test_unconfig merge.log &&
391 test_config merge.summary yes &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000392 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700393 test_tick &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700394 git fetch . left right &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700395 git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
396 test_cmp expected actual
397'
398
399test_expect_success 'merge-msg -F in subdirectory' '
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700400 test_unconfig merge.log &&
401 test_config merge.summary yes &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000402 git checkout main &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700403 test_tick &&
Stephen Boyd4c8d4c12009-05-23 11:53:11 -0700404 git fetch . left right &&
405 mkdir sub &&
406 cp .git/FETCH_HEAD sub/FETCH_HEAD &&
407 (
408 cd sub &&
409 git fmt-merge-msg -F FETCH_HEAD >../actual
410 ) &&
411 test_cmp expected actual
412'
413
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700414test_expect_success 'merge-msg with nothing to merge' '
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700415 test_unconfig merge.log &&
416 test_config merge.summary yes &&
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700417
418 (
419 cd remote &&
420 git checkout -b unrelated &&
Stephen Boyd6183a6a2010-03-24 00:15:59 -0700421 test_tick &&
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700422 git fetch origin &&
423 git fmt-merge-msg <.git/FETCH_HEAD >../actual
424 ) &&
425
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200426 test_must_be_empty actual
Stephen Boyd419fe5b2010-03-24 00:15:58 -0700427'
428
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700429test_expect_success 'merge-msg tag' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500430 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700431 Merge tag ${apos}tag-r3${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700432
Jonathan Niederd834c962010-08-17 01:57:40 -0500433 * tag ${apos}tag-r3${apos}:
434 Right #3
435 Common #2
436 Common #1
437 EOF
438
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700439 test_unconfig merge.log &&
440 test_config merge.summary yes &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700441
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000442 git checkout main &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700443 test_tick &&
444 git fetch . tag tag-r3 &&
445
446 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
447 test_cmp expected actual
448'
449
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700450test_expect_success 'merge-msg two tags' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500451 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700452 Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700453
Jonathan Niederd834c962010-08-17 01:57:40 -0500454 * tag ${apos}tag-r3${apos}:
455 Right #3
456 Common #2
457 Common #1
458
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700459 # By Another Author (3) and A U Thor (2)
460 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500461 * tag ${apos}tag-l5${apos}:
462 Left #5
463 Left #4
464 Left #3
465 Common #2
466 Common #1
467 EOF
468
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700469 test_unconfig merge.log &&
470 test_config merge.summary yes &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700471
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000472 git checkout main &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700473 test_tick &&
474 git fetch . tag tag-r3 tag tag-l5 &&
475
476 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
477 test_cmp expected actual
478'
479
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700480test_expect_success 'merge-msg tag and branch' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500481 cat >expected <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700482 Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700483
Jonathan Niederd834c962010-08-17 01:57:40 -0500484 * tag ${apos}tag-r3${apos}:
485 Right #3
486 Common #2
487 Common #1
488
Junio C Hamano9830a9c2012-06-06 14:24:28 -0700489 # By Another Author (3) and A U Thor (2)
490 # Via Another Committer
Jonathan Niederd834c962010-08-17 01:57:40 -0500491 * left:
492 Left #5
493 Left #4
494 Left #3
495 Common #2
496 Common #1
497 EOF
498
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700499 test_unconfig merge.log &&
500 test_config merge.summary yes &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700501
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000502 git checkout main &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700503 test_tick &&
504 git fetch . tag tag-r3 left &&
505
506 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
507 test_cmp expected actual
508'
509
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700510test_expect_success 'merge-msg lots of commits' '
Jonathan Niederd834c962010-08-17 01:57:40 -0500511 {
512 cat <<-EOF &&
Junio C Hamano21531922020-07-30 10:06:42 -0700513 Merge branch ${apos}long${apos}
Jonathan Niederd834c962010-08-17 01:57:40 -0500514
515 * long: (35 commits)
516 EOF
517
518 i=29 &&
519 while test $i -gt 9
520 do
521 echo " $i" &&
522 i=$(($i-1))
523 done &&
524 echo " ..."
525 } >expected &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700526
Junio C Hamano9a94dba2013-04-01 12:33:52 -0700527 test_config merge.summary yes &&
528
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000529 git checkout main &&
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700530 test_tick &&
531 git fetch . long &&
532
Stephen Boyd6d6f6e62010-03-24 00:16:00 -0700533 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
534 test_cmp expected actual
535'
536
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700537test_expect_success 'merge-msg with "merging" an annotated tag' '
538 test_config merge.log true &&
539
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000540 git checkout main^0 &&
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700541 git commit --allow-empty -m "One step ahead" &&
542 git tag -a -m "An annotated one" annote HEAD &&
543
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000544 git checkout main &&
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700545 git fetch . annote &&
546
547 git fmt-merge-msg <.git/FETCH_HEAD >actual &&
548 {
549 cat <<-\EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700550 Merge tag '\''annote'\''
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700551
552 An annotated one
553
554 * tag '\''annote'\'':
555 One step ahead
556 EOF
557 } >expected &&
558 test_cmp expected actual &&
559
560 test_when_finished "git reset --hard" &&
561 annote=$(git rev-parse annote) &&
Junio C Hamanoadcc94a2018-02-14 10:18:55 -0800562 git merge --no-commit --no-ff $annote &&
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700563 {
564 cat <<-EOF
Junio C Hamano21531922020-07-30 10:06:42 -0700565 Merge tag '\''$annote'\''
Junio C Hamanoa38d3d72013-04-01 12:51:50 -0700566
567 An annotated one
568
569 * tag '\''$annote'\'':
570 One step ahead
571 EOF
572 } >expected &&
573 test_cmp expected .git/MERGE_MSG
574'
575
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700576test_expect_success 'merge.suppressDest configuration' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000577 git checkout -B side main &&
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700578 git commit --allow-empty -m "One step ahead" &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000579 git checkout main &&
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700580 git fetch . side &&
581
582 git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 &&
583 head -n1 full.1 >actual &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000584 grep -e "Merge branch .side. into main" actual &&
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700585
586 git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 &&
587 head -n1 full.2 >actual &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000588 grep -e "Merge branch .side. into main$" actual &&
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700589
Johannes Schindelin392ab3d2020-10-23 14:00:01 +0000590 git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700591 head -n1 full.3 >actual &&
592 grep -e "Merge branch .side." actual &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000593 ! grep -e " into main$" actual
Junio C Hamano6e6029a2020-07-29 15:50:01 -0700594'
595
Junio C Hamano30a95f32006-07-03 18:09:54 -0700596test_done