| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Johannes E. Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test commit notes' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | write_script fake_editor <<\EOF |
| 11 | echo "$MSG" >"$1" |
| 12 | echo "$MSG" >&2 |
| 13 | EOF |
| 14 | GIT_EDITOR=./fake_editor |
| 15 | export GIT_EDITOR |
| 16 | |
| 17 | indent=" " |
| 18 | |
| 19 | test_expect_success 'cannot annotate non-existing HEAD' ' |
| 20 | test_must_fail env MSG=3 git notes add |
| 21 | ' |
| 22 | |
| 23 | test_expect_success 'setup' ' |
| 24 | test_commit 1st && |
| 25 | test_commit 2nd |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'need valid notes ref' ' |
| 29 | test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show && |
| 30 | test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'refusing to add notes in refs/heads/' ' |
| 34 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'refusing to edit notes in refs/remotes/' ' |
| 38 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit |
| 39 | ' |
| 40 | |
| 41 | # 1 indicates caught gracefully by die, 128 means git-show barked |
| 42 | test_expect_success 'handle empty notes gracefully' ' |
| 43 | test_expect_code 1 git notes show |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'show non-existent notes entry with %N' ' |
| 47 | test_write_lines A B >expect && |
| 48 | git show -s --format="A%n%NB" >actual && |
| 49 | test_cmp expect actual |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'create notes' ' |
| 53 | MSG=b4 git notes add && |
| 54 | test_path_is_missing .git/NOTES_EDITMSG && |
| 55 | git ls-tree -r refs/notes/commits >actual && |
| 56 | test_line_count = 1 actual && |
| 57 | echo b4 >expect && |
| 58 | git notes show >actual && |
| 59 | test_cmp expect actual && |
| 60 | git show HEAD^ && |
| 61 | test_must_fail git notes show HEAD^ |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'show notes entry with %N' ' |
| 65 | test_write_lines A b4 B >expect && |
| 66 | git show -s --format="A%n%NB" >actual && |
| 67 | test_cmp expect actual |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'create reflog entry' ' |
| 71 | ref=$(git rev-parse --short refs/notes/commits) && |
| 72 | cat <<-EOF >expect && |
| 73 | $ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\'' |
| 74 | EOF |
| 75 | git reflog show refs/notes/commits >actual && |
| 76 | test_cmp expect actual |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'edit existing notes' ' |
| 80 | MSG=b3 git notes edit && |
| 81 | test_path_is_missing .git/NOTES_EDITMSG && |
| 82 | git ls-tree -r refs/notes/commits >actual && |
| 83 | test_line_count = 1 actual && |
| 84 | echo b3 >expect && |
| 85 | git notes show >actual && |
| 86 | test_cmp expect actual && |
| 87 | git show HEAD^ && |
| 88 | test_must_fail git notes show HEAD^ |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'show notes from treeish' ' |
| 92 | echo b3 >expect && |
| 93 | git notes --ref commits^{tree} show >actual && |
| 94 | test_cmp expect actual && |
| 95 | |
| 96 | echo b4 >expect && |
| 97 | git notes --ref commits@{1} show >actual && |
| 98 | test_cmp expect actual |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'cannot edit notes from non-ref' ' |
| 102 | test_must_fail git notes --ref commits^{tree} edit && |
| 103 | test_must_fail git notes --ref commits@{1} edit |
| 104 | ' |
| 105 | |
| 106 | test_expect_success 'cannot "git notes add -m" where notes already exists' ' |
| 107 | test_must_fail git notes add -m "b2" && |
| 108 | test_path_is_missing .git/NOTES_EDITMSG && |
| 109 | git ls-tree -r refs/notes/commits >actual && |
| 110 | test_line_count = 1 actual && |
| 111 | echo b3 >expect && |
| 112 | git notes show >actual && |
| 113 | test_cmp expect actual && |
| 114 | git show HEAD^ && |
| 115 | test_must_fail git notes show HEAD^ |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' |
| 119 | git notes add -f -m "b1" && |
| 120 | test_path_is_missing .git/NOTES_EDITMSG && |
| 121 | git ls-tree -r refs/notes/commits >actual && |
| 122 | test_line_count = 1 actual && |
| 123 | echo b1 >expect && |
| 124 | git notes show >actual && |
| 125 | test_cmp expect actual && |
| 126 | git show HEAD^ && |
| 127 | test_must_fail git notes show HEAD^ |
| 128 | ' |
| 129 | |
| 130 | test_expect_success 'add w/no options on existing note morphs into edit' ' |
| 131 | MSG=b2 git notes add && |
| 132 | test_path_is_missing .git/NOTES_EDITMSG && |
| 133 | git ls-tree -r refs/notes/commits >actual && |
| 134 | test_line_count = 1 actual && |
| 135 | echo b2 >expect && |
| 136 | git notes show >actual && |
| 137 | test_cmp expect actual && |
| 138 | git show HEAD^ && |
| 139 | test_must_fail git notes show HEAD^ |
| 140 | ' |
| 141 | |
| 142 | test_expect_success 'can overwrite existing note with "git notes add -f"' ' |
| 143 | MSG=b1 git notes add -f && |
| 144 | test_path_is_missing .git/NOTES_EDITMSG && |
| 145 | git ls-tree -r refs/notes/commits >actual && |
| 146 | test_line_count = 1 actual && |
| 147 | echo b1 >expect && |
| 148 | git notes show >actual && |
| 149 | test_cmp expect actual && |
| 150 | git show HEAD^ && |
| 151 | test_must_fail git notes show HEAD^ |
| 152 | ' |
| 153 | |
| 154 | test_expect_success 'show notes' ' |
| 155 | commit=$(git rev-parse HEAD) && |
| 156 | cat >expect <<-EOF && |
| 157 | commit $commit |
| 158 | Author: A U Thor <author@example.com> |
| 159 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 160 | |
| 161 | ${indent}2nd |
| 162 | |
| 163 | Notes: |
| 164 | ${indent}b1 |
| 165 | EOF |
| 166 | git cat-file commit HEAD >commits && |
| 167 | test_grep ! b1 commits && |
| 168 | git log -1 >actual && |
| 169 | test_cmp expect actual |
| 170 | ' |
| 171 | |
| 172 | test_expect_success 'show multi-line notes' ' |
| 173 | test_commit 3rd && |
| 174 | MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add && |
| 175 | commit=$(git rev-parse HEAD) && |
| 176 | cat >expect-multiline <<-EOF && |
| 177 | commit $commit |
| 178 | Author: A U Thor <author@example.com> |
| 179 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 180 | |
| 181 | ${indent}3rd |
| 182 | |
| 183 | Notes: |
| 184 | ${indent}b3 |
| 185 | ${indent}c3c3c3c3 |
| 186 | ${indent}d3d3d3 |
| 187 | |
| 188 | EOF |
| 189 | cat expect >>expect-multiline && |
| 190 | git log -2 >actual && |
| 191 | test_cmp expect-multiline actual |
| 192 | ' |
| 193 | |
| 194 | test_expect_success 'show -F notes' ' |
| 195 | test_commit 4th && |
| 196 | echo "xyzzy" >note5 && |
| 197 | git notes add -F note5 && |
| 198 | commit=$(git rev-parse HEAD) && |
| 199 | cat >expect-F <<-EOF && |
| 200 | commit $commit |
| 201 | Author: A U Thor <author@example.com> |
| 202 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 203 | |
| 204 | ${indent}4th |
| 205 | |
| 206 | Notes: |
| 207 | ${indent}xyzzy |
| 208 | |
| 209 | EOF |
| 210 | cat expect-multiline >>expect-F && |
| 211 | git log -3 >actual && |
| 212 | test_cmp expect-F actual |
| 213 | ' |
| 214 | |
| 215 | test_expect_success 'Re-adding -F notes without -f fails' ' |
| 216 | echo "zyxxy" >note5 && |
| 217 | test_must_fail git notes add -F note5 && |
| 218 | git log -3 >actual && |
| 219 | test_cmp expect-F actual |
| 220 | ' |
| 221 | |
| 222 | test_expect_success 'git log --pretty=raw does not show notes' ' |
| 223 | commit=$(git rev-parse HEAD) && |
| 224 | tree=$(git rev-parse HEAD^{tree}) && |
| 225 | parent=$(git rev-parse HEAD^) && |
| 226 | cat >expect <<-EOF && |
| 227 | commit $commit |
| 228 | tree $tree |
| 229 | parent $parent |
| 230 | author A U Thor <author@example.com> 1112912173 -0700 |
| 231 | committer C O Mitter <committer@example.com> 1112912173 -0700 |
| 232 | |
| 233 | ${indent}4th |
| 234 | EOF |
| 235 | git log -1 --pretty=raw >actual && |
| 236 | test_cmp expect actual |
| 237 | ' |
| 238 | |
| 239 | test_expect_success 'git log --show-notes' ' |
| 240 | cat >>expect <<-EOF && |
| 241 | |
| 242 | Notes: |
| 243 | ${indent}xyzzy |
| 244 | EOF |
| 245 | git log -1 --pretty=raw --show-notes >actual && |
| 246 | test_cmp expect actual |
| 247 | ' |
| 248 | |
| 249 | test_expect_success 'git log --no-notes' ' |
| 250 | git log -1 --no-notes >actual && |
| 251 | test_grep ! xyzzy actual |
| 252 | ' |
| 253 | |
| 254 | test_expect_success 'git format-patch does not show notes' ' |
| 255 | git format-patch -1 --stdout >actual && |
| 256 | test_grep ! xyzzy actual |
| 257 | ' |
| 258 | |
| 259 | test_expect_success 'git format-patch --show-notes does show notes' ' |
| 260 | git format-patch --show-notes -1 --stdout >actual && |
| 261 | test_grep xyzzy actual |
| 262 | ' |
| 263 | |
| 264 | for pretty in \ |
| 265 | "" --pretty --pretty=raw --pretty=short --pretty=medium \ |
| 266 | --pretty=full --pretty=fuller --pretty=format:%s --oneline |
| 267 | do |
| 268 | case "$pretty" in |
| 269 | "") p= not= negate="" ;; |
| 270 | ?*) p="$pretty" not=" not" negate="!" ;; |
| 271 | esac |
| 272 | test_expect_success "git show $pretty does$not show notes" ' |
| 273 | git show $p >actual && |
| 274 | eval "$negate grep xyzzy actual" |
| 275 | ' |
| 276 | done |
| 277 | |
| 278 | test_expect_success 'setup alternate notes ref' ' |
| 279 | git notes --ref=alternate add -m alternate |
| 280 | ' |
| 281 | |
| 282 | test_expect_success 'git log --notes shows default notes' ' |
| 283 | git log -1 --notes >actual && |
| 284 | test_grep xyzzy actual && |
| 285 | test_grep ! alternate actual |
| 286 | ' |
| 287 | |
| 288 | test_expect_success 'git log --notes=X shows only X' ' |
| 289 | git log -1 --notes=alternate >actual && |
| 290 | test_grep ! xyzzy actual && |
| 291 | test_grep alternate actual |
| 292 | ' |
| 293 | |
| 294 | test_expect_success 'git log --notes --notes=X shows both' ' |
| 295 | git log -1 --notes --notes=alternate >actual && |
| 296 | test_grep xyzzy actual && |
| 297 | test_grep alternate actual |
| 298 | ' |
| 299 | |
| 300 | test_expect_success 'git log --no-notes resets default state' ' |
| 301 | git log -1 --notes --notes=alternate \ |
| 302 | --no-notes --notes=alternate \ |
| 303 | >actual && |
| 304 | test_grep ! xyzzy actual && |
| 305 | test_grep alternate actual |
| 306 | ' |
| 307 | |
| 308 | test_expect_success 'git log --no-notes resets ref list' ' |
| 309 | git log -1 --notes --notes=alternate \ |
| 310 | --no-notes --notes \ |
| 311 | >actual && |
| 312 | test_grep xyzzy actual && |
| 313 | test_grep ! alternate actual |
| 314 | ' |
| 315 | |
| 316 | test_expect_success 'show -m notes' ' |
| 317 | test_commit 5th && |
| 318 | git notes add -m spam -m "foo${LF}bar${LF}baz" && |
| 319 | commit=$(git rev-parse HEAD) && |
| 320 | cat >expect-m <<-EOF && |
| 321 | commit $commit |
| 322 | Author: A U Thor <author@example.com> |
| 323 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 324 | |
| 325 | ${indent}5th |
| 326 | |
| 327 | Notes: |
| 328 | ${indent}spam |
| 329 | ${indent} |
| 330 | ${indent}foo |
| 331 | ${indent}bar |
| 332 | ${indent}baz |
| 333 | |
| 334 | EOF |
| 335 | cat expect-F >>expect-m && |
| 336 | git log -4 >actual && |
| 337 | test_cmp expect-m actual |
| 338 | ' |
| 339 | |
| 340 | test_expect_success 'remove note with add -f -F /dev/null' ' |
| 341 | git notes add -f -F /dev/null && |
| 342 | commit=$(git rev-parse HEAD) && |
| 343 | cat >expect-rm-F <<-EOF && |
| 344 | commit $commit |
| 345 | Author: A U Thor <author@example.com> |
| 346 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 347 | |
| 348 | ${indent}5th |
| 349 | |
| 350 | EOF |
| 351 | cat expect-F >>expect-rm-F && |
| 352 | git log -4 >actual && |
| 353 | test_cmp expect-rm-F actual && |
| 354 | test_must_fail git notes show |
| 355 | ' |
| 356 | |
| 357 | test_expect_success 'do not create empty note with -m ""' ' |
| 358 | git notes add -m "" && |
| 359 | git log -4 >actual && |
| 360 | test_cmp expect-rm-F actual && |
| 361 | test_must_fail git notes show |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'create note with combination of -m and -F' ' |
| 365 | test_when_finished git notes remove HEAD && |
| 366 | cat >expect-combine_m_and_F <<-EOF && |
| 367 | foo |
| 368 | |
| 369 | xyzzy |
| 370 | |
| 371 | bar |
| 372 | |
| 373 | zyxxy |
| 374 | |
| 375 | baz |
| 376 | EOF |
| 377 | echo "xyzzy" >note_a && |
| 378 | echo "zyxxy" >note_b && |
| 379 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" && |
| 380 | git notes show >actual && |
| 381 | test_cmp expect-combine_m_and_F actual |
| 382 | ' |
| 383 | |
| 384 | test_expect_success 'create note with combination of -m and -F and --separator' ' |
| 385 | test_when_finished git notes remove HEAD && |
| 386 | cat >expect-combine_m_and_F <<-\EOF && |
| 387 | foo |
| 388 | ------- |
| 389 | xyzzy |
| 390 | ------- |
| 391 | bar |
| 392 | ------- |
| 393 | zyxxy |
| 394 | ------- |
| 395 | baz |
| 396 | EOF |
| 397 | echo "xyzzy" >note_a && |
| 398 | echo "zyxxy" >note_b && |
| 399 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --separator="-------" && |
| 400 | git notes show >actual && |
| 401 | test_cmp expect-combine_m_and_F actual |
| 402 | ' |
| 403 | |
| 404 | test_expect_success 'create note with combination of -m and -F and --no-separator' ' |
| 405 | cat >expect-combine_m_and_F <<-\EOF && |
| 406 | foo |
| 407 | xyzzy |
| 408 | bar |
| 409 | zyxxy |
| 410 | baz |
| 411 | EOF |
| 412 | echo "xyzzy" >note_a && |
| 413 | echo "zyxxy" >note_b && |
| 414 | git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --no-separator && |
| 415 | git notes show >actual && |
| 416 | test_cmp expect-combine_m_and_F actual |
| 417 | ' |
| 418 | |
| 419 | test_expect_success 'remove note with "git notes remove"' ' |
| 420 | git notes remove HEAD^ && |
| 421 | git notes remove && |
| 422 | commit=$(git rev-parse HEAD) && |
| 423 | parent=$(git rev-parse HEAD^) && |
| 424 | cat >expect-rm-remove <<-EOF && |
| 425 | commit $commit |
| 426 | Author: A U Thor <author@example.com> |
| 427 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 428 | |
| 429 | ${indent}5th |
| 430 | |
| 431 | commit $parent |
| 432 | Author: A U Thor <author@example.com> |
| 433 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 434 | |
| 435 | ${indent}4th |
| 436 | |
| 437 | EOF |
| 438 | cat expect-multiline >>expect-rm-remove && |
| 439 | git log -4 >actual && |
| 440 | test_cmp expect-rm-remove actual && |
| 441 | test_must_fail git notes show HEAD^ |
| 442 | ' |
| 443 | |
| 444 | test_expect_success 'removing non-existing note should not create new commit' ' |
| 445 | git rev-parse --verify refs/notes/commits >before_commit && |
| 446 | test_must_fail git notes remove HEAD^ && |
| 447 | git rev-parse --verify refs/notes/commits >after_commit && |
| 448 | test_cmp before_commit after_commit |
| 449 | ' |
| 450 | |
| 451 | test_expect_success 'removing more than one' ' |
| 452 | before=$(git rev-parse --verify refs/notes/commits) && |
| 453 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 454 | |
| 455 | # We have only two -- add another and make sure it stays |
| 456 | git notes add -m "extra" && |
| 457 | git notes list HEAD >after-removal-expect && |
| 458 | git notes remove HEAD^^ HEAD^^^ && |
| 459 | git notes list | sed -e "s/ .*//" >actual && |
| 460 | test_cmp after-removal-expect actual |
| 461 | ' |
| 462 | |
| 463 | test_expect_success 'removing is atomic' ' |
| 464 | before=$(git rev-parse --verify refs/notes/commits) && |
| 465 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 466 | test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ && |
| 467 | after=$(git rev-parse --verify refs/notes/commits) && |
| 468 | test "$before" = "$after" |
| 469 | ' |
| 470 | |
| 471 | test_expect_success 'removing with --ignore-missing' ' |
| 472 | before=$(git rev-parse --verify refs/notes/commits) && |
| 473 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 474 | |
| 475 | # We have only two -- add another and make sure it stays |
| 476 | git notes add -m "extra" && |
| 477 | git notes list HEAD >after-removal-expect && |
| 478 | git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ && |
| 479 | git notes list | sed -e "s/ .*//" >actual && |
| 480 | test_cmp after-removal-expect actual |
| 481 | ' |
| 482 | |
| 483 | test_expect_success 'removing with --ignore-missing but bogus ref' ' |
| 484 | before=$(git rev-parse --verify refs/notes/commits) && |
| 485 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 486 | test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT && |
| 487 | after=$(git rev-parse --verify refs/notes/commits) && |
| 488 | test "$before" = "$after" |
| 489 | ' |
| 490 | |
| 491 | test_expect_success 'remove reads from --stdin' ' |
| 492 | before=$(git rev-parse --verify refs/notes/commits) && |
| 493 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 494 | |
| 495 | # We have only two -- add another and make sure it stays |
| 496 | git notes add -m "extra" && |
| 497 | git notes list HEAD >after-removal-expect && |
| 498 | git rev-parse HEAD^^ HEAD^^^ >input && |
| 499 | git notes remove --stdin <input && |
| 500 | git notes list | sed -e "s/ .*//" >actual && |
| 501 | test_cmp after-removal-expect actual |
| 502 | ' |
| 503 | |
| 504 | test_expect_success 'remove --stdin is also atomic' ' |
| 505 | before=$(git rev-parse --verify refs/notes/commits) && |
| 506 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 507 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && |
| 508 | test_must_fail git notes remove --stdin <input && |
| 509 | after=$(git rev-parse --verify refs/notes/commits) && |
| 510 | test "$before" = "$after" |
| 511 | ' |
| 512 | |
| 513 | test_expect_success 'removing with --stdin --ignore-missing' ' |
| 514 | before=$(git rev-parse --verify refs/notes/commits) && |
| 515 | test_when_finished "git update-ref refs/notes/commits $before" && |
| 516 | |
| 517 | # We have only two -- add another and make sure it stays |
| 518 | git notes add -m "extra" && |
| 519 | git notes list HEAD >after-removal-expect && |
| 520 | git rev-parse HEAD^^ HEAD^^^ HEAD^ >input && |
| 521 | git notes remove --ignore-missing --stdin <input && |
| 522 | git notes list | sed -e "s/ .*//" >actual && |
| 523 | test_cmp after-removal-expect actual |
| 524 | ' |
| 525 | |
| 526 | test_expect_success 'list notes with "git notes list"' ' |
| 527 | commit_2=$(git rev-parse 2nd) && |
| 528 | commit_3=$(git rev-parse 3rd) && |
| 529 | note_2=$(git rev-parse refs/notes/commits:$commit_2) && |
| 530 | note_3=$(git rev-parse refs/notes/commits:$commit_3) && |
| 531 | sort -t" " -k2 >expect <<-EOF && |
| 532 | $note_2 $commit_2 |
| 533 | $note_3 $commit_3 |
| 534 | EOF |
| 535 | git notes list >actual && |
| 536 | test_cmp expect actual |
| 537 | ' |
| 538 | |
| 539 | test_expect_success 'list notes with "git notes"' ' |
| 540 | git notes >actual && |
| 541 | test_cmp expect actual |
| 542 | ' |
| 543 | |
| 544 | test_expect_success '"git notes" without subcommand does not take arguments' ' |
| 545 | test_expect_code 129 git notes HEAD^^ 2>err && |
| 546 | test_grep "^error: unknown subcommand" err |
| 547 | ' |
| 548 | |
| 549 | test_expect_success 'list specific note with "git notes list <object>"' ' |
| 550 | git rev-parse refs/notes/commits:$commit_3 >expect && |
| 551 | git notes list HEAD^^ >actual && |
| 552 | test_cmp expect actual |
| 553 | ' |
| 554 | |
| 555 | test_expect_success 'listing non-existing notes fails' ' |
| 556 | test_must_fail git notes list HEAD >actual && |
| 557 | test_must_be_empty actual |
| 558 | ' |
| 559 | |
| 560 | test_expect_success 'append: specify a separator with an empty arg' ' |
| 561 | test_when_finished git notes remove HEAD && |
| 562 | cat >expect <<-\EOF && |
| 563 | notes-1 |
| 564 | |
| 565 | notes-2 |
| 566 | EOF |
| 567 | |
| 568 | git notes add -m "notes-1" && |
| 569 | git notes append --separator="" -m "notes-2" && |
| 570 | git notes show >actual && |
| 571 | test_cmp expect actual |
| 572 | ' |
| 573 | |
| 574 | test_expect_success 'append: specify a separator without arg' ' |
| 575 | test_when_finished git notes remove HEAD && |
| 576 | cat >expect <<-\EOF && |
| 577 | notes-1 |
| 578 | |
| 579 | notes-2 |
| 580 | EOF |
| 581 | |
| 582 | git notes add -m "notes-1" && |
| 583 | git notes append --separator -m "notes-2" && |
| 584 | git notes show >actual && |
| 585 | test_cmp expect actual |
| 586 | ' |
| 587 | |
| 588 | test_expect_success 'append: specify as --no-separator' ' |
| 589 | test_when_finished git notes remove HEAD && |
| 590 | cat >expect <<-\EOF && |
| 591 | notes-1 |
| 592 | notes-2 |
| 593 | EOF |
| 594 | |
| 595 | git notes add -m "notes-1" && |
| 596 | git notes append --no-separator -m "notes-2" && |
| 597 | git notes show >actual && |
| 598 | test_cmp expect actual |
| 599 | ' |
| 600 | |
| 601 | test_expect_success 'append: specify separator with line break' ' |
| 602 | test_when_finished git notes remove HEAD && |
| 603 | cat >expect <<-\EOF && |
| 604 | notes-1 |
| 605 | ------- |
| 606 | notes-2 |
| 607 | EOF |
| 608 | |
| 609 | git notes add -m "notes-1" && |
| 610 | git notes append --separator="-------$LF" -m "notes-2" && |
| 611 | git notes show >actual && |
| 612 | test_cmp expect actual |
| 613 | ' |
| 614 | |
| 615 | test_expect_success 'append: specify separator without line break' ' |
| 616 | test_when_finished git notes remove HEAD && |
| 617 | cat >expect <<-\EOF && |
| 618 | notes-1 |
| 619 | ------- |
| 620 | notes-2 |
| 621 | EOF |
| 622 | |
| 623 | git notes add -m "notes-1" && |
| 624 | git notes append --separator="-------" -m "notes-2" && |
| 625 | git notes show >actual && |
| 626 | test_cmp expect actual |
| 627 | ' |
| 628 | |
| 629 | test_expect_success 'append: specify separator with multiple messages' ' |
| 630 | test_when_finished git notes remove HEAD && |
| 631 | cat >expect <<-\EOF && |
| 632 | notes-1 |
| 633 | ------- |
| 634 | notes-2 |
| 635 | ------- |
| 636 | notes-3 |
| 637 | EOF |
| 638 | |
| 639 | git notes add -m "notes-1" && |
| 640 | git notes append --separator="-------" -m "notes-2" -m "notes-3" && |
| 641 | git notes show >actual && |
| 642 | test_cmp expect actual |
| 643 | ' |
| 644 | |
| 645 | test_expect_success 'append note with combination of -m and -F and --separator' ' |
| 646 | test_when_finished git notes remove HEAD && |
| 647 | cat >expect-combine_m_and_F <<-\EOF && |
| 648 | m-notes-1 |
| 649 | ------- |
| 650 | f-notes-1 |
| 651 | ------- |
| 652 | m-notes-2 |
| 653 | ------- |
| 654 | f-notes-2 |
| 655 | ------- |
| 656 | m-notes-3 |
| 657 | EOF |
| 658 | |
| 659 | echo "f-notes-1" >note_a && |
| 660 | echo "f-notes-2" >note_b && |
| 661 | git notes append -m "m-notes-1" -F note_a -m "m-notes-2" -F note_b -m "m-notes-3" --separator="-------" && |
| 662 | git notes show >actual && |
| 663 | test_cmp expect-combine_m_and_F actual |
| 664 | ' |
| 665 | |
| 666 | test_expect_success 'append to existing note with "git notes append"' ' |
| 667 | cat >expect <<-EOF && |
| 668 | Initial set of notes |
| 669 | |
| 670 | More notes appended with git notes append |
| 671 | EOF |
| 672 | git notes add -m "Initial set of notes" && |
| 673 | git notes append -m "More notes appended with git notes append" && |
| 674 | git notes show >actual && |
| 675 | test_cmp expect actual |
| 676 | ' |
| 677 | |
| 678 | test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' |
| 679 | commit_5=$(git rev-parse 5th) && |
| 680 | note_5=$(git rev-parse refs/notes/commits:$commit_5) && |
| 681 | sort -t" " -k2 >expect_list <<-EOF && |
| 682 | $note_2 $commit_2 |
| 683 | $note_3 $commit_3 |
| 684 | $note_5 $commit_5 |
| 685 | EOF |
| 686 | git notes list >actual && |
| 687 | test_cmp expect_list actual |
| 688 | ' |
| 689 | |
| 690 | test_expect_success 'appending empty string does not change existing note' ' |
| 691 | git notes append -m "" && |
| 692 | git notes show >actual && |
| 693 | test_cmp expect actual |
| 694 | ' |
| 695 | |
| 696 | test_expect_success 'git notes append == add when there is no existing note' ' |
| 697 | git notes remove HEAD && |
| 698 | test_must_fail git notes list HEAD && |
| 699 | git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" && |
| 700 | git notes show >actual && |
| 701 | test_cmp expect actual |
| 702 | ' |
| 703 | |
| 704 | test_expect_success 'appending empty string to non-existing note does not create note' ' |
| 705 | git notes remove HEAD && |
| 706 | test_must_fail git notes list HEAD && |
| 707 | git notes append -m "" && |
| 708 | test_must_fail git notes list HEAD |
| 709 | ' |
| 710 | |
| 711 | test_expect_success 'create other note on a different notes ref (setup)' ' |
| 712 | test_commit 6th && |
| 713 | GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" && |
| 714 | commit=$(git rev-parse HEAD) && |
| 715 | cat >expect-not-other <<-EOF && |
| 716 | commit $commit |
| 717 | Author: A U Thor <author@example.com> |
| 718 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 719 | |
| 720 | ${indent}6th |
| 721 | EOF |
| 722 | cp expect-not-other expect-other && |
| 723 | cat >>expect-other <<-EOF |
| 724 | |
| 725 | Notes (other): |
| 726 | ${indent}other note |
| 727 | EOF |
| 728 | ' |
| 729 | |
| 730 | test_expect_success 'Do not show note on other ref by default' ' |
| 731 | git log -1 >actual && |
| 732 | test_cmp expect-not-other actual |
| 733 | ' |
| 734 | |
| 735 | test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' |
| 736 | GIT_NOTES_REF="refs/notes/other" git log -1 >actual && |
| 737 | test_cmp expect-other actual |
| 738 | ' |
| 739 | |
| 740 | test_expect_success 'Do show note when ref is given in core.notesRef config' ' |
| 741 | test_config core.notesRef "refs/notes/other" && |
| 742 | git log -1 >actual && |
| 743 | test_cmp expect-other actual |
| 744 | ' |
| 745 | |
| 746 | test_expect_success 'Do not show note when core.notesRef is overridden' ' |
| 747 | test_config core.notesRef "refs/notes/other" && |
| 748 | GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual && |
| 749 | test_cmp expect-not-other actual |
| 750 | ' |
| 751 | |
| 752 | test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' |
| 753 | commit=$(git rev-parse HEAD) && |
| 754 | parent=$(git rev-parse HEAD^) && |
| 755 | cat >expect-both <<-EOF && |
| 756 | commit $commit |
| 757 | Author: A U Thor <author@example.com> |
| 758 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 759 | |
| 760 | ${indent}6th |
| 761 | |
| 762 | Notes: |
| 763 | ${indent}order test |
| 764 | |
| 765 | Notes (other): |
| 766 | ${indent}other note |
| 767 | |
| 768 | commit $parent |
| 769 | Author: A U Thor <author@example.com> |
| 770 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 771 | |
| 772 | ${indent}5th |
| 773 | |
| 774 | Notes: |
| 775 | ${indent}replacement for deleted note |
| 776 | EOF |
| 777 | GIT_NOTES_REF=refs/notes/commits git notes add \ |
| 778 | -m"replacement for deleted note" HEAD^ && |
| 779 | GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" && |
| 780 | test_unconfig core.notesRef && |
| 781 | test_config notes.displayRef "refs/notes/*" && |
| 782 | git log -2 >actual && |
| 783 | test_cmp expect-both actual |
| 784 | ' |
| 785 | |
| 786 | test_expect_success 'core.notesRef is implicitly in notes.displayRef' ' |
| 787 | test_config core.notesRef refs/notes/commits && |
| 788 | test_config notes.displayRef refs/notes/other && |
| 789 | git log -2 >actual && |
| 790 | test_cmp expect-both actual |
| 791 | ' |
| 792 | |
| 793 | test_expect_success 'notes.displayRef can be given more than once' ' |
| 794 | test_unconfig core.notesRef && |
| 795 | test_config notes.displayRef refs/notes/commits && |
| 796 | git config --add notes.displayRef refs/notes/other && |
| 797 | git log -2 >actual && |
| 798 | test_cmp expect-both actual |
| 799 | ' |
| 800 | |
| 801 | test_expect_success 'notes.displayRef respects order' ' |
| 802 | commit=$(git rev-parse HEAD) && |
| 803 | cat >expect-both-reversed <<-EOF && |
| 804 | commit $commit |
| 805 | Author: A U Thor <author@example.com> |
| 806 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 807 | |
| 808 | ${indent}6th |
| 809 | |
| 810 | Notes (other): |
| 811 | ${indent}other note |
| 812 | |
| 813 | Notes: |
| 814 | ${indent}order test |
| 815 | EOF |
| 816 | test_config core.notesRef refs/notes/other && |
| 817 | test_config notes.displayRef refs/notes/commits && |
| 818 | git log -1 >actual && |
| 819 | test_cmp expect-both-reversed actual |
| 820 | ' |
| 821 | |
| 822 | test_expect_success 'notes.displayRef with no value handled gracefully' ' |
| 823 | test_must_fail git -c notes.displayRef log -0 --notes && |
| 824 | test_must_fail git -c notes.displayRef diff-tree --notes HEAD |
| 825 | ' |
| 826 | |
| 827 | test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' |
| 828 | GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ |
| 829 | git log -2 >actual && |
| 830 | test_cmp expect-both actual |
| 831 | ' |
| 832 | |
| 833 | test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' |
| 834 | commit=$(git rev-parse HEAD) && |
| 835 | parent=$(git rev-parse HEAD^) && |
| 836 | cat >expect-none <<-EOF && |
| 837 | commit $commit |
| 838 | Author: A U Thor <author@example.com> |
| 839 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 840 | |
| 841 | ${indent}6th |
| 842 | |
| 843 | commit $parent |
| 844 | Author: A U Thor <author@example.com> |
| 845 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 846 | |
| 847 | ${indent}5th |
| 848 | EOF |
| 849 | test_config notes.displayRef "refs/notes/*" && |
| 850 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual && |
| 851 | test_cmp expect-none actual |
| 852 | ' |
| 853 | |
| 854 | test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' ' |
| 855 | GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual && |
| 856 | test_cmp expect-both actual |
| 857 | ' |
| 858 | |
| 859 | test_expect_success '--no-standard-notes' ' |
| 860 | commit=$(git rev-parse HEAD) && |
| 861 | cat >expect-commits <<-EOF && |
| 862 | commit $commit |
| 863 | Author: A U Thor <author@example.com> |
| 864 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 865 | |
| 866 | ${indent}6th |
| 867 | |
| 868 | Notes: |
| 869 | ${indent}order test |
| 870 | EOF |
| 871 | git log --no-standard-notes --show-notes=commits -1 >actual && |
| 872 | test_cmp expect-commits actual |
| 873 | ' |
| 874 | |
| 875 | test_expect_success '--standard-notes' ' |
| 876 | test_config notes.displayRef "refs/notes/*" && |
| 877 | git log --no-standard-notes --show-notes=commits \ |
| 878 | --standard-notes -2 >actual && |
| 879 | test_cmp expect-both actual |
| 880 | ' |
| 881 | |
| 882 | test_expect_success '--show-notes=ref accumulates' ' |
| 883 | git log --show-notes=other --show-notes=commits \ |
| 884 | --no-standard-notes -1 >actual && |
| 885 | test_cmp expect-both-reversed actual |
| 886 | ' |
| 887 | |
| 888 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
| 889 | test_config core.notesRef refs/notes/other && |
| 890 | echo "Note on a tree" >expect && |
| 891 | git notes add -m "Note on a tree" HEAD: && |
| 892 | git notes show HEAD: >actual && |
| 893 | test_cmp expect actual && |
| 894 | echo "Note on a blob" >expect && |
| 895 | git ls-tree --name-only HEAD >files && |
| 896 | filename=$(head -n1 files) && |
| 897 | git notes add -m "Note on a blob" HEAD:$filename && |
| 898 | git notes show HEAD:$filename >actual && |
| 899 | test_cmp expect actual && |
| 900 | echo "Note on a tag" >expect && |
| 901 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
| 902 | git notes add -m "Note on a tag" foobar && |
| 903 | git notes show foobar >actual && |
| 904 | test_cmp expect actual |
| 905 | ' |
| 906 | |
| 907 | test_expect_success 'create note from other note with "git notes add -C"' ' |
| 908 | test_commit 7th && |
| 909 | commit=$(git rev-parse HEAD) && |
| 910 | cat >expect <<-EOF && |
| 911 | commit $commit |
| 912 | Author: A U Thor <author@example.com> |
| 913 | Date: Thu Apr 7 15:19:13 2005 -0700 |
| 914 | |
| 915 | ${indent}7th |
| 916 | |
| 917 | Notes: |
| 918 | ${indent}order test |
| 919 | EOF |
| 920 | note=$(git notes list HEAD^) && |
| 921 | git notes add -C $note && |
| 922 | git log -1 >actual && |
| 923 | test_cmp expect actual && |
| 924 | git notes list HEAD^ >expect && |
| 925 | git notes list HEAD >actual && |
| 926 | test_cmp expect actual |
| 927 | ' |
| 928 | |
| 929 | test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' |
| 930 | test_commit 8th && |
| 931 | test_must_fail git notes add -C deadbeef && |
| 932 | test_must_fail git notes list HEAD |
| 933 | ' |
| 934 | |
| 935 | test_expect_success 'create note from non-blob with "git notes add -C" fails' ' |
| 936 | commit=$(git rev-parse --verify HEAD) && |
| 937 | tree=$(git rev-parse --verify HEAD:) && |
| 938 | test_must_fail git notes add -C $commit && |
| 939 | test_must_fail git notes add -C $tree && |
| 940 | test_must_fail git notes list HEAD |
| 941 | ' |
| 942 | |
| 943 | test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' |
| 944 | commit=$(git rev-parse HEAD) && |
| 945 | cat >expect <<-EOF && |
| 946 | commit $commit |
| 947 | Author: A U Thor <author@example.com> |
| 948 | Date: Thu Apr 7 15:20:13 2005 -0700 |
| 949 | |
| 950 | ${indent}8th |
| 951 | |
| 952 | Notes: |
| 953 | ${indent}This is a blob object |
| 954 | EOF |
| 955 | echo "This is a blob object" | git hash-object -w --stdin >blob && |
| 956 | git notes add -C $(cat blob) && |
| 957 | git log -1 >actual && |
| 958 | test_cmp expect actual && |
| 959 | git notes list HEAD >actual && |
| 960 | test_cmp blob actual |
| 961 | ' |
| 962 | |
| 963 | test_expect_success 'create note from blob with "-C", also specify "-m", "-F" and "--separator"' ' |
| 964 | # 8th will be reuseed in following tests, so rollback when the test is done |
| 965 | test_when_finished "git notes remove && git notes add -C $(cat blob)" && |
| 966 | commit=$(git rev-parse HEAD) && |
| 967 | cat >expect <<-EOF && |
| 968 | commit $commit |
| 969 | Author: A U Thor <author@example.com> |
| 970 | Date: Thu Apr 7 15:20:13 2005 -0700 |
| 971 | |
| 972 | ${indent}8th |
| 973 | |
| 974 | Notes: |
| 975 | ${indent}This is a blob object |
| 976 | ${indent}------- |
| 977 | ${indent}This is created by -m |
| 978 | ${indent}------- |
| 979 | ${indent}This is created by -F |
| 980 | EOF |
| 981 | |
| 982 | git notes remove && |
| 983 | echo "This is a blob object" | git hash-object -w --stdin >blob && |
| 984 | echo "This is created by -F" >note_a && |
| 985 | git notes add -C $(cat blob) -m "This is created by -m" -F note_a --separator="-------" && |
| 986 | git log -1 >actual && |
| 987 | test_cmp expect actual |
| 988 | ' |
| 989 | |
| 990 | test_expect_success 'create note from other note with "git notes add -c"' ' |
| 991 | test_commit 9th && |
| 992 | commit=$(git rev-parse HEAD) && |
| 993 | cat >expect <<-EOF && |
| 994 | commit $commit |
| 995 | Author: A U Thor <author@example.com> |
| 996 | Date: Thu Apr 7 15:21:13 2005 -0700 |
| 997 | |
| 998 | ${indent}9th |
| 999 | |
| 1000 | Notes: |
| 1001 | ${indent}yet another note |
| 1002 | EOF |
| 1003 | note=$(git notes list HEAD^^) && |
| 1004 | MSG="yet another note" git notes add -c $note && |
| 1005 | git log -1 >actual && |
| 1006 | test_cmp expect actual |
| 1007 | ' |
| 1008 | |
| 1009 | test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' |
| 1010 | test_commit 10th && |
| 1011 | test_must_fail env MSG="yet another note" git notes add -c deadbeef && |
| 1012 | test_must_fail git notes list HEAD |
| 1013 | ' |
| 1014 | |
| 1015 | test_expect_success 'append to note from other note with "git notes append -C"' ' |
| 1016 | commit=$(git rev-parse HEAD^) && |
| 1017 | cat >expect <<-EOF && |
| 1018 | commit $commit |
| 1019 | Author: A U Thor <author@example.com> |
| 1020 | Date: Thu Apr 7 15:21:13 2005 -0700 |
| 1021 | |
| 1022 | ${indent}9th |
| 1023 | |
| 1024 | Notes: |
| 1025 | ${indent}yet another note |
| 1026 | ${indent} |
| 1027 | ${indent}yet another note |
| 1028 | EOF |
| 1029 | note=$(git notes list HEAD^) && |
| 1030 | git notes append -C $note HEAD^ && |
| 1031 | git log -1 HEAD^ >actual && |
| 1032 | test_cmp expect actual |
| 1033 | ' |
| 1034 | |
| 1035 | test_expect_success 'create note from other note with "git notes append -c"' ' |
| 1036 | commit=$(git rev-parse HEAD) && |
| 1037 | cat >expect <<-EOF && |
| 1038 | commit $commit |
| 1039 | Author: A U Thor <author@example.com> |
| 1040 | Date: Thu Apr 7 15:22:13 2005 -0700 |
| 1041 | |
| 1042 | ${indent}10th |
| 1043 | |
| 1044 | Notes: |
| 1045 | ${indent}other note |
| 1046 | EOF |
| 1047 | note=$(git notes list HEAD^) && |
| 1048 | MSG="other note" git notes append -c $note && |
| 1049 | git log -1 >actual && |
| 1050 | test_cmp expect actual |
| 1051 | ' |
| 1052 | |
| 1053 | test_expect_success 'append to note from other note with "git notes append -c"' ' |
| 1054 | commit=$(git rev-parse HEAD) && |
| 1055 | cat >expect <<-EOF && |
| 1056 | commit $commit |
| 1057 | Author: A U Thor <author@example.com> |
| 1058 | Date: Thu Apr 7 15:22:13 2005 -0700 |
| 1059 | |
| 1060 | ${indent}10th |
| 1061 | |
| 1062 | Notes: |
| 1063 | ${indent}other note |
| 1064 | ${indent} |
| 1065 | ${indent}yet another note |
| 1066 | EOF |
| 1067 | note=$(git notes list HEAD) && |
| 1068 | MSG="yet another note" git notes append -c $note && |
| 1069 | git log -1 >actual && |
| 1070 | test_cmp expect actual |
| 1071 | ' |
| 1072 | |
| 1073 | test_expect_success 'copy note with "git notes copy"' ' |
| 1074 | commit=$(git rev-parse 4th) && |
| 1075 | cat >expect <<-EOF && |
| 1076 | commit $commit |
| 1077 | Author: A U Thor <author@example.com> |
| 1078 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 1079 | |
| 1080 | ${indent}4th |
| 1081 | |
| 1082 | Notes: |
| 1083 | ${indent}This is a blob object |
| 1084 | EOF |
| 1085 | git notes copy 8th 4th && |
| 1086 | git log 3rd..4th >actual && |
| 1087 | test_cmp expect actual && |
| 1088 | git notes list 4th >expect && |
| 1089 | git notes list 8th >actual && |
| 1090 | test_cmp expect actual |
| 1091 | ' |
| 1092 | |
| 1093 | test_expect_success 'copy note with "git notes copy" with default' ' |
| 1094 | test_commit 11th && |
| 1095 | commit=$(git rev-parse HEAD) && |
| 1096 | cat >expect <<-EOF && |
| 1097 | commit $commit |
| 1098 | Author: A U Thor <author@example.com> |
| 1099 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 1100 | |
| 1101 | ${indent}11th |
| 1102 | |
| 1103 | Notes: |
| 1104 | ${indent}other note |
| 1105 | ${indent} |
| 1106 | ${indent}yet another note |
| 1107 | EOF |
| 1108 | git notes copy HEAD^ && |
| 1109 | git log -1 >actual && |
| 1110 | test_cmp expect actual && |
| 1111 | git notes list HEAD^ >expect && |
| 1112 | git notes list HEAD >actual && |
| 1113 | test_cmp expect actual |
| 1114 | ' |
| 1115 | |
| 1116 | test_expect_success 'prevent overwrite with "git notes copy"' ' |
| 1117 | test_must_fail git notes copy HEAD~2 HEAD && |
| 1118 | cat >expect <<-EOF && |
| 1119 | commit $commit |
| 1120 | Author: A U Thor <author@example.com> |
| 1121 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 1122 | |
| 1123 | ${indent}11th |
| 1124 | |
| 1125 | Notes: |
| 1126 | ${indent}other note |
| 1127 | ${indent} |
| 1128 | ${indent}yet another note |
| 1129 | EOF |
| 1130 | git log -1 >actual && |
| 1131 | test_cmp expect actual && |
| 1132 | git notes list HEAD^ >expect && |
| 1133 | git notes list HEAD >actual && |
| 1134 | test_cmp expect actual |
| 1135 | ' |
| 1136 | |
| 1137 | test_expect_success 'allow overwrite with "git notes copy -f"' ' |
| 1138 | commit=$(git rev-parse HEAD) && |
| 1139 | cat >expect <<-EOF && |
| 1140 | commit $commit |
| 1141 | Author: A U Thor <author@example.com> |
| 1142 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 1143 | |
| 1144 | ${indent}11th |
| 1145 | |
| 1146 | Notes: |
| 1147 | ${indent}This is a blob object |
| 1148 | EOF |
| 1149 | git notes copy -f HEAD~3 HEAD && |
| 1150 | git log -1 >actual && |
| 1151 | test_cmp expect actual && |
| 1152 | git notes list HEAD~3 >expect && |
| 1153 | git notes list HEAD >actual && |
| 1154 | test_cmp expect actual |
| 1155 | ' |
| 1156 | |
| 1157 | test_expect_success 'allow overwrite with "git notes copy -f" with default' ' |
| 1158 | commit=$(git rev-parse HEAD) && |
| 1159 | cat >expect <<-EOF && |
| 1160 | commit $commit |
| 1161 | Author: A U Thor <author@example.com> |
| 1162 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 1163 | |
| 1164 | ${indent}11th |
| 1165 | |
| 1166 | Notes: |
| 1167 | ${indent}yet another note |
| 1168 | ${indent} |
| 1169 | ${indent}yet another note |
| 1170 | EOF |
| 1171 | git notes copy -f HEAD~2 && |
| 1172 | git log -1 >actual && |
| 1173 | test_cmp expect actual && |
| 1174 | git notes list HEAD~2 >expect && |
| 1175 | git notes list HEAD >actual && |
| 1176 | test_cmp expect actual |
| 1177 | ' |
| 1178 | |
| 1179 | test_expect_success 'cannot copy note from object without notes' ' |
| 1180 | test_commit 12th && |
| 1181 | test_commit 13th && |
| 1182 | test_must_fail git notes copy HEAD^ HEAD |
| 1183 | ' |
| 1184 | |
| 1185 | test_expect_success 'git notes copy --stdin' ' |
| 1186 | commit=$(git rev-parse HEAD) && |
| 1187 | parent=$(git rev-parse HEAD^) && |
| 1188 | cat >expect <<-EOF && |
| 1189 | commit $commit |
| 1190 | Author: A U Thor <author@example.com> |
| 1191 | Date: Thu Apr 7 15:25:13 2005 -0700 |
| 1192 | |
| 1193 | ${indent}13th |
| 1194 | |
| 1195 | Notes: |
| 1196 | ${indent}yet another note |
| 1197 | ${indent} |
| 1198 | ${indent}yet another note |
| 1199 | |
| 1200 | commit $parent |
| 1201 | Author: A U Thor <author@example.com> |
| 1202 | Date: Thu Apr 7 15:24:13 2005 -0700 |
| 1203 | |
| 1204 | ${indent}12th |
| 1205 | |
| 1206 | Notes: |
| 1207 | ${indent}other note |
| 1208 | ${indent} |
| 1209 | ${indent}yet another note |
| 1210 | EOF |
| 1211 | from=$(git rev-parse HEAD~3) && |
| 1212 | to=$(git rev-parse HEAD^) && |
| 1213 | echo "$from" "$to" >copy && |
| 1214 | from=$(git rev-parse HEAD~2) && |
| 1215 | to=$(git rev-parse HEAD) && |
| 1216 | echo "$from" "$to" >>copy && |
| 1217 | git notes copy --stdin <copy && |
| 1218 | git log -2 >actual && |
| 1219 | test_cmp expect actual && |
| 1220 | git notes list HEAD~2 >expect && |
| 1221 | git notes list HEAD >actual && |
| 1222 | test_cmp expect actual && |
| 1223 | git notes list HEAD~3 >expect && |
| 1224 | git notes list HEAD^ >actual && |
| 1225 | test_cmp expect actual |
| 1226 | ' |
| 1227 | |
| 1228 | test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' |
| 1229 | test_commit 14th && |
| 1230 | test_commit 15th && |
| 1231 | commit=$(git rev-parse HEAD) && |
| 1232 | parent=$(git rev-parse HEAD^) && |
| 1233 | cat >expect <<-EOF && |
| 1234 | commit $commit |
| 1235 | Author: A U Thor <author@example.com> |
| 1236 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1237 | |
| 1238 | ${indent}15th |
| 1239 | |
| 1240 | commit $parent |
| 1241 | Author: A U Thor <author@example.com> |
| 1242 | Date: Thu Apr 7 15:26:13 2005 -0700 |
| 1243 | |
| 1244 | ${indent}14th |
| 1245 | EOF |
| 1246 | from=$(git rev-parse HEAD~3) && |
| 1247 | to=$(git rev-parse HEAD^) && |
| 1248 | echo "$from" "$to" >copy && |
| 1249 | from=$(git rev-parse HEAD~2) && |
| 1250 | to=$(git rev-parse HEAD) && |
| 1251 | echo "$from" "$to" >>copy && |
| 1252 | git notes copy --for-rewrite=foo <copy && |
| 1253 | git log -2 >actual && |
| 1254 | test_cmp expect actual |
| 1255 | ' |
| 1256 | |
| 1257 | test_expect_success 'git notes copy --for-rewrite (enabled)' ' |
| 1258 | commit=$(git rev-parse HEAD) && |
| 1259 | parent=$(git rev-parse HEAD^) && |
| 1260 | cat >expect <<-EOF && |
| 1261 | commit $commit |
| 1262 | Author: A U Thor <author@example.com> |
| 1263 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1264 | |
| 1265 | ${indent}15th |
| 1266 | |
| 1267 | Notes: |
| 1268 | ${indent}yet another note |
| 1269 | ${indent} |
| 1270 | ${indent}yet another note |
| 1271 | |
| 1272 | commit $parent |
| 1273 | Author: A U Thor <author@example.com> |
| 1274 | Date: Thu Apr 7 15:26:13 2005 -0700 |
| 1275 | |
| 1276 | ${indent}14th |
| 1277 | |
| 1278 | Notes: |
| 1279 | ${indent}other note |
| 1280 | ${indent} |
| 1281 | ${indent}yet another note |
| 1282 | EOF |
| 1283 | test_config notes.rewriteMode overwrite && |
| 1284 | test_config notes.rewriteRef "refs/notes/*" && |
| 1285 | from=$(git rev-parse HEAD~3) && |
| 1286 | to=$(git rev-parse HEAD^) && |
| 1287 | echo "$from" "$to" >copy && |
| 1288 | from=$(git rev-parse HEAD~2) && |
| 1289 | to=$(git rev-parse HEAD) && |
| 1290 | echo "$from" "$to" >>copy && |
| 1291 | git notes copy --for-rewrite=foo <copy && |
| 1292 | git log -2 >actual && |
| 1293 | test_cmp expect actual |
| 1294 | ' |
| 1295 | |
| 1296 | test_expect_success 'git notes copy --for-rewrite (disabled)' ' |
| 1297 | test_config notes.rewrite.bar false && |
| 1298 | from=$(git rev-parse HEAD~3) && |
| 1299 | to=$(git rev-parse HEAD) && |
| 1300 | echo "$from" "$to" >copy && |
| 1301 | git notes copy --for-rewrite=bar <copy && |
| 1302 | git log -2 >actual && |
| 1303 | test_cmp expect actual |
| 1304 | ' |
| 1305 | |
| 1306 | test_expect_success 'git notes copy --for-rewrite (overwrite)' ' |
| 1307 | commit=$(git rev-parse HEAD) && |
| 1308 | cat >expect <<-EOF && |
| 1309 | commit $commit |
| 1310 | Author: A U Thor <author@example.com> |
| 1311 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1312 | |
| 1313 | ${indent}15th |
| 1314 | |
| 1315 | Notes: |
| 1316 | ${indent}a fresh note |
| 1317 | EOF |
| 1318 | git notes add -f -m"a fresh note" HEAD^ && |
| 1319 | test_config notes.rewriteMode overwrite && |
| 1320 | test_config notes.rewriteRef "refs/notes/*" && |
| 1321 | from=$(git rev-parse HEAD^) && |
| 1322 | to=$(git rev-parse HEAD) && |
| 1323 | echo "$from" "$to" >copy && |
| 1324 | git notes copy --for-rewrite=foo <copy && |
| 1325 | git log -1 >actual && |
| 1326 | test_cmp expect actual |
| 1327 | ' |
| 1328 | |
| 1329 | test_expect_success 'git notes copy --for-rewrite (ignore)' ' |
| 1330 | test_config notes.rewriteMode ignore && |
| 1331 | test_config notes.rewriteRef "refs/notes/*" && |
| 1332 | from=$(git rev-parse HEAD^) && |
| 1333 | to=$(git rev-parse HEAD) && |
| 1334 | echo "$from" "$to" >copy && |
| 1335 | git notes copy --for-rewrite=foo <copy && |
| 1336 | git log -1 >actual && |
| 1337 | test_cmp expect actual |
| 1338 | ' |
| 1339 | |
| 1340 | test_expect_success 'git notes copy --for-rewrite (append)' ' |
| 1341 | commit=$(git rev-parse HEAD) && |
| 1342 | cat >expect <<-EOF && |
| 1343 | commit $commit |
| 1344 | Author: A U Thor <author@example.com> |
| 1345 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1346 | |
| 1347 | ${indent}15th |
| 1348 | |
| 1349 | Notes: |
| 1350 | ${indent}a fresh note |
| 1351 | ${indent} |
| 1352 | ${indent}another fresh note |
| 1353 | EOF |
| 1354 | git notes add -f -m"another fresh note" HEAD^ && |
| 1355 | test_config notes.rewriteMode concatenate && |
| 1356 | test_config notes.rewriteRef "refs/notes/*" && |
| 1357 | from=$(git rev-parse HEAD^) && |
| 1358 | to=$(git rev-parse HEAD) && |
| 1359 | echo "$from" "$to" >copy && |
| 1360 | git notes copy --for-rewrite=foo <copy && |
| 1361 | git log -1 >actual && |
| 1362 | test_cmp expect actual |
| 1363 | ' |
| 1364 | |
| 1365 | test_expect_success 'git notes copy --for-rewrite (append two to one)' ' |
| 1366 | commit=$(git rev-parse HEAD) && |
| 1367 | cat >expect <<-EOF && |
| 1368 | commit $commit |
| 1369 | Author: A U Thor <author@example.com> |
| 1370 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1371 | |
| 1372 | ${indent}15th |
| 1373 | |
| 1374 | Notes: |
| 1375 | ${indent}a fresh note |
| 1376 | ${indent} |
| 1377 | ${indent}another fresh note |
| 1378 | ${indent} |
| 1379 | ${indent}append 1 |
| 1380 | ${indent} |
| 1381 | ${indent}append 2 |
| 1382 | EOF |
| 1383 | git notes add -f -m"append 1" HEAD^ && |
| 1384 | git notes add -f -m"append 2" HEAD^^ && |
| 1385 | test_config notes.rewriteMode concatenate && |
| 1386 | test_config notes.rewriteRef "refs/notes/*" && |
| 1387 | from=$(git rev-parse HEAD^) && |
| 1388 | to=$(git rev-parse HEAD) && |
| 1389 | echo "$from" "$to" >copy && |
| 1390 | from=$(git rev-parse HEAD^^) && |
| 1391 | to=$(git rev-parse HEAD) && |
| 1392 | echo "$from" "$to" >>copy && |
| 1393 | git notes copy --for-rewrite=foo <copy && |
| 1394 | git log -1 >actual && |
| 1395 | test_cmp expect actual |
| 1396 | ' |
| 1397 | |
| 1398 | test_expect_success 'git notes copy --for-rewrite (append empty)' ' |
| 1399 | git notes remove HEAD^ && |
| 1400 | test_config notes.rewriteMode concatenate && |
| 1401 | test_config notes.rewriteRef "refs/notes/*" && |
| 1402 | from=$(git rev-parse HEAD^) && |
| 1403 | to=$(git rev-parse HEAD) && |
| 1404 | echo "$from" "$to" >copy && |
| 1405 | git notes copy --for-rewrite=foo <copy && |
| 1406 | git log -1 >actual && |
| 1407 | test_cmp expect actual |
| 1408 | ' |
| 1409 | |
| 1410 | test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' |
| 1411 | commit=$(git rev-parse HEAD) && |
| 1412 | cat >expect <<-EOF && |
| 1413 | commit $commit |
| 1414 | Author: A U Thor <author@example.com> |
| 1415 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1416 | |
| 1417 | ${indent}15th |
| 1418 | |
| 1419 | Notes: |
| 1420 | ${indent}replacement note 1 |
| 1421 | EOF |
| 1422 | test_config notes.rewriteMode concatenate && |
| 1423 | test_config notes.rewriteRef "refs/notes/*" && |
| 1424 | git notes add -f -m"replacement note 1" HEAD^ && |
| 1425 | from=$(git rev-parse HEAD^) && |
| 1426 | to=$(git rev-parse HEAD) && |
| 1427 | echo "$from" "$to" >copy && |
| 1428 | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && |
| 1429 | git log -1 >actual && |
| 1430 | test_cmp expect actual |
| 1431 | ' |
| 1432 | |
| 1433 | test_expect_success 'GIT_NOTES_REWRITE_REF works' ' |
| 1434 | commit=$(git rev-parse HEAD) && |
| 1435 | cat >expect <<-EOF && |
| 1436 | commit $commit |
| 1437 | Author: A U Thor <author@example.com> |
| 1438 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1439 | |
| 1440 | ${indent}15th |
| 1441 | |
| 1442 | Notes: |
| 1443 | ${indent}replacement note 2 |
| 1444 | EOF |
| 1445 | git notes add -f -m"replacement note 2" HEAD^ && |
| 1446 | test_config notes.rewriteMode overwrite && |
| 1447 | test_unconfig notes.rewriteRef && |
| 1448 | from=$(git rev-parse HEAD^) && |
| 1449 | to=$(git rev-parse HEAD) && |
| 1450 | echo "$from" "$to" >copy && |
| 1451 | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ |
| 1452 | git notes copy --for-rewrite=foo <copy && |
| 1453 | git log -1 >actual && |
| 1454 | test_cmp expect actual |
| 1455 | ' |
| 1456 | |
| 1457 | test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' |
| 1458 | git notes add -f -m"replacement note 3" HEAD^ && |
| 1459 | test_config notes.rewriteMode overwrite && |
| 1460 | test_config notes.rewriteRef refs/notes/other && |
| 1461 | from=$(git rev-parse HEAD^) && |
| 1462 | to=$(git rev-parse HEAD) && |
| 1463 | echo "$from" "$to" >copy && |
| 1464 | GIT_NOTES_REWRITE_REF=refs/notes/commits \ |
| 1465 | git notes copy --for-rewrite=foo <copy && |
| 1466 | git log -1 >actual && |
| 1467 | test_grep "replacement note 3" actual |
| 1468 | ' |
| 1469 | |
| 1470 | test_expect_success 'git notes copy diagnoses too many or too few arguments' ' |
| 1471 | test_must_fail git notes copy 2>error && |
| 1472 | test_grep "too few arguments" error && |
| 1473 | test_must_fail git notes copy one two three 2>error && |
| 1474 | test_grep "too many arguments" error |
| 1475 | ' |
| 1476 | |
| 1477 | test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' ' |
| 1478 | test_unconfig core.notesRef && |
| 1479 | sane_unset GIT_NOTES_REF && |
| 1480 | echo refs/notes/refs/heads/main >expect && |
| 1481 | git notes --ref=refs/heads/main get-ref >actual && |
| 1482 | test_cmp expect actual |
| 1483 | ' |
| 1484 | |
| 1485 | test_expect_success 'git notes get-ref (no overrides)' ' |
| 1486 | test_unconfig core.notesRef && |
| 1487 | sane_unset GIT_NOTES_REF && |
| 1488 | echo refs/notes/commits >expect && |
| 1489 | git notes get-ref >actual && |
| 1490 | test_cmp expect actual |
| 1491 | ' |
| 1492 | |
| 1493 | test_expect_success 'git notes get-ref (core.notesRef)' ' |
| 1494 | test_config core.notesRef refs/notes/foo && |
| 1495 | echo refs/notes/foo >expect && |
| 1496 | git notes get-ref >actual && |
| 1497 | test_cmp expect actual |
| 1498 | ' |
| 1499 | |
| 1500 | test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' |
| 1501 | echo refs/notes/bar >expect && |
| 1502 | GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && |
| 1503 | test_cmp expect actual |
| 1504 | ' |
| 1505 | |
| 1506 | test_expect_success 'git notes get-ref (--ref)' ' |
| 1507 | echo refs/notes/baz >expect && |
| 1508 | GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && |
| 1509 | test_cmp expect actual |
| 1510 | ' |
| 1511 | |
| 1512 | test_expect_success 'setup testing of empty notes' ' |
| 1513 | test_unconfig core.notesRef && |
| 1514 | test_commit 16th && |
| 1515 | empty_blob=$(git hash-object -w /dev/null) && |
| 1516 | echo "$empty_blob" >expect_empty |
| 1517 | ' |
| 1518 | |
| 1519 | while read cmd |
| 1520 | do |
| 1521 | test_expect_success "'git notes $cmd' removes empty note" " |
| 1522 | test_might_fail git notes remove HEAD && |
| 1523 | MSG= git notes $cmd && |
| 1524 | test_must_fail git notes list HEAD |
| 1525 | " |
| 1526 | |
| 1527 | test_expect_success "'git notes $cmd --allow-empty' stores empty note" " |
| 1528 | test_might_fail git notes remove HEAD && |
| 1529 | MSG= git notes $cmd --allow-empty && |
| 1530 | git notes list HEAD >actual && |
| 1531 | test_cmp expect_empty actual |
| 1532 | " |
| 1533 | done <<\EOF |
| 1534 | add |
| 1535 | add -F /dev/null |
| 1536 | add -m "" |
| 1537 | add -c "$empty_blob" |
| 1538 | add -C "$empty_blob" |
| 1539 | append |
| 1540 | append -F /dev/null |
| 1541 | append -m "" |
| 1542 | append -c "$empty_blob" |
| 1543 | append -C "$empty_blob" |
| 1544 | edit |
| 1545 | EOF |
| 1546 | |
| 1547 | test_expect_success 'empty notes are displayed by git log' ' |
| 1548 | test_commit 17th && |
| 1549 | git log -1 >expect && |
| 1550 | cat >>expect <<-EOF && |
| 1551 | |
| 1552 | Notes: |
| 1553 | EOF |
| 1554 | git notes add -C "$empty_blob" --allow-empty && |
| 1555 | git log -1 >actual && |
| 1556 | test_cmp expect actual |
| 1557 | ' |
| 1558 | |
| 1559 | test_expect_success 'empty notes do not invoke the editor' ' |
| 1560 | test_commit 18th && |
| 1561 | GIT_EDITOR="false" git notes add -C "$empty_blob" --allow-empty && |
| 1562 | git notes remove HEAD && |
| 1563 | GIT_EDITOR="false" git notes add -m "" --allow-empty && |
| 1564 | git notes remove HEAD && |
| 1565 | GIT_EDITOR="false" git notes add -F /dev/null --allow-empty && |
| 1566 | git notes remove HEAD |
| 1567 | ' |
| 1568 | |
| 1569 | test_expect_success 'git notes add with -m/-F invokes editor with -e' ' |
| 1570 | test_commit 19th && |
| 1571 | echo "edited" >expect && |
| 1572 | MSG="$(cat expect)" git notes add -m "initial" -e && |
| 1573 | git notes show >actual && |
| 1574 | test_cmp expect actual && |
| 1575 | git notes remove HEAD && |
| 1576 | |
| 1577 | # Add a note using -F and edit it |
| 1578 | echo "initial" >note_file && |
| 1579 | MSG="$(cat expect)" git notes add -F note_file -e && |
| 1580 | git notes show >actual && |
| 1581 | test_cmp expect actual |
| 1582 | ' |
| 1583 | |
| 1584 | test_expect_success 'git notes append with -m/-F invokes the editor with -e' ' |
| 1585 | test_commit 20th && |
| 1586 | cat >expect <<-EOF && |
| 1587 | initial |
| 1588 | |
| 1589 | edited |
| 1590 | EOF |
| 1591 | git notes add -m "initial" && |
| 1592 | MSG="edited" git notes append -m "appended" -e && |
| 1593 | |
| 1594 | # Verify the note content was appended and edited |
| 1595 | git notes show >actual && |
| 1596 | test_cmp expect actual && |
| 1597 | git notes remove HEAD && |
| 1598 | |
| 1599 | # Append a note using -F and edit it |
| 1600 | echo "note from file" >note_file && |
| 1601 | git notes add -m "initial" && |
| 1602 | MSG="edited" git notes append -F note_file -e && |
| 1603 | |
| 1604 | # Verify notes from file has been edited in editor and appended |
| 1605 | git notes show >actual && |
| 1606 | test_cmp expect actual |
| 1607 | ' |
| 1608 | |
| 1609 | test_expect_success 'git notes with a combination of -m, -F and -e invokes editor' ' |
| 1610 | test_commit 21st && |
| 1611 | echo "foo-file-1" >note_1 && |
| 1612 | echo "foo-file-2" >note_2 && |
| 1613 | echo "edited" >expect && |
| 1614 | |
| 1615 | MSG=$(cat expect) git notes append -F note_1 -m "message-1" -F note_2 -e && |
| 1616 | |
| 1617 | # Verify that combined messages from file and -m have been edited |
| 1618 | git notes show >actual && |
| 1619 | test_cmp expect actual |
| 1620 | ' |
| 1621 | test_expect_success 'git notes append aborts when editor fails with -e' ' |
| 1622 | test_commit 22nd && |
| 1623 | echo "foo-file-1" >note_1 && |
| 1624 | |
| 1625 | # Try to append a note with -F and -e, but make the editor fail |
| 1626 | test_env GIT_EDITOR="false" test_must_fail git notes append -F note_1 -e && |
| 1627 | |
| 1628 | # Verify that no note was added due to editor failure |
| 1629 | test_must_fail git notes show |
| 1630 | ' |
| 1631 | |
| 1632 | test_done |