t / t3301-notes.shon commit test-lib: use subshell instead of cd $new && .. && cd $old (0d314ce)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='Test commit notes'
   7
   8. ./test-lib.sh
   9
  10cat > fake_editor.sh << \EOF
  11#!/bin/sh
  12echo "$MSG" > "$1"
  13echo "$MSG" >& 2
  14EOF
  15chmod a+x fake_editor.sh
  16GIT_EDITOR=./fake_editor.sh
  17export GIT_EDITOR
  18
  19test_expect_success 'cannot annotate non-existing HEAD' '
  20        (MSG=3 && export MSG && test_must_fail git notes add)
  21'
  22
  23test_expect_success setup '
  24        : > a1 &&
  25        git add a1 &&
  26        test_tick &&
  27        git commit -m 1st &&
  28        : > a2 &&
  29        git add a2 &&
  30        test_tick &&
  31        git commit -m 2nd
  32'
  33
  34test_expect_success 'need valid notes ref' '
  35        (MSG=1 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
  36         test_must_fail git notes add) &&
  37        (MSG=2 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
  38         test_must_fail git notes show)
  39'
  40
  41test_expect_success 'refusing to add notes in refs/heads/' '
  42        (MSG=1 GIT_NOTES_REF=refs/heads/bogus &&
  43         export MSG GIT_NOTES_REF &&
  44         test_must_fail git notes add)
  45'
  46
  47test_expect_success 'refusing to edit notes in refs/remotes/' '
  48        (MSG=1 GIT_NOTES_REF=refs/remotes/bogus &&
  49         export MSG GIT_NOTES_REF &&
  50         test_must_fail git notes edit)
  51'
  52
  53# 1 indicates caught gracefully by die, 128 means git-show barked
  54test_expect_success 'handle empty notes gracefully' '
  55        git notes show ; test 1 = $?
  56'
  57
  58test_expect_success 'show non-existent notes entry with %N' '
  59        for l in A B
  60        do
  61                echo "$l"
  62        done >expect &&
  63        git show -s --format='A%n%NB' >output &&
  64        test_cmp expect output
  65'
  66
  67test_expect_success 'create notes' '
  68        git config core.notesRef refs/notes/commits &&
  69        MSG=b4 git notes add &&
  70        test ! -f .git/NOTES_EDITMSG &&
  71        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
  72        test b4 = $(git notes show) &&
  73        git show HEAD^ &&
  74        test_must_fail git notes show HEAD^
  75'
  76
  77test_expect_success 'show notes entry with %N' '
  78        for l in A b4 B
  79        do
  80                echo "$l"
  81        done >expect &&
  82        git show -s --format='A%n%NB' >output &&
  83        test_cmp expect output
  84'
  85
  86cat >expect <<EOF
  87d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
  88EOF
  89
  90test_expect_success 'create reflog entry' '
  91        git reflog show refs/notes/commits >output &&
  92        test_cmp expect output
  93'
  94
  95test_expect_success 'edit existing notes' '
  96        MSG=b3 git notes edit &&
  97        test ! -f .git/NOTES_EDITMSG &&
  98        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
  99        test b3 = $(git notes show) &&
 100        git show HEAD^ &&
 101        test_must_fail git notes show HEAD^
 102'
 103
 104test_expect_success 'cannot add note where one exists' '
 105        ! MSG=b2 git notes add &&
 106        test ! -f .git/NOTES_EDITMSG &&
 107        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
 108        test b3 = $(git notes show) &&
 109        git show HEAD^ &&
 110        test_must_fail git notes show HEAD^
 111'
 112
 113test_expect_success 'can overwrite existing note with "git notes add -f"' '
 114        MSG=b1 git notes add -f &&
 115        test ! -f .git/NOTES_EDITMSG &&
 116        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
 117        test b1 = $(git notes show) &&
 118        git show HEAD^ &&
 119        test_must_fail git notes show HEAD^
 120'
 121
 122cat > expect << EOF
 123commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
 124Author: A U Thor <author@example.com>
 125Date:   Thu Apr 7 15:14:13 2005 -0700
 126
 127    2nd
 128
 129Notes:
 130    b1
 131EOF
 132
 133test_expect_success 'show notes' '
 134        ! (git cat-file commit HEAD | grep b1) &&
 135        git log -1 > output &&
 136        test_cmp expect output
 137'
 138
 139test_expect_success 'create multi-line notes (setup)' '
 140        : > a3 &&
 141        git add a3 &&
 142        test_tick &&
 143        git commit -m 3rd &&
 144        MSG="b3
 145c3c3c3c3
 146d3d3d3" git notes add
 147'
 148
 149cat > expect-multiline << EOF
 150commit 1584215f1d29c65e99c6c6848626553fdd07fd75
 151Author: A U Thor <author@example.com>
 152Date:   Thu Apr 7 15:15:13 2005 -0700
 153
 154    3rd
 155
 156Notes:
 157    b3
 158    c3c3c3c3
 159    d3d3d3
 160EOF
 161
 162printf "\n" >> expect-multiline
 163cat expect >> expect-multiline
 164
 165test_expect_success 'show multi-line notes' '
 166        git log -2 > output &&
 167        test_cmp expect-multiline output
 168'
 169test_expect_success 'create -F notes (setup)' '
 170        : > a4 &&
 171        git add a4 &&
 172        test_tick &&
 173        git commit -m 4th &&
 174        echo "xyzzy" > note5 &&
 175        git notes add -F note5
 176'
 177
 178cat > expect-F << EOF
 179commit 15023535574ded8b1a89052b32673f84cf9582b8
 180Author: A U Thor <author@example.com>
 181Date:   Thu Apr 7 15:16:13 2005 -0700
 182
 183    4th
 184
 185Notes:
 186    xyzzy
 187EOF
 188
 189printf "\n" >> expect-F
 190cat expect-multiline >> expect-F
 191
 192test_expect_success 'show -F notes' '
 193        git log -3 > output &&
 194        test_cmp expect-F output
 195'
 196
 197cat >expect << EOF
 198commit 15023535574ded8b1a89052b32673f84cf9582b8
 199tree e070e3af51011e47b183c33adf9736736a525709
 200parent 1584215f1d29c65e99c6c6848626553fdd07fd75
 201author A U Thor <author@example.com> 1112912173 -0700
 202committer C O Mitter <committer@example.com> 1112912173 -0700
 203
 204    4th
 205EOF
 206test_expect_success 'git log --pretty=raw does not show notes' '
 207        git log -1 --pretty=raw >output &&
 208        test_cmp expect output
 209'
 210
 211cat >>expect <<EOF
 212
 213Notes:
 214    xyzzy
 215EOF
 216test_expect_success 'git log --show-notes' '
 217        git log -1 --pretty=raw --show-notes >output &&
 218        test_cmp expect output
 219'
 220
 221test_expect_success 'git log --no-notes' '
 222        git log -1 --no-notes >output &&
 223        ! grep xyzzy output
 224'
 225
 226test_expect_success 'git format-patch does not show notes' '
 227        git format-patch -1 --stdout >output &&
 228        ! grep xyzzy output
 229'
 230
 231test_expect_success 'git format-patch --show-notes does show notes' '
 232        git format-patch --show-notes -1 --stdout >output &&
 233        grep xyzzy output
 234'
 235
 236for pretty in \
 237        "" --pretty --pretty=raw --pretty=short --pretty=medium \
 238        --pretty=full --pretty=fuller --pretty=format:%s --oneline
 239do
 240        case "$pretty" in
 241        "") p= not= negate="" ;;
 242        ?*) p="$pretty" not=" not" negate="!" ;;
 243        esac
 244        test_expect_success "git show $pretty does$not show notes" '
 245                git show $p >output &&
 246                eval "$negate grep xyzzy output"
 247        '
 248done
 249
 250test_expect_success 'create -m notes (setup)' '
 251        : > a5 &&
 252        git add a5 &&
 253        test_tick &&
 254        git commit -m 5th &&
 255        git notes add -m spam -m "foo
 256bar
 257baz"
 258'
 259
 260whitespace="    "
 261cat > expect-m << EOF
 262commit bd1753200303d0a0344be813e504253b3d98e74d
 263Author: A U Thor <author@example.com>
 264Date:   Thu Apr 7 15:17:13 2005 -0700
 265
 266    5th
 267
 268Notes:
 269    spam
 270$whitespace
 271    foo
 272    bar
 273    baz
 274EOF
 275
 276printf "\n" >> expect-m
 277cat expect-F >> expect-m
 278
 279test_expect_success 'show -m notes' '
 280        git log -4 > output &&
 281        test_cmp expect-m output
 282'
 283
 284test_expect_success 'remove note with add -f -F /dev/null (setup)' '
 285        git notes add -f -F /dev/null
 286'
 287
 288cat > expect-rm-F << EOF
 289commit bd1753200303d0a0344be813e504253b3d98e74d
 290Author: A U Thor <author@example.com>
 291Date:   Thu Apr 7 15:17:13 2005 -0700
 292
 293    5th
 294EOF
 295
 296printf "\n" >> expect-rm-F
 297cat expect-F >> expect-rm-F
 298
 299test_expect_success 'verify note removal with -F /dev/null' '
 300        git log -4 > output &&
 301        test_cmp expect-rm-F output &&
 302        ! git notes show
 303'
 304
 305test_expect_success 'do not create empty note with -m "" (setup)' '
 306        git notes add -m ""
 307'
 308
 309test_expect_success 'verify non-creation of note with -m ""' '
 310        git log -4 > output &&
 311        test_cmp expect-rm-F output &&
 312        ! git notes show
 313'
 314
 315cat > expect-combine_m_and_F << EOF
 316foo
 317
 318xyzzy
 319
 320bar
 321
 322zyxxy
 323
 324baz
 325EOF
 326
 327test_expect_success 'create note with combination of -m and -F' '
 328        echo "xyzzy" > note_a &&
 329        echo "zyxxy" > note_b &&
 330        git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
 331        git notes show > output &&
 332        test_cmp expect-combine_m_and_F output
 333'
 334
 335test_expect_success 'remove note with "git notes remove" (setup)' '
 336        git notes remove HEAD^ &&
 337        git notes remove
 338'
 339
 340cat > expect-rm-remove << EOF
 341commit bd1753200303d0a0344be813e504253b3d98e74d
 342Author: A U Thor <author@example.com>
 343Date:   Thu Apr 7 15:17:13 2005 -0700
 344
 345    5th
 346
 347commit 15023535574ded8b1a89052b32673f84cf9582b8
 348Author: A U Thor <author@example.com>
 349Date:   Thu Apr 7 15:16:13 2005 -0700
 350
 351    4th
 352EOF
 353
 354printf "\n" >> expect-rm-remove
 355cat expect-multiline >> expect-rm-remove
 356
 357test_expect_success 'verify note removal with "git notes remove"' '
 358        git log -4 > output &&
 359        test_cmp expect-rm-remove output &&
 360        ! git notes show HEAD^
 361'
 362
 363cat > expect << EOF
 364c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
 365c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
 366EOF
 367
 368test_expect_success 'list notes with "git notes list"' '
 369        git notes list > output &&
 370        test_cmp expect output
 371'
 372
 373test_expect_success 'list notes with "git notes"' '
 374        git notes > output &&
 375        test_cmp expect output
 376'
 377
 378cat > expect << EOF
 379c18dc024e14f08d18d14eea0d747ff692d66d6a3
 380EOF
 381
 382test_expect_success 'list specific note with "git notes list <object>"' '
 383        git notes list HEAD^^ > output &&
 384        test_cmp expect output
 385'
 386
 387cat > expect << EOF
 388EOF
 389
 390test_expect_success 'listing non-existing notes fails' '
 391        test_must_fail git notes list HEAD > output &&
 392        test_cmp expect output
 393'
 394
 395cat > expect << EOF
 396Initial set of notes
 397
 398More notes appended with git notes append
 399EOF
 400
 401test_expect_success 'append to existing note with "git notes append"' '
 402        git notes add -m "Initial set of notes" &&
 403        git notes append -m "More notes appended with git notes append" &&
 404        git notes show > output &&
 405        test_cmp expect output
 406'
 407
 408cat > expect_list << EOF
 409c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
 410c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
 4114b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
 412EOF
 413
 414test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
 415        git notes list > output &&
 416        test_cmp expect_list output
 417'
 418
 419test_expect_success 'appending empty string does not change existing note' '
 420        git notes append -m "" &&
 421        git notes show > output &&
 422        test_cmp expect output
 423'
 424
 425test_expect_success 'git notes append == add when there is no existing note' '
 426        git notes remove HEAD &&
 427        test_must_fail git notes list HEAD &&
 428        git notes append -m "Initial set of notes
 429
 430More notes appended with git notes append" &&
 431        git notes show > output &&
 432        test_cmp expect output
 433'
 434
 435test_expect_success 'appending empty string to non-existing note does not create note' '
 436        git notes remove HEAD &&
 437        test_must_fail git notes list HEAD &&
 438        git notes append -m "" &&
 439        test_must_fail git notes list HEAD
 440'
 441
 442test_expect_success 'create other note on a different notes ref (setup)' '
 443        : > a6 &&
 444        git add a6 &&
 445        test_tick &&
 446        git commit -m 6th &&
 447        GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
 448'
 449
 450cat > expect-other << EOF
 451commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 452Author: A U Thor <author@example.com>
 453Date:   Thu Apr 7 15:18:13 2005 -0700
 454
 455    6th
 456
 457Notes (other):
 458    other note
 459EOF
 460
 461cat > expect-not-other << EOF
 462commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 463Author: A U Thor <author@example.com>
 464Date:   Thu Apr 7 15:18:13 2005 -0700
 465
 466    6th
 467EOF
 468
 469test_expect_success 'Do not show note on other ref by default' '
 470        git log -1 > output &&
 471        test_cmp expect-not-other output
 472'
 473
 474test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
 475        GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
 476        test_cmp expect-other output
 477'
 478
 479test_expect_success 'Do show note when ref is given in core.notesRef config' '
 480        git config core.notesRef "refs/notes/other" &&
 481        git log -1 > output &&
 482        test_cmp expect-other output
 483'
 484
 485test_expect_success 'Do not show note when core.notesRef is overridden' '
 486        GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
 487        test_cmp expect-not-other output
 488'
 489
 490cat > expect-both << EOF
 491commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 492Author: A U Thor <author@example.com>
 493Date:   Thu Apr 7 15:18:13 2005 -0700
 494
 495    6th
 496
 497Notes:
 498    order test
 499
 500Notes (other):
 501    other note
 502
 503commit bd1753200303d0a0344be813e504253b3d98e74d
 504Author: A U Thor <author@example.com>
 505Date:   Thu Apr 7 15:17:13 2005 -0700
 506
 507    5th
 508
 509Notes:
 510    replacement for deleted note
 511EOF
 512
 513test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
 514        GIT_NOTES_REF=refs/notes/commits git notes add \
 515                -m"replacement for deleted note" HEAD^ &&
 516        GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
 517        git config --unset core.notesRef &&
 518        git config notes.displayRef "refs/notes/*" &&
 519        git log -2 > output &&
 520        test_cmp expect-both output
 521'
 522
 523test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
 524        git config core.notesRef refs/notes/commits &&
 525        git config notes.displayRef refs/notes/other &&
 526        git log -2 > output &&
 527        test_cmp expect-both output
 528'
 529
 530test_expect_success 'notes.displayRef can be given more than once' '
 531        git config --unset core.notesRef &&
 532        git config notes.displayRef refs/notes/commits &&
 533        git config --add notes.displayRef refs/notes/other &&
 534        git log -2 > output &&
 535        test_cmp expect-both output
 536'
 537
 538cat > expect-both-reversed << EOF
 539commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 540Author: A U Thor <author@example.com>
 541Date:   Thu Apr 7 15:18:13 2005 -0700
 542
 543    6th
 544
 545Notes (other):
 546    other note
 547
 548Notes:
 549    order test
 550EOF
 551
 552test_expect_success 'notes.displayRef respects order' '
 553        git config core.notesRef refs/notes/other &&
 554        git config --unset-all notes.displayRef &&
 555        git config notes.displayRef refs/notes/commits &&
 556        git log -1 > output &&
 557        test_cmp expect-both-reversed output
 558'
 559
 560test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
 561        git config --unset-all core.notesRef &&
 562        git config --unset-all notes.displayRef &&
 563        GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
 564                git log -2 > output &&
 565        test_cmp expect-both output
 566'
 567
 568cat > expect-none << EOF
 569commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 570Author: A U Thor <author@example.com>
 571Date:   Thu Apr 7 15:18:13 2005 -0700
 572
 573    6th
 574
 575commit bd1753200303d0a0344be813e504253b3d98e74d
 576Author: A U Thor <author@example.com>
 577Date:   Thu Apr 7 15:17:13 2005 -0700
 578
 579    5th
 580EOF
 581
 582test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
 583        git config notes.displayRef "refs/notes/*" &&
 584        GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output &&
 585        test_cmp expect-none output
 586'
 587
 588test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
 589        GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output &&
 590        test_cmp expect-both output
 591'
 592
 593cat > expect-commits << EOF
 594commit 387a89921c73d7ed72cd94d179c1c7048ca47756
 595Author: A U Thor <author@example.com>
 596Date:   Thu Apr 7 15:18:13 2005 -0700
 597
 598    6th
 599
 600Notes:
 601    order test
 602EOF
 603
 604test_expect_success '--no-standard-notes' '
 605        git log --no-standard-notes --show-notes=commits -1 > output &&
 606        test_cmp expect-commits output
 607'
 608
 609test_expect_success '--standard-notes' '
 610        git log --no-standard-notes --show-notes=commits \
 611                --standard-notes -2 > output &&
 612        test_cmp expect-both output
 613'
 614
 615test_expect_success '--show-notes=ref accumulates' '
 616        git log --show-notes=other --show-notes=commits \
 617                 --no-standard-notes -1 > output &&
 618        test_cmp expect-both-reversed output
 619'
 620
 621test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
 622        git config core.notesRef refs/notes/other &&
 623        echo "Note on a tree" > expect
 624        git notes add -m "Note on a tree" HEAD: &&
 625        git notes show HEAD: > actual &&
 626        test_cmp expect actual &&
 627        echo "Note on a blob" > expect
 628        filename=$(git ls-tree --name-only HEAD | head -n1) &&
 629        git notes add -m "Note on a blob" HEAD:$filename &&
 630        git notes show HEAD:$filename > actual &&
 631        test_cmp expect actual &&
 632        echo "Note on a tag" > expect
 633        git tag -a -m "This is an annotated tag" foobar HEAD^ &&
 634        git notes add -m "Note on a tag" foobar &&
 635        git notes show foobar > actual &&
 636        test_cmp expect actual
 637'
 638
 639cat > expect << EOF
 640commit 2ede89468182a62d0bde2583c736089bcf7d7e92
 641Author: A U Thor <author@example.com>
 642Date:   Thu Apr 7 15:19:13 2005 -0700
 643
 644    7th
 645
 646Notes (other):
 647    other note
 648EOF
 649
 650test_expect_success 'create note from other note with "git notes add -C"' '
 651        : > a7 &&
 652        git add a7 &&
 653        test_tick &&
 654        git commit -m 7th &&
 655        git notes add -C $(git notes list HEAD^) &&
 656        git log -1 > actual &&
 657        test_cmp expect actual &&
 658        test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 659'
 660
 661test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
 662        : > a8 &&
 663        git add a8 &&
 664        test_tick &&
 665        git commit -m 8th &&
 666        test_must_fail git notes add -C deadbeef &&
 667        test_must_fail git notes list HEAD
 668'
 669
 670cat > expect << EOF
 671commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
 672Author: A U Thor <author@example.com>
 673Date:   Thu Apr 7 15:21:13 2005 -0700
 674
 675    9th
 676
 677Notes (other):
 678    yet another note
 679EOF
 680
 681test_expect_success 'create note from other note with "git notes add -c"' '
 682        : > a9 &&
 683        git add a9 &&
 684        test_tick &&
 685        git commit -m 9th &&
 686        MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
 687        git log -1 > actual &&
 688        test_cmp expect actual
 689'
 690
 691test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
 692        : > a10 &&
 693        git add a10 &&
 694        test_tick &&
 695        git commit -m 10th &&
 696        (
 697                MSG="yet another note" &&
 698                export MSG &&
 699                test_must_fail git notes add -c deadbeef
 700        ) &&
 701        test_must_fail git notes list HEAD
 702'
 703
 704cat > expect << EOF
 705commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
 706Author: A U Thor <author@example.com>
 707Date:   Thu Apr 7 15:21:13 2005 -0700
 708
 709    9th
 710
 711Notes (other):
 712    yet another note
 713$whitespace
 714    yet another note
 715EOF
 716
 717test_expect_success 'append to note from other note with "git notes append -C"' '
 718        git notes append -C $(git notes list HEAD^) HEAD^ &&
 719        git log -1 HEAD^ > actual &&
 720        test_cmp expect actual
 721'
 722
 723cat > expect << EOF
 724commit ffed603236bfa3891c49644257a83598afe8ae5a
 725Author: A U Thor <author@example.com>
 726Date:   Thu Apr 7 15:22:13 2005 -0700
 727
 728    10th
 729
 730Notes (other):
 731    other note
 732EOF
 733
 734test_expect_success 'create note from other note with "git notes append -c"' '
 735        MSG="other note" git notes append -c $(git notes list HEAD^) &&
 736        git log -1 > actual &&
 737        test_cmp expect actual
 738'
 739
 740cat > expect << EOF
 741commit ffed603236bfa3891c49644257a83598afe8ae5a
 742Author: A U Thor <author@example.com>
 743Date:   Thu Apr 7 15:22:13 2005 -0700
 744
 745    10th
 746
 747Notes (other):
 748    other note
 749$whitespace
 750    yet another note
 751EOF
 752
 753test_expect_success 'append to note from other note with "git notes append -c"' '
 754        MSG="yet another note" git notes append -c $(git notes list HEAD) &&
 755        git log -1 > actual &&
 756        test_cmp expect actual
 757'
 758
 759cat > expect << EOF
 760commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
 761Author: A U Thor <author@example.com>
 762Date:   Thu Apr 7 15:23:13 2005 -0700
 763
 764    11th
 765
 766Notes (other):
 767    other note
 768$whitespace
 769    yet another note
 770EOF
 771
 772test_expect_success 'copy note with "git notes copy"' '
 773        : > a11 &&
 774        git add a11 &&
 775        test_tick &&
 776        git commit -m 11th &&
 777        git notes copy HEAD^ HEAD &&
 778        git log -1 > actual &&
 779        test_cmp expect actual &&
 780        test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 781'
 782
 783test_expect_success 'prevent overwrite with "git notes copy"' '
 784        test_must_fail git notes copy HEAD~2 HEAD &&
 785        git log -1 > actual &&
 786        test_cmp expect actual &&
 787        test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
 788'
 789
 790cat > expect << EOF
 791commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
 792Author: A U Thor <author@example.com>
 793Date:   Thu Apr 7 15:23:13 2005 -0700
 794
 795    11th
 796
 797Notes (other):
 798    yet another note
 799$whitespace
 800    yet another note
 801EOF
 802
 803test_expect_success 'allow overwrite with "git notes copy -f"' '
 804        git notes copy -f HEAD~2 HEAD &&
 805        git log -1 > actual &&
 806        test_cmp expect actual &&
 807        test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
 808'
 809
 810test_expect_success 'cannot copy note from object without notes' '
 811        : > a12 &&
 812        git add a12 &&
 813        test_tick &&
 814        git commit -m 12th &&
 815        : > a13 &&
 816        git add a13 &&
 817        test_tick &&
 818        git commit -m 13th &&
 819        test_must_fail git notes copy HEAD^ HEAD
 820'
 821
 822cat > expect << EOF
 823commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
 824Author: A U Thor <author@example.com>
 825Date:   Thu Apr 7 15:25:13 2005 -0700
 826
 827    13th
 828
 829Notes (other):
 830    yet another note
 831$whitespace
 832    yet another note
 833
 834commit 7038787dfe22a14c3867ce816dbba39845359719
 835Author: A U Thor <author@example.com>
 836Date:   Thu Apr 7 15:24:13 2005 -0700
 837
 838    12th
 839
 840Notes (other):
 841    other note
 842$whitespace
 843    yet another note
 844EOF
 845
 846test_expect_success 'git notes copy --stdin' '
 847        (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 848        echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 849        git notes copy --stdin &&
 850        git log -2 > output &&
 851        test_cmp expect output &&
 852        test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
 853        test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
 854'
 855
 856cat > expect << EOF
 857commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
 858Author: A U Thor <author@example.com>
 859Date:   Thu Apr 7 15:27:13 2005 -0700
 860
 861    15th
 862
 863commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
 864Author: A U Thor <author@example.com>
 865Date:   Thu Apr 7 15:26:13 2005 -0700
 866
 867    14th
 868EOF
 869
 870test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
 871        test_commit 14th &&
 872        test_commit 15th &&
 873        (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 874        echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 875        git notes copy --for-rewrite=foo &&
 876        git log -2 > output &&
 877        test_cmp expect output
 878'
 879
 880cat > expect << EOF
 881commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
 882Author: A U Thor <author@example.com>
 883Date:   Thu Apr 7 15:27:13 2005 -0700
 884
 885    15th
 886
 887Notes (other):
 888    yet another note
 889$whitespace
 890    yet another note
 891
 892commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
 893Author: A U Thor <author@example.com>
 894Date:   Thu Apr 7 15:26:13 2005 -0700
 895
 896    14th
 897
 898Notes (other):
 899    other note
 900$whitespace
 901    yet another note
 902EOF
 903
 904test_expect_success 'git notes copy --for-rewrite (enabled)' '
 905        git config notes.rewriteMode overwrite &&
 906        git config notes.rewriteRef "refs/notes/*" &&
 907        (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
 908        echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
 909        git notes copy --for-rewrite=foo &&
 910        git log -2 > output &&
 911        test_cmp expect output
 912'
 913
 914test_expect_success 'git notes copy --for-rewrite (disabled)' '
 915        git config notes.rewrite.bar false &&
 916        echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
 917        git notes copy --for-rewrite=bar &&
 918        git log -2 > output &&
 919        test_cmp expect output
 920'
 921
 922cat > expect << EOF
 923commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
 924Author: A U Thor <author@example.com>
 925Date:   Thu Apr 7 15:27:13 2005 -0700
 926
 927    15th
 928
 929Notes (other):
 930    a fresh note
 931EOF
 932
 933test_expect_success 'git notes copy --for-rewrite (overwrite)' '
 934        git notes add -f -m"a fresh note" HEAD^ &&
 935        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 936        git notes copy --for-rewrite=foo &&
 937        git log -1 > output &&
 938        test_cmp expect output
 939'
 940
 941test_expect_success 'git notes copy --for-rewrite (ignore)' '
 942        git config notes.rewriteMode ignore &&
 943        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 944        git notes copy --for-rewrite=foo &&
 945        git log -1 > output &&
 946        test_cmp expect output
 947'
 948
 949cat > expect << EOF
 950commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
 951Author: A U Thor <author@example.com>
 952Date:   Thu Apr 7 15:27:13 2005 -0700
 953
 954    15th
 955
 956Notes (other):
 957    a fresh note
 958    another fresh note
 959EOF
 960
 961test_expect_success 'git notes copy --for-rewrite (append)' '
 962        git notes add -f -m"another fresh note" HEAD^ &&
 963        git config notes.rewriteMode concatenate &&
 964        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 965        git notes copy --for-rewrite=foo &&
 966        git log -1 > output &&
 967        test_cmp expect output
 968'
 969
 970cat > expect << EOF
 971commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
 972Author: A U Thor <author@example.com>
 973Date:   Thu Apr 7 15:27:13 2005 -0700
 974
 975    15th
 976
 977Notes (other):
 978    a fresh note
 979    another fresh note
 980    append 1
 981    append 2
 982EOF
 983
 984test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 985        git notes add -f -m"append 1" HEAD^ &&
 986        git notes add -f -m"append 2" HEAD^^ &&
 987        (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
 988        echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
 989        git notes copy --for-rewrite=foo &&
 990        git log -1 > output &&
 991        test_cmp expect output
 992'
 993
 994test_expect_success 'git notes copy --for-rewrite (append empty)' '
 995        git notes remove HEAD^ &&
 996        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
 997        git notes copy --for-rewrite=foo &&
 998        git log -1 > output &&
 999        test_cmp expect output
1000'
1001
1002cat > expect << EOF
1003commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1004Author: A U Thor <author@example.com>
1005Date:   Thu Apr 7 15:27:13 2005 -0700
1006
1007    15th
1008
1009Notes (other):
1010    replacement note 1
1011EOF
1012
1013test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1014        git notes add -f -m"replacement note 1" HEAD^ &&
1015        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1016        GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1017        git log -1 > output &&
1018        test_cmp expect output
1019'
1020
1021cat > expect << EOF
1022commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1023Author: A U Thor <author@example.com>
1024Date:   Thu Apr 7 15:27:13 2005 -0700
1025
1026    15th
1027
1028Notes (other):
1029    replacement note 2
1030EOF
1031
1032test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1033        git config notes.rewriteMode overwrite &&
1034        git notes add -f -m"replacement note 2" HEAD^ &&
1035        git config --unset-all notes.rewriteRef &&
1036        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1037        GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1038                git notes copy --for-rewrite=foo &&
1039        git log -1 > output &&
1040        test_cmp expect output
1041'
1042
1043test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1044        git config notes.rewriteRef refs/notes/other &&
1045        git notes add -f -m"replacement note 3" HEAD^ &&
1046        echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1047        GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1048        git log -1 > output &&
1049        test_cmp expect output
1050'
1051
1052test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1053        test_must_fail git notes copy &&
1054        test_must_fail git notes copy one two three
1055'
1056
1057test_done