t / t3304-notes-mixed.shon commit Merge branch 'tc/http-cleanup' (78d909a)
   1#!/bin/sh
   2
   3test_description='Test notes trees that also contain non-notes'
   4
   5. ./test-lib.sh
   6
   7number_of_commits=100
   8
   9start_note_commit () {
  10        test_tick &&
  11        cat <<INPUT_END
  12commit refs/notes/commits
  13committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  14data <<COMMIT
  15notes
  16COMMIT
  17
  18from refs/notes/commits^0
  19deleteall
  20INPUT_END
  21
  22}
  23
  24verify_notes () {
  25        git log | grep "^    " > output &&
  26        i=$number_of_commits &&
  27        while [ $i -gt 0 ]; do
  28                echo "    commit #$i" &&
  29                echo "    note for commit #$i" &&
  30                i=$(($i-1));
  31        done > expect &&
  32        test_cmp expect output
  33}
  34
  35test_expect_success "setup: create a couple of commits" '
  36
  37        test_tick &&
  38        cat <<INPUT_END >input &&
  39commit refs/heads/master
  40committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  41data <<COMMIT
  42commit #1
  43COMMIT
  44
  45M 644 inline file
  46data <<EOF
  47file in commit #1
  48EOF
  49
  50INPUT_END
  51
  52        test_tick &&
  53        cat <<INPUT_END >>input &&
  54commit refs/heads/master
  55committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  56data <<COMMIT
  57commit #2
  58COMMIT
  59
  60M 644 inline file
  61data <<EOF
  62file in commit #2
  63EOF
  64
  65INPUT_END
  66        git fast-import --quiet <input
  67'
  68
  69test_expect_success "create a notes tree with both notes and non-notes" '
  70
  71        commit1=$(git rev-parse refs/heads/master^) &&
  72        commit2=$(git rev-parse refs/heads/master) &&
  73        test_tick &&
  74        cat <<INPUT_END >input &&
  75commit refs/notes/commits
  76committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  77data <<COMMIT
  78notes commit #1
  79COMMIT
  80
  81N inline $commit1
  82data <<EOF
  83note for commit #1
  84EOF
  85
  86N inline $commit2
  87data <<EOF
  88note for commit #2
  89EOF
  90
  91INPUT_END
  92        test_tick &&
  93        cat <<INPUT_END >>input &&
  94commit refs/notes/commits
  95committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  96data <<COMMIT
  97notes commit #2
  98COMMIT
  99
 100M 644 inline foobar/non-note.txt
 101data <<EOF
 102A non-note in a notes tree
 103EOF
 104
 105N inline $commit2
 106data <<EOF
 107edited note for commit #2
 108EOF
 109
 110INPUT_END
 111        test_tick &&
 112        cat <<INPUT_END >>input &&
 113commit refs/notes/commits
 114committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 115data <<COMMIT
 116notes commit #3
 117COMMIT
 118
 119N inline $commit1
 120data <<EOF
 121edited note for commit #1
 122EOF
 123
 124M 644 inline deadbeef
 125data <<EOF
 126non-note with SHA1-like name
 127EOF
 128
 129M 644 inline de/adbeef
 130data <<EOF
 131another non-note with SHA1-like name
 132EOF
 133
 134M 644 inline de/adbeefdeadbeefdeadbeefdeadbeefdeadbeef
 135data <<EOF
 136This is actually a valid note, albeit to a non-existing object.
 137It is needed in order to trigger the "mishandling" of the dead/beef non-note.
 138EOF
 139
 140M 644 inline dead/beef
 141data <<EOF
 142yet another non-note with SHA1-like name
 143EOF
 144
 145INPUT_END
 146        git fast-import --quiet <input &&
 147        git config core.notesRef refs/notes/commits
 148'
 149
 150cat >expect <<EXPECT_END
 151    commit #2
 152    edited note for commit #2
 153    commit #1
 154    edited note for commit #1
 155EXPECT_END
 156
 157test_expect_success "verify contents of notes" '
 158
 159        git log | grep "^    " > actual &&
 160        test_cmp expect actual
 161'
 162
 163cat >expect_nn1 <<EXPECT_END
 164A non-note in a notes tree
 165EXPECT_END
 166cat >expect_nn2 <<EXPECT_END
 167non-note with SHA1-like name
 168EXPECT_END
 169cat >expect_nn3 <<EXPECT_END
 170another non-note with SHA1-like name
 171EXPECT_END
 172cat >expect_nn4 <<EXPECT_END
 173yet another non-note with SHA1-like name
 174EXPECT_END
 175
 176test_expect_success "verify contents of non-notes" '
 177
 178        git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
 179        test_cmp expect_nn1 actual_nn1 &&
 180        git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
 181        test_cmp expect_nn2 actual_nn2 &&
 182        git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
 183        test_cmp expect_nn3 actual_nn3 &&
 184        git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
 185        test_cmp expect_nn4 actual_nn4
 186'
 187
 188test_expect_success "git-notes preserves non-notes" '
 189
 190        test_tick &&
 191        git notes add -f -m "foo bar"
 192'
 193
 194test_expect_success "verify contents of non-notes after git-notes" '
 195
 196        git cat-file -p refs/notes/commits:foobar/non-note.txt > actual_nn1 &&
 197        test_cmp expect_nn1 actual_nn1 &&
 198        git cat-file -p refs/notes/commits:deadbeef > actual_nn2 &&
 199        test_cmp expect_nn2 actual_nn2 &&
 200        git cat-file -p refs/notes/commits:de/adbeef > actual_nn3 &&
 201        test_cmp expect_nn3 actual_nn3 &&
 202        git cat-file -p refs/notes/commits:dead/beef > actual_nn4 &&
 203        test_cmp expect_nn4 actual_nn4
 204'
 205
 206test_done