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