t / t3301-notes.shon commit Merge branch 'tc/maint-transport-ls-remote-with-void' (cab1b01)
   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
  11echo "$MSG" > "$1"
  12echo "$MSG" >& 2
  13EOF
  14chmod a+x fake_editor.sh
  15VISUAL=./fake_editor.sh
  16export VISUAL
  17
  18test_expect_success 'cannot annotate non-existing HEAD' '
  19        (MSG=3 && export MSG && test_must_fail git notes edit)
  20'
  21
  22test_expect_success setup '
  23        : > a1 &&
  24        git add a1 &&
  25        test_tick &&
  26        git commit -m 1st &&
  27        : > a2 &&
  28        git add a2 &&
  29        test_tick &&
  30        git commit -m 2nd
  31'
  32
  33test_expect_success 'need valid notes ref' '
  34        (MSG=1 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
  35         test_must_fail git notes edit) &&
  36        (MSG=2 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF &&
  37         test_must_fail git notes show)
  38'
  39
  40test_expect_success 'refusing to edit in refs/heads/' '
  41        (MSG=1 GIT_NOTES_REF=refs/heads/bogus &&
  42         export MSG GIT_NOTES_REF &&
  43         test_must_fail git notes edit)
  44'
  45
  46test_expect_success 'refusing to edit in refs/remotes/' '
  47        (MSG=1 GIT_NOTES_REF=refs/remotes/bogus &&
  48         export MSG GIT_NOTES_REF &&
  49         test_must_fail git notes edit)
  50'
  51
  52# 1 indicates caught gracefully by die, 128 means git-show barked
  53test_expect_success 'handle empty notes gracefully' '
  54        git notes show ; test 1 = $?
  55'
  56
  57test_expect_success 'create notes' '
  58        git config core.notesRef refs/notes/commits &&
  59        MSG=b1 git notes edit &&
  60        test ! -f .git/new-notes &&
  61        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
  62        test b1 = $(git notes show) &&
  63        git show HEAD^ &&
  64        test_must_fail git notes show HEAD^
  65'
  66
  67cat > expect << EOF
  68commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
  69Author: A U Thor <author@example.com>
  70Date:   Thu Apr 7 15:14:13 2005 -0700
  71
  72    2nd
  73
  74Notes:
  75    b1
  76EOF
  77
  78test_expect_success 'show notes' '
  79        ! (git cat-file commit HEAD | grep b1) &&
  80        git log -1 > output &&
  81        test_cmp expect output
  82'
  83test_expect_success 'create multi-line notes (setup)' '
  84        : > a3 &&
  85        git add a3 &&
  86        test_tick &&
  87        git commit -m 3rd &&
  88        MSG="b3
  89c3c3c3c3
  90d3d3d3" git notes edit
  91'
  92
  93cat > expect-multiline << EOF
  94commit 1584215f1d29c65e99c6c6848626553fdd07fd75
  95Author: A U Thor <author@example.com>
  96Date:   Thu Apr 7 15:15:13 2005 -0700
  97
  98    3rd
  99
 100Notes:
 101    b3
 102    c3c3c3c3
 103    d3d3d3
 104EOF
 105
 106printf "\n" >> expect-multiline
 107cat expect >> expect-multiline
 108
 109test_expect_success 'show multi-line notes' '
 110        git log -2 > output &&
 111        test_cmp expect-multiline output
 112'
 113test_expect_success 'create -m and -F notes (setup)' '
 114        : > a4 &&
 115        git add a4 &&
 116        test_tick &&
 117        git commit -m 4th &&
 118        echo "xyzzy" > note5 &&
 119        git notes edit -m spam -F note5 -m "foo
 120bar
 121baz"
 122'
 123
 124whitespace="    "
 125cat > expect-m-and-F << EOF
 126commit 15023535574ded8b1a89052b32673f84cf9582b8
 127Author: A U Thor <author@example.com>
 128Date:   Thu Apr 7 15:16:13 2005 -0700
 129
 130    4th
 131
 132Notes:
 133    spam
 134$whitespace
 135    xyzzy
 136$whitespace
 137    foo
 138    bar
 139    baz
 140EOF
 141
 142printf "\n" >> expect-m-and-F
 143cat expect-multiline >> expect-m-and-F
 144
 145test_expect_success 'show -m and -F notes' '
 146        git log -3 > output &&
 147        test_cmp expect-m-and-F output
 148'
 149
 150cat >expect << EOF
 151commit 15023535574ded8b1a89052b32673f84cf9582b8
 152tree e070e3af51011e47b183c33adf9736736a525709
 153parent 1584215f1d29c65e99c6c6848626553fdd07fd75
 154author A U Thor <author@example.com> 1112912173 -0700
 155committer C O Mitter <committer@example.com> 1112912173 -0700
 156
 157    4th
 158EOF
 159test_expect_success 'git log --pretty=raw does not show notes' '
 160        git log -1 --pretty=raw >output &&
 161        test_cmp expect output
 162'
 163
 164cat >>expect <<EOF
 165
 166Notes:
 167    spam
 168$whitespace
 169    xyzzy
 170$whitespace
 171    foo
 172    bar
 173    baz
 174EOF
 175test_expect_success 'git log --show-notes' '
 176        git log -1 --pretty=raw --show-notes >output &&
 177        test_cmp expect output
 178'
 179
 180test_expect_success 'git log --no-notes' '
 181        git log -1 --no-notes >output &&
 182        ! grep spam output
 183'
 184
 185test_expect_success 'git format-patch does not show notes' '
 186        git format-patch -1 --stdout >output &&
 187        ! grep spam output
 188'
 189
 190test_expect_success 'git format-patch --show-notes does show notes' '
 191        git format-patch --show-notes -1 --stdout >output &&
 192        grep spam output
 193'
 194
 195for pretty in \
 196        "" --pretty --pretty=raw --pretty=short --pretty=medium \
 197        --pretty=full --pretty=fuller --pretty=format:%s --oneline
 198do
 199        case "$pretty" in
 200        "") p= not= negate="" ;;
 201        ?*) p="$pretty" not=" not" negate="!" ;;
 202        esac
 203        test_expect_success "git show $pretty does$not show notes" '
 204                git show $p >output &&
 205                eval "$negate grep spam output"
 206        '
 207done
 208
 209test_done