3 # Copyright (c) 2010 Johan Herland
6 test_description='Test merging of notes trees'
10 test_expect_success setup '
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 &&
21 git notes add -m "Notes on 4th commit" 4th &&
22 # Copy notes to remote-notes
23 git fetch . refs/notes/*:refs/remote-notes/origin/*
26 commit_sha1=$(git rev-parse 1st^{commit})
27 commit_sha2=$(git rev-parse 2nd^{commit})
28 commit_sha3=$(git rev-parse 3rd^{commit})
29 commit_sha4=$(git rev-parse 4th^{commit})
30 commit_sha5=$(git rev-parse 5th^{commit})
34 git -c core.notesRef="refs/notes/$notes_ref" notes |
35 sort >"output_notes_$notes_ref" &&
36 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
37 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
38 >"output_log_$notes_ref" &&
39 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
42 cat <<EOF | sort >expect_notes_x
43 5e93d24084d32e1cb61f7070505b9d2530cca987 $commit_sha4
44 8366731eeee53787d2bdf8fc1eff7d94757e8da0 $commit_sha3
45 eede89064cd42441590d6afec6c37b321ada3389 $commit_sha2
46 daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
49 cat >expect_log_x <<EOF
66 test_expect_success 'verify initial notes (x)' '
70 cp expect_notes_x expect_notes_y
71 cp expect_notes_x expect_notes_v
72 cp expect_log_x expect_log_y
73 cp expect_log_x expect_log_v
75 test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y)' '
76 test_must_fail git -c "core.notesRef=refs/notes/y" notes merge z
79 test_expect_success 'fail to merge into various non-notes refs' '
80 test_must_fail git -c "core.notesRef=refs/notes" notes merge x &&
81 test_must_fail git -c "core.notesRef=refs/notes/" notes merge x &&
82 mkdir -p .git/refs/notes/dir &&
83 test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x &&
84 test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x &&
85 test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x &&
86 test_must_fail git -c "core.notesRef=refs/notes/y:" notes merge x &&
87 test_must_fail git -c "core.notesRef=refs/notes/y:foo" notes merge x &&
88 test_must_fail git -c "core.notesRef=refs/notes/foo^{bar" notes merge x
91 test_expect_success 'merge non-notes ref into empty notes ref (remote-notes/origin/x => v)' '
92 git config core.notesRef refs/notes/v &&
93 git notes merge refs/remote-notes/origin/x &&
95 # refs/remote-notes/origin/x and v should point to the same notes commit
96 test "$(git rev-parse refs/remote-notes/origin/x)" = "$(git rev-parse refs/notes/v)"
99 test_expect_success 'merge notes into empty notes ref (x => y)' '
100 git config core.notesRef refs/notes/y &&
103 # x and y should point to the same notes commit
104 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
107 test_expect_success 'merge empty notes ref (z => y)' '
109 # y should not change (still == x)
110 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
113 test_expect_success 'change notes on other notes ref (y)' '
114 # Not touching notes to 1st commit
115 git notes remove 2nd &&
116 git notes append -m "More notes on 3rd commit" 3rd &&
117 git notes add -f -m "New notes on 4th commit" 4th &&
118 git notes add -m "Notes on 5th commit" 5th
121 test_expect_success 'merge previous notes commit (y^ => y) => No-op' '
122 pre_state="$(git rev-parse refs/notes/y)" &&
123 git notes merge y^ &&
125 test "$pre_state" = "$(git rev-parse refs/notes/y)"
128 cat <<EOF | sort >expect_notes_y
129 0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
130 dec2502dac3ea161543f71930044deff93fa945c $commit_sha4
131 4069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3
132 daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
135 cat >expect_log_y <<EOF
140 New notes on 4th commit
145 More notes on 3rd commit
154 test_expect_success 'verify changed notes on other notes ref (y)' '
158 test_expect_success 'verify unchanged notes on original notes ref (x)' '
162 test_expect_success 'merge original notes (x) into changed notes (y) => No-op' '
163 git notes merge -vvv x &&
168 cp expect_notes_y expect_notes_x
169 cp expect_log_y expect_log_x
171 test_expect_success 'merge changed (y) into original (x) => Fast-forward' '
172 git config core.notesRef refs/notes/x &&
176 # x and y should point to same the notes commit
177 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
180 test_expect_success 'merge empty notes ref (z => y)' '
181 # Prepare empty (but valid) notes ref (z)
182 git config core.notesRef refs/notes/z &&
183 git notes add -m "foo" &&
185 git notes >output_notes_z &&
186 test_cmp /dev/null output_notes_z &&
187 # Do the merge (z => y)
188 git config core.notesRef refs/notes/y &&
191 # y should no longer point to the same notes commit as x
192 test "$(git rev-parse refs/notes/x)" != "$(git rev-parse refs/notes/y)"
195 cat <<EOF | sort >expect_notes_y
196 0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
197 dec2502dac3ea161543f71930044deff93fa945c $commit_sha4
198 4069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3
199 d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
200 43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
203 cat >expect_log_y <<EOF
208 New notes on 4th commit
213 More notes on 3rd commit
216 New notes on 2nd commit
221 More notes on 1st commit
225 test_expect_success 'change notes on other notes ref (y)' '
226 # Append to 1st commit notes
227 git notes append -m "More notes on 1st commit" 1st &&
228 # Add new notes to 2nd commit
229 git notes add -m "New notes on 2nd commit" 2nd &&
233 cat <<EOF | sort >expect_notes_x
234 0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
235 1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
236 daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
239 cat >expect_log_x <<EOF
244 New notes on 4th commit
246 More notes on 4th commit
257 test_expect_success 'change notes on notes ref (x)' '
258 git config core.notesRef refs/notes/x &&
259 git notes remove 3rd &&
260 git notes append -m "More notes on 4th commit" 4th &&
264 cat <<EOF | sort >expect_notes_x
265 0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
266 1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
267 d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
268 43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
271 cat >expect_log_x <<EOF
276 New notes on 4th commit
278 More notes on 4th commit
283 New notes on 2nd commit
288 More notes on 1st commit
292 test_expect_success 'merge y into x => Non-conflicting 3-way merge' '
298 cat <<EOF | sort >expect_notes_w
299 05a4927951bcef347f51486575b878b2b60137f2 $commit_sha3
300 d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
303 cat >expect_log_w <<EOF
309 New notes on 3rd commit
312 New notes on 2nd commit
318 test_expect_success 'create notes on new, separate notes ref (w)' '
319 git config core.notesRef refs/notes/w &&
320 # Add same note as refs/notes/y on 2nd commit
321 git notes add -m "New notes on 2nd commit" 2nd &&
322 # Add new note on 3rd commit (non-conflicting)
323 git notes add -m "New notes on 3rd commit" 3rd &&
324 # Verify state of notes on new, separate notes ref (w)
328 cat <<EOF | sort >expect_notes_x
329 0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
330 1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
331 05a4927951bcef347f51486575b878b2b60137f2 $commit_sha3
332 d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
333 43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
336 cat >expect_log_x <<EOF
341 New notes on 4th commit
343 More notes on 4th commit
346 New notes on 3rd commit
349 New notes on 2nd commit
354 More notes on 1st commit
358 test_expect_success 'merge w into x => Non-conflicting history-less merge' '
359 git config core.notesRef refs/notes/x &&
361 # Verify new state of notes on other notes ref (x)
363 # Also verify that nothing changed on other notes refs (y and w)