1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
|
#!/bin/sh
#
# Copyright (c) 2010 Johan Herland
#
test_description='Test notes merging at various fanout levels'
. ./test-lib.sh
verify_notes () {
notes_ref="$1"
commit="$2"
if test -f "expect_notes_$notes_ref"
then
git -c core.notesRef="refs/notes/$notes_ref" notes |
sort >"output_notes_$notes_ref" &&
test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" ||
return 1
fi &&
git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
"$commit" >"output_log_$notes_ref" &&
test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
}
verify_fanout () {
notes_ref="$1"
# Expect entire notes tree to have a fanout == 1
git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
git ls-tree -r --name-only "refs/notes/$notes_ref" |
while read path
do
echo "$path" | grep "^../[0-9a-f]*$" || {
echo "Invalid path \"$path\"" &&
return 1;
}
done
}
verify_no_fanout () {
notes_ref="$1"
# Expect entire notes tree to have a fanout == 0
git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null &&
git ls-tree -r --name-only "refs/notes/$notes_ref" |
while read path
do
echo "$path" | grep -v "^../.*" || {
echo "Invalid path \"$path\"" &&
return 1;
}
done
}
# Set up a notes merge scenario with different kinds of conflicts
test_expect_success 'setup a few initial commits with notes (notes ref: x)' '
git config core.notesRef refs/notes/x &&
for i in 1 2 3 4 5
do
test_commit "commit$i" >/dev/null &&
git notes add -m "notes for commit$i" || return 1
done &&
git log --format=oneline &&
test_oid_cache <<-EOF
hash05a sha1:aed91155c7a72c2188e781fdf40e0f3761b299db
hash04a sha1:99fab268f9d7ee7b011e091a436c78def8eeee69
hash03a sha1:953c20ae26c7aa0b428c20693fe38bc687f9d1a9
hash02a sha1:6358796131b8916eaa2dde6902642942a1cb37e1
hash01a sha1:b02d459c32f0e68f2fe0981033bb34f38776ba47
hash03b sha1:9f506ee70e20379d7f78204c77b334f43d77410d
hash02b sha1:23a47d6ea7d589895faf800752054818e1e7627b
hash05a sha256:3aae5d26619d96dba93795f66325716e4cbc486884f95a6adee8fb0615a76d12
hash04a sha256:07e43dd3d89fe634d3252e253b426aacc7285a995dcdbcf94ac284060a1122cf
hash03a sha256:26fb52eaa7f4866bf735254587be7b31209ec10e525912ffd8e8ba549ba892ff
hash02a sha256:b57ebdf23634e750dcbc4b9a37991d70f90830d568a0e4529ce9de0a3f8d605c
hash01a sha256:377903b1572bd5117087a5518fcb1011b5053cccbc59e3c7c823a8615204173b
hash03b sha256:04e7b392fda7c185bfa17c9179b56db732edc2dc2b3bf887308dcaabb717270d
hash02b sha256:66099aaaec49a485ed990acadd9a9b81232ea592079964113d8f581ff69ef50b
EOF
'
commit_sha1=$(git rev-parse commit1^{commit})
commit_sha2=$(git rev-parse commit2^{commit})
commit_sha3=$(git rev-parse commit3^{commit})
commit_sha4=$(git rev-parse commit4^{commit})
commit_sha5=$(git rev-parse commit5^{commit})
cat <<EOF | sort >expect_notes_x
$(test_oid hash05a) $commit_sha5
$(test_oid hash04a) $commit_sha4
$(test_oid hash03a) $commit_sha3
$(test_oid hash02a) $commit_sha2
$(test_oid hash01a) $commit_sha1
EOF
cat >expect_log_x <<EOF
$commit_sha5 commit5
notes for commit5
$commit_sha4 commit4
notes for commit4
$commit_sha3 commit3
notes for commit3
$commit_sha2 commit2
notes for commit2
$commit_sha1 commit1
notes for commit1
EOF
test_expect_success 'sanity check (x)' '
verify_notes x commit5 &&
verify_no_fanout x
'
num=300
cp expect_log_x expect_log_y
test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' '
git update-ref refs/notes/y refs/notes/x &&
git config core.notesRef refs/notes/y &&
test_commit_bulk --start=6 --id=commit $((num - 5)) &&
i=0 &&
while test $i -lt $((num - 5))
do
git notes add -m "notes for commit$i" HEAD~$i || return 1
i=$((i + 1))
done &&
test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" &&
# Expected number of commits and notes
test $(git rev-list HEAD | wc -l) = $num &&
test $(git notes list | wc -l) = $num &&
# 5 first notes unchanged
verify_notes y commit5
'
test_expect_success 'notes tree has fanout (y)' 'verify_fanout y'
test_expect_success 'No-op merge (already included) (x => y)' '
git update-ref refs/notes/m refs/notes/y &&
git config core.notesRef refs/notes/m &&
git notes merge x &&
test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
'
test_expect_success 'Fast-forward merge (y => x)' '
git update-ref refs/notes/m refs/notes/x &&
git notes merge y &&
test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)"
'
cat <<EOF | sort >expect_notes_z
$(test_oid hash03b) $commit_sha3
$(test_oid hash02b) $commit_sha2
$(test_oid hash01a) $commit_sha1
EOF
cat >expect_log_z <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
$commit_sha3 commit3
notes for commit3
appended notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
notes for commit1
EOF
test_expect_success 'change some of the initial 5 notes (x -> z)' '
git update-ref refs/notes/z refs/notes/x &&
git config core.notesRef refs/notes/z &&
git notes add -f -m "new notes for commit2" commit2 &&
git notes append -m "appended notes for commit3" commit3 &&
git notes remove commit4 &&
git notes remove commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z'
cp expect_log_z expect_log_m
test_expect_success 'successful merge without conflicts (y => z)' '
git update-ref refs/notes/m refs/notes/z &&
git config core.notesRef refs/notes/m &&
git notes merge y &&
verify_notes m commit5 &&
# x/y/z unchanged
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
cat >expect_log_w <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
other notes for commit4
$commit_sha3 commit3
other notes for commit3
$commit_sha2 commit2
notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'introduce conflicting changes (y -> w)' '
git update-ref refs/notes/w refs/notes/y &&
git config core.notesRef refs/notes/w &&
git notes add -f -m "other notes for commit1" commit1 &&
git notes add -f -m "other notes for commit3" commit3 &&
git notes add -f -m "other notes for commit4" commit4 &&
git notes remove commit5 &&
verify_notes w commit5
'
cat >expect_log_m <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
other notes for commit4
$commit_sha3 commit3
other notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'successful merge using "ours" strategy (z => w)' '
git update-ref refs/notes/m refs/notes/w &&
git config core.notesRef refs/notes/m &&
git notes merge -s ours z &&
verify_notes m commit5 &&
# w/x/y/z unchanged
verify_notes w commit5 &&
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
cat >expect_log_m <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
$commit_sha3 commit3
notes for commit3
appended notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'successful merge using "theirs" strategy (z => w)' '
git update-ref refs/notes/m refs/notes/w &&
git notes merge -s theirs z &&
verify_notes m commit5 &&
# w/x/y/z unchanged
verify_notes w commit5 &&
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
cat >expect_log_m <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
other notes for commit4
$commit_sha3 commit3
other notes for commit3
notes for commit3
appended notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'successful merge using "union" strategy (z => w)' '
git update-ref refs/notes/m refs/notes/w &&
git notes merge -s union z &&
verify_notes m commit5 &&
# w/x/y/z unchanged
verify_notes w commit5 &&
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
cat >expect_log_m <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
other notes for commit4
$commit_sha3 commit3
appended notes for commit3
notes for commit3
other notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'successful merge using "cat_sort_uniq" strategy (z => w)' '
git update-ref refs/notes/m refs/notes/w &&
git notes merge -s cat_sort_uniq z &&
verify_notes m commit5 &&
# w/x/y/z unchanged
verify_notes w commit5 &&
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
# We're merging z into w. Here are the conflicts we expect:
#
# commit | x -> w | x -> z | conflict?
# -------|-----------|-----------|----------
# 1 | changed | unchanged | no, use w
# 2 | unchanged | changed | no, use z
# 3 | changed | changed | yes (w, then z in conflict markers)
# 4 | changed | deleted | yes (w)
# 5 | deleted | deleted | no, deleted
test_expect_success 'fails to merge using "manual" strategy (z => w)' '
git update-ref refs/notes/m refs/notes/w &&
test_must_fail git notes merge z
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
cat <<EOF | sort >expect_conflicts
$commit_sha3
$commit_sha4
EOF
cat >expect_conflict_$commit_sha3 <<EOF
<<<<<<< refs/notes/m
other notes for commit3
=======
notes for commit3
appended notes for commit3
>>>>>>> refs/notes/z
EOF
cat >expect_conflict_$commit_sha4 <<EOF
other notes for commit4
EOF
test_expect_success 'verify conflict entries (with no fanout)' '
ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
test_cmp expect_conflicts output_conflicts &&
( for f in $(cat expect_conflicts); do
test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
exit 1
done ) &&
# Verify that current notes tree (pre-merge) has not changed (m == w)
test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)"
'
cat >expect_log_m <<EOF
$commit_sha5 commit5
$commit_sha4 commit4
other notes for commit4
$commit_sha3 commit3
other notes for commit3
appended notes for commit3
$commit_sha2 commit2
new notes for commit2
$commit_sha1 commit1
other notes for commit1
EOF
test_expect_success 'resolve and finalize merge (z => w)' '
cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF &&
other notes for commit3
appended notes for commit3
EOF
git notes merge --commit &&
verify_notes m commit5 &&
# w/x/y/z unchanged
verify_notes w commit5 &&
verify_notes x commit5 &&
verify_notes y commit5 &&
verify_notes z commit5
'
test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m'
test_done
|