]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3308-notes-merge.sh
t5703: replace "grep -a" usage by perl
[thirdparty/git.git] / t / t3308-notes-merge.sh
CommitLineData
75ef3f4a
JH
1#!/bin/sh
2#
3# Copyright (c) 2010 Johan Herland
4#
5
6test_description='Test merging of notes trees'
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 test_commit 1st &&
12 test_commit 2nd &&
13 test_commit 3rd &&
14 test_commit 4th &&
15 test_commit 5th &&
16 # Create notes on 4 first commits
17 git config core.notesRef refs/notes/x &&
18 git notes add -m "Notes on 1st commit" 1st &&
19 git notes add -m "Notes on 2nd commit" 2nd &&
20 git notes add -m "Notes on 3rd commit" 3rd &&
b3715b75
JK
21 git notes add -m "Notes on 4th commit" 4th &&
22 # Copy notes to remote-notes
7b1a1822 23 git fetch . refs/notes/*:refs/remote-notes/origin/* &&
24
25 test_oid_init &&
26 test_oid_cache <<-EOF
27 hash4a sha1:5e93d24084d32e1cb61f7070505b9d2530cca987
28 hash3a sha1:8366731eeee53787d2bdf8fc1eff7d94757e8da0
29 hash2a sha1:eede89064cd42441590d6afec6c37b321ada3389
30 hash1a sha1:daa55ffad6cb99bf64226532147ffcaf5ce8bdd1
31 hash5b sha1:0f2efbd00262f2fd41dfae33df8765618eeacd99
32 hash4b sha1:dec2502dac3ea161543f71930044deff93fa945c
33 hash3b sha1:4069cdb399fd45463ec6eef8e051a16a03592d91
34 hash2c sha1:d000d30e6ddcfce3a8122c403226a2ce2fd04d9d
35 hash1c sha1:43add6bd0c8c0bc871ac7991e0f5573cfba27804
36 hash4d sha1:1f257a3a90328557c452f0817d6cc50c89d315d4
37 hash3d sha1:05a4927951bcef347f51486575b878b2b60137f2
38
39 hash4a sha256:eef876be1d32ac2e2e42240e0429325cec116e55e88cb2969899fac695aa762f
40 hash3a sha256:cf7cd1bc091d7ba4166a86df864110e42087cd893a5ae96bc50d637e0290939d
41 hash2a sha256:21ddde7ebce2c285213898cb04deca0fd3209610cf7aaf8222e4e2f45262fae2
42 hash1a sha256:f9fe0eda16c6027732ed9d4295689a03abd16f893be69b3dcbf4037ddb191921
43 hash5b sha256:20046f2244577797a9e3d3f790ea9eca4d8a6bafb2a5570bcb0e03aa02ce100b
44 hash4b sha256:f90563d134c61a95bb88afbd45d48ccc9e919c62aa6fbfcd483302b3e4d8dbcb
45 hash3b sha256:988f2aca9f2d87e93e6a73197c2bb99560cc44a2f92d18653968f956f01221e0
46 hash2c sha256:84153b777b4d42827a756c6578dcdb59d8ae5d1360b874fb37c430150c825c26
47 hash1c sha256:9beb2bc4eef72e4c4087be168a20573e34d993d9ab1883055f23e322afa06567
48 hash4d sha256:32de39dc06e679a7abb2d4a55ede7709b3124340a4a90aa305971b1c72ac319d
49 hash3d sha256:fa73b20e41cbb7541c4c81d1535016131dbfbeb05bf6a71f6115e9cad31c7af5
50 EOF
75ef3f4a
JH
51'
52
53commit_sha1=$(git rev-parse 1st^{commit})
54commit_sha2=$(git rev-parse 2nd^{commit})
55commit_sha3=$(git rev-parse 3rd^{commit})
56commit_sha4=$(git rev-parse 4th^{commit})
57commit_sha5=$(git rev-parse 5th^{commit})
58
59verify_notes () {
60 notes_ref="$1"
61 git -c core.notesRef="refs/notes/$notes_ref" notes |
62 sort >"output_notes_$notes_ref" &&
63 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
64 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
65 >"output_log_$notes_ref" &&
66 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
67}
68
69cat <<EOF | sort >expect_notes_x
7b1a1822 70$(test_oid hash4a) $commit_sha4
71$(test_oid hash3a) $commit_sha3
72$(test_oid hash2a) $commit_sha2
73$(test_oid hash1a) $commit_sha1
75ef3f4a
JH
74EOF
75
76cat >expect_log_x <<EOF
77$commit_sha5 5th
78
79$commit_sha4 4th
80Notes on 4th commit
81
82$commit_sha3 3rd
83Notes on 3rd commit
84
85$commit_sha2 2nd
86Notes on 2nd commit
87
88$commit_sha1 1st
89Notes on 1st commit
90
91EOF
92
93test_expect_success 'verify initial notes (x)' '
94 verify_notes x
95'
96
97cp expect_notes_x expect_notes_y
b3715b75 98cp expect_notes_x expect_notes_v
75ef3f4a 99cp expect_log_x expect_log_y
b3715b75 100cp expect_log_x expect_log_v
75ef3f4a
JH
101
102test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y)' '
103 test_must_fail git -c "core.notesRef=refs/notes/y" notes merge z
104'
105
106test_expect_success 'fail to merge into various non-notes refs' '
107 test_must_fail git -c "core.notesRef=refs/notes" notes merge x &&
108 test_must_fail git -c "core.notesRef=refs/notes/" notes merge x &&
f2515d91 109 git update-ref refs/notes/dir/foo HEAD &&
75ef3f4a
JH
110 test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x &&
111 test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x &&
112 test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x &&
113 test_must_fail git -c "core.notesRef=refs/notes/y:" notes merge x &&
114 test_must_fail git -c "core.notesRef=refs/notes/y:foo" notes merge x &&
115 test_must_fail git -c "core.notesRef=refs/notes/foo^{bar" notes merge x
116'
117
b3715b75
JK
118test_expect_success 'merge non-notes ref into empty notes ref (remote-notes/origin/x => v)' '
119 git config core.notesRef refs/notes/v &&
120 git notes merge refs/remote-notes/origin/x &&
121 verify_notes v &&
122 # refs/remote-notes/origin/x and v should point to the same notes commit
123 test "$(git rev-parse refs/remote-notes/origin/x)" = "$(git rev-parse refs/notes/v)"
75ef3f4a
JH
124'
125
126test_expect_success 'merge notes into empty notes ref (x => y)' '
127 git config core.notesRef refs/notes/y &&
128 git notes merge x &&
129 verify_notes y &&
130 # x and y should point to the same notes commit
131 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
132'
133
134test_expect_success 'merge empty notes ref (z => y)' '
135 git notes merge z &&
136 # y should not change (still == x)
137 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
138'
139
140test_expect_success 'change notes on other notes ref (y)' '
141 # Not touching notes to 1st commit
142 git notes remove 2nd &&
143 git notes append -m "More notes on 3rd commit" 3rd &&
144 git notes add -f -m "New notes on 4th commit" 4th &&
145 git notes add -m "Notes on 5th commit" 5th
146'
147
148test_expect_success 'merge previous notes commit (y^ => y) => No-op' '
149 pre_state="$(git rev-parse refs/notes/y)" &&
150 git notes merge y^ &&
151 # y should not move
152 test "$pre_state" = "$(git rev-parse refs/notes/y)"
153'
154
155cat <<EOF | sort >expect_notes_y
7b1a1822 156$(test_oid hash5b) $commit_sha5
157$(test_oid hash4b) $commit_sha4
158$(test_oid hash3b) $commit_sha3
159$(test_oid hash1a) $commit_sha1
75ef3f4a
JH
160EOF
161
162cat >expect_log_y <<EOF
163$commit_sha5 5th
164Notes on 5th commit
165
166$commit_sha4 4th
167New notes on 4th commit
168
169$commit_sha3 3rd
170Notes on 3rd commit
171
172More notes on 3rd commit
173
174$commit_sha2 2nd
175
176$commit_sha1 1st
177Notes on 1st commit
178
179EOF
180
181test_expect_success 'verify changed notes on other notes ref (y)' '
182 verify_notes y
183'
184
185test_expect_success 'verify unchanged notes on original notes ref (x)' '
186 verify_notes x
187'
188
189test_expect_success 'merge original notes (x) into changed notes (y) => No-op' '
190 git notes merge -vvv x &&
191 verify_notes y &&
192 verify_notes x
193'
194
195cp expect_notes_y expect_notes_x
196cp expect_log_y expect_log_x
197
198test_expect_success 'merge changed (y) into original (x) => Fast-forward' '
199 git config core.notesRef refs/notes/x &&
200 git notes merge y &&
201 verify_notes x &&
202 verify_notes y &&
203 # x and y should point to same the notes commit
204 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
205'
206
2085b16a
JH
207test_expect_success 'merge empty notes ref (z => y)' '
208 # Prepare empty (but valid) notes ref (z)
209 git config core.notesRef refs/notes/z &&
210 git notes add -m "foo" &&
211 git notes remove &&
212 git notes >output_notes_z &&
ec21ac8c 213 test_must_be_empty output_notes_z &&
2085b16a
JH
214 # Do the merge (z => y)
215 git config core.notesRef refs/notes/y &&
216 git notes merge z &&
217 verify_notes y &&
218 # y should no longer point to the same notes commit as x
219 test "$(git rev-parse refs/notes/x)" != "$(git rev-parse refs/notes/y)"
220'
221
222cat <<EOF | sort >expect_notes_y
7b1a1822 223$(test_oid hash5b) $commit_sha5
224$(test_oid hash4b) $commit_sha4
225$(test_oid hash3b) $commit_sha3
226$(test_oid hash2c) $commit_sha2
227$(test_oid hash1c) $commit_sha1
2085b16a
JH
228EOF
229
230cat >expect_log_y <<EOF
231$commit_sha5 5th
232Notes on 5th commit
233
234$commit_sha4 4th
235New notes on 4th commit
236
237$commit_sha3 3rd
238Notes on 3rd commit
239
240More notes on 3rd commit
241
242$commit_sha2 2nd
243New notes on 2nd commit
244
245$commit_sha1 1st
246Notes on 1st commit
247
248More notes on 1st commit
249
250EOF
251
252test_expect_success 'change notes on other notes ref (y)' '
253 # Append to 1st commit notes
254 git notes append -m "More notes on 1st commit" 1st &&
255 # Add new notes to 2nd commit
256 git notes add -m "New notes on 2nd commit" 2nd &&
257 verify_notes y
258'
259
260cat <<EOF | sort >expect_notes_x
7b1a1822 261$(test_oid hash5b) $commit_sha5
262$(test_oid hash4d) $commit_sha4
263$(test_oid hash1a) $commit_sha1
2085b16a
JH
264EOF
265
266cat >expect_log_x <<EOF
267$commit_sha5 5th
268Notes on 5th commit
269
270$commit_sha4 4th
271New notes on 4th commit
272
273More notes on 4th commit
274
275$commit_sha3 3rd
276
277$commit_sha2 2nd
278
279$commit_sha1 1st
280Notes on 1st commit
281
282EOF
283
284test_expect_success 'change notes on notes ref (x)' '
285 git config core.notesRef refs/notes/x &&
286 git notes remove 3rd &&
287 git notes append -m "More notes on 4th commit" 4th &&
288 verify_notes x
289'
290
291cat <<EOF | sort >expect_notes_x
7b1a1822 292$(test_oid hash5b) $commit_sha5
293$(test_oid hash4d) $commit_sha4
294$(test_oid hash2c) $commit_sha2
295$(test_oid hash1c) $commit_sha1
2085b16a
JH
296EOF
297
298cat >expect_log_x <<EOF
299$commit_sha5 5th
300Notes on 5th commit
301
302$commit_sha4 4th
303New notes on 4th commit
304
305More notes on 4th commit
306
307$commit_sha3 3rd
308
309$commit_sha2 2nd
310New notes on 2nd commit
311
312$commit_sha1 1st
313Notes on 1st commit
314
315More notes on 1st commit
316
317EOF
318
319test_expect_success 'merge y into x => Non-conflicting 3-way merge' '
320 git notes merge y &&
321 verify_notes x &&
322 verify_notes y
323'
324
325cat <<EOF | sort >expect_notes_w
7b1a1822 326$(test_oid hash3d) $commit_sha3
327$(test_oid hash2c) $commit_sha2
2085b16a
JH
328EOF
329
330cat >expect_log_w <<EOF
331$commit_sha5 5th
332
333$commit_sha4 4th
334
335$commit_sha3 3rd
336New notes on 3rd commit
337
338$commit_sha2 2nd
339New notes on 2nd commit
340
341$commit_sha1 1st
342
343EOF
344
345test_expect_success 'create notes on new, separate notes ref (w)' '
346 git config core.notesRef refs/notes/w &&
347 # Add same note as refs/notes/y on 2nd commit
348 git notes add -m "New notes on 2nd commit" 2nd &&
349 # Add new note on 3rd commit (non-conflicting)
350 git notes add -m "New notes on 3rd commit" 3rd &&
351 # Verify state of notes on new, separate notes ref (w)
352 verify_notes w
353'
354
355cat <<EOF | sort >expect_notes_x
7b1a1822 356$(test_oid hash5b) $commit_sha5
357$(test_oid hash4d) $commit_sha4
358$(test_oid hash3d) $commit_sha3
359$(test_oid hash2c) $commit_sha2
360$(test_oid hash1c) $commit_sha1
2085b16a
JH
361EOF
362
363cat >expect_log_x <<EOF
364$commit_sha5 5th
365Notes on 5th commit
366
367$commit_sha4 4th
368New notes on 4th commit
369
370More notes on 4th commit
371
372$commit_sha3 3rd
373New notes on 3rd commit
374
375$commit_sha2 2nd
376New notes on 2nd commit
377
378$commit_sha1 1st
379Notes on 1st commit
380
381More notes on 1st commit
382
383EOF
384
385test_expect_success 'merge w into x => Non-conflicting history-less merge' '
386 git config core.notesRef refs/notes/x &&
387 git notes merge w &&
388 # Verify new state of notes on other notes ref (x)
389 verify_notes x &&
390 # Also verify that nothing changed on other notes refs (y and w)
391 verify_notes y &&
392 verify_notes w
393'
394
75ef3f4a 395test_done