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