Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3311-notes-merge-fanout.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3311-notes-merge-fanout.sh` 446 lines ยท 11033 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2010 Johan Herland 4 # 5 6 test_description='Test notes merging at various fanout levels' 7 8 . ./test-lib.sh 9 10 verify_notes () { 11 notes_ref="$1" 12 commit="$2" 13 if test -f "expect_notes_$notes_ref" 14 then 15 git -c core.notesRef="refs/notes/$notes_ref" notes | 16 sort >"output_notes_$notes_ref" && 17 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" || 18 return 1 19 fi && 20 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ 21 "$commit" >"output_log_$notes_ref" && 22 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" 23 } 24 25 verify_fanout () { 26 notes_ref="$1" 27 # Expect entire notes tree to have a fanout == 1 28 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null && 29 git ls-tree -r --name-only "refs/notes/$notes_ref" | 30 while read path 31 do 32 echo "$path" | grep "^../[0-9a-f]*$" || { 33 echo "Invalid path \"$path\"" && 34 return 1; 35 } 36 done 37 } 38 39 verify_no_fanout () { 40 notes_ref="$1" 41 # Expect entire notes tree to have a fanout == 0 42 git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null && 43 git ls-tree -r --name-only "refs/notes/$notes_ref" | 44 while read path 45 do 46 echo "$path" | grep -v "^../.*" || { 47 echo "Invalid path \"$path\"" && 48 return 1; 49 } 50 done 51 } 52 53 # Set up a notes merge scenario with different kinds of conflicts 54 test_expect_success 'setup a few initial commits with notes (notes ref: x)' ' 55 git config core.notesRef refs/notes/x && 56 for i in 1 2 3 4 5 57 do 58 test_commit "commit$i" >/dev/null && 59 git notes add -m "notes for commit$i" || return 1 60 done && 61 62 git log --format=oneline && 63 64 test_oid_cache <<-EOF 65 hash05a sha1:`aed91155c7a72c2188e781fdf40e0f3761b299db` 66 hash04a sha1:`99fab268f9d7ee7b011e091a436c78def8eeee69` 67 hash03a sha1:`953c20ae26c7aa0b428c20693fe38bc687f9d1a9` 68 hash02a sha1:`6358796131b8916eaa2dde6902642942a1cb37e1` 69 hash01a sha1:`b02d459c32f0e68f2fe0981033bb34f38776ba47` 70 hash03b sha1:`9f506ee70e20379d7f78204c77b334f43d77410d` 71 hash02b sha1:`23a47d6ea7d589895faf800752054818e1e7627b` 72 73 hash05a sha256:`3aae5d26619d96dba93795f66325716e4cbc486884f95a6adee8fb0615a76d12` 74 hash04a sha256:`07e43dd3d89fe634d3252e253b426aacc7285a995dcdbcf94ac284060a1122cf` 75 hash03a sha256:`26fb52eaa7f4866bf735254587be7b31209ec10e525912ffd8e8ba549ba892ff` 76 hash02a sha256:`b57ebdf23634e750dcbc4b9a37991d70f90830d568a0e4529ce9de0a3f8d605c` 77 hash01a sha256:`377903b1572bd5117087a5518fcb1011b5053cccbc59e3c7c823a8615204173b` 78 hash03b sha256:`04e7b392fda7c185bfa17c9179b56db732edc2dc2b3bf887308dcaabb717270d` 79 hash02b sha256:`66099aaaec49a485ed990acadd9a9b81232ea592079964113d8f581ff69ef50b` 80 EOF 81 ' 82 83 commit_sha1=$(git rev-parse commit1^{commit}) 84 commit_sha2=$(git rev-parse commit2^{commit}) 85 commit_sha3=$(git rev-parse commit3^{commit}) 86 commit_sha4=$(git rev-parse commit4^{commit}) 87 commit_sha5=$(git rev-parse commit5^{commit}) 88 89 cat <expect_notes_x 90 $(test_oid hash05a) $commit_sha5 91 $(test_oid hash04a) $commit_sha4 92 $(test_oid hash03a) $commit_sha3 93 $(test_oid hash02a) $commit_sha2 94 $(test_oid hash01a) $commit_sha1 95 EOF 96 97 cat >expect_log_x < y)' ' 125 git update-ref refs/notes/y refs/notes/x && 126 git config core.notesRef refs/notes/y && 127 test_commit_bulk --start=6 --id=commit $((num - 5)) && 128 i=0 && 129 while test $i -lt $((num - 5)) 130 do 131 git notes add -m "notes for commit$i" HEAD~$i || return 1 132 i=$((i + 1)) 133 done && 134 test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" && 135 # Expected number of commits and notes 136 test $(git rev-list HEAD | wc -l) = $num && 137 test $(git notes list | wc -l) = $num && 138 # 5 first notes unchanged 139 verify_notes y commit5 140 ' 141 142 test_expect_success 'notes tree has fanout (y)' 'verify_fanout y' 143 144 test_expect_success 'No-op merge (already included) (x => y)' ' 145 git update-ref refs/notes/m refs/notes/y && 146 git config core.notesRef refs/notes/m && 147 git notes merge x && 148 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)" 149 ' 150 151 test_expect_success 'Fast-forward merge (y => x)' ' 152 git update-ref refs/notes/m refs/notes/x && 153 git notes merge y && 154 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)" 155 ' 156 157 cat <expect_notes_z 158 $(test_oid hash03b) $commit_sha3 159 $(test_oid hash02b) $commit_sha2 160 $(test_oid hash01a) $commit_sha1 161 EOF 162 163 cat >expect_log_z < z)' ' 182 git update-ref refs/notes/z refs/notes/x && 183 git config core.notesRef refs/notes/z && 184 git notes add -f -m "new notes for commit2" commit2 && 185 git notes append -m "appended notes for commit3" commit3 && 186 git notes remove commit4 && 187 git notes remove commit5 && 188 verify_notes z commit5 189 ' 190 191 test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z' 192 193 cp expect_log_z expect_log_m 194 195 test_expect_success 'successful merge without conflicts (y => z)' ' 196 git update-ref refs/notes/m refs/notes/z && 197 git config core.notesRef refs/notes/m && 198 git notes merge y && 199 verify_notes m commit5 && 200 # x/y/z unchanged 201 verify_notes x commit5 && 202 verify_notes y commit5 && 203 verify_notes z commit5 204 ' 205 206 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 207 208 cat >expect_log_w < w)' ' 226 git update-ref refs/notes/w refs/notes/y && 227 git config core.notesRef refs/notes/w && 228 git notes add -f -m "other notes for commit1" commit1 && 229 git notes add -f -m "other notes for commit3" commit3 && 230 git notes add -f -m "other notes for commit4" commit4 && 231 git notes remove commit5 && 232 verify_notes w commit5 233 ' 234 235 cat >expect_log_m < w)' ' 253 git update-ref refs/notes/m refs/notes/w && 254 git config core.notesRef refs/notes/m && 255 git notes merge -s ours z && 256 verify_notes m commit5 && 257 # w/x/y/z unchanged 258 verify_notes w commit5 && 259 verify_notes x commit5 && 260 verify_notes y commit5 && 261 verify_notes z commit5 262 ' 263 264 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 265 266 cat >expect_log_m < w)' ' 285 git update-ref refs/notes/m refs/notes/w && 286 git notes merge -s theirs z && 287 verify_notes m commit5 && 288 # w/x/y/z unchanged 289 verify_notes w commit5 && 290 verify_notes x commit5 && 291 verify_notes y commit5 && 292 verify_notes z commit5 293 ' 294 295 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 296 297 cat >expect_log_m < w)' ' 319 git update-ref refs/notes/m refs/notes/w && 320 git notes merge -s union z && 321 verify_notes m commit5 && 322 # w/x/y/z unchanged 323 verify_notes w commit5 && 324 verify_notes x commit5 && 325 verify_notes y commit5 && 326 verify_notes z commit5 327 ' 328 329 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 330 331 cat >expect_log_m < w)' ' 351 git update-ref refs/notes/m refs/notes/w && 352 git notes merge -s cat_sort_uniq z && 353 verify_notes m commit5 && 354 # w/x/y/z unchanged 355 verify_notes w commit5 && 356 verify_notes x commit5 && 357 verify_notes y commit5 && 358 verify_notes z commit5 359 ' 360 361 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 362 363 # We're merging z into w. Here are the conflicts we expect: 364 # 365 # commit | x -> w | x -> z | conflict? 366 # -------|-----------|-----------|---------- 367 # 1 | changed | unchanged | no, use w 368 # 2 | unchanged | changed | no, use z 369 # 3 | changed | changed | yes (w, then z in conflict markers) 370 # 4 | changed | deleted | yes (w) 371 # 5 | deleted | deleted | no, deleted 372 373 test_expect_success 'fails to merge using "manual" strategy (z => w)' ' 374 git update-ref refs/notes/m refs/notes/w && 375 test_must_fail git notes merge z 376 ' 377 378 test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' 379 380 cat <expect_conflicts 381 $commit_sha3 382 $commit_sha4 383 EOF 384 385 cat >expect_conflict_$commit_sha3 <>>>>>> refs/notes/z 393 EOF 394 395 cat >expect_conflict_$commit_sha4 <output_conflicts && 401 test_cmp expect_conflicts output_conflicts && 402 ( for f in $(cat expect_conflicts); do 403 test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || 404 exit 1 405 done ) && 406 # Verify that current notes tree (pre-merge) has not changed (m == w) 407 test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" 408 ' 409 410 cat >expect_log_m < w)' ' 430 cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <