Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Johannes E. Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='Test commit notes' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | cat > fake_editor.sh << \EOF |
| 11 | echo "$MSG" > "$1" |
| 12 | echo "$MSG" >& 2 |
| 13 | EOF |
| 14 | chmod a+x fake_editor.sh |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 15 | GIT_EDITOR=./fake_editor.sh |
| 16 | export GIT_EDITOR |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 17 | |
| 18 | test_expect_success 'cannot annotate non-existing HEAD' ' |
| 19 | (MSG=3 && export MSG && test_must_fail git notes edit) |
| 20 | ' |
| 21 | |
| 22 | test_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 | |
| 33 | test_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 | |
| 40 | test_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 | |
| 46 | test_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 |
| 53 | test_expect_success 'handle empty notes gracefully' ' |
| 54 | git notes show ; test 1 = $? |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'create notes' ' |
| 58 | git config core.notesRef refs/notes/commits && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 59 | MSG=b0 git notes edit && |
| 60 | test ! -f .git/NOTES_EDITMSG && |
| 61 | test 1 = $(git ls-tree refs/notes/commits | wc -l) && |
| 62 | test b0 = $(git notes show) && |
| 63 | git show HEAD^ && |
| 64 | test_must_fail git notes show HEAD^ |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'edit existing notes' ' |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 68 | MSG=b1 git notes edit && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 69 | test ! -f .git/NOTES_EDITMSG && |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 70 | test 1 = $(git ls-tree refs/notes/commits | wc -l) && |
| 71 | test b1 = $(git notes show) && |
| 72 | git show HEAD^ && |
| 73 | test_must_fail git notes show HEAD^ |
| 74 | ' |
| 75 | |
| 76 | cat > expect << EOF |
| 77 | commit 268048bfb8a1fb38e703baceb8ab235421bf80c5 |
| 78 | Author: A U Thor <author@example.com> |
| 79 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 80 | |
| 81 | 2nd |
| 82 | |
| 83 | Notes: |
| 84 | b1 |
| 85 | EOF |
| 86 | |
| 87 | test_expect_success 'show notes' ' |
| 88 | ! (git cat-file commit HEAD | grep b1) && |
| 89 | git log -1 > output && |
| 90 | test_cmp expect output |
| 91 | ' |
| 92 | test_expect_success 'create multi-line notes (setup)' ' |
| 93 | : > a3 && |
| 94 | git add a3 && |
| 95 | test_tick && |
| 96 | git commit -m 3rd && |
| 97 | MSG="b3 |
| 98 | c3c3c3c3 |
| 99 | d3d3d3" git notes edit |
| 100 | ' |
| 101 | |
| 102 | cat > expect-multiline << EOF |
| 103 | commit 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 104 | Author: A U Thor <author@example.com> |
| 105 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 106 | |
| 107 | 3rd |
| 108 | |
| 109 | Notes: |
| 110 | b3 |
| 111 | c3c3c3c3 |
| 112 | d3d3d3 |
| 113 | EOF |
| 114 | |
| 115 | printf "\n" >> expect-multiline |
| 116 | cat expect >> expect-multiline |
| 117 | |
| 118 | test_expect_success 'show multi-line notes' ' |
| 119 | git log -2 > output && |
| 120 | test_cmp expect-multiline output |
| 121 | ' |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 122 | test_expect_success 'create -F notes (setup)' ' |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 123 | : > a4 && |
| 124 | git add a4 && |
| 125 | test_tick && |
| 126 | git commit -m 4th && |
| 127 | echo "xyzzy" > note5 && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 128 | git notes edit -F note5 |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 129 | ' |
| 130 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 131 | cat > expect-F << EOF |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 132 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 133 | Author: A U Thor <author@example.com> |
| 134 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 135 | |
| 136 | 4th |
| 137 | |
| 138 | Notes: |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 139 | xyzzy |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 140 | EOF |
| 141 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 142 | printf "\n" >> expect-F |
| 143 | cat expect-multiline >> expect-F |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 144 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 145 | test_expect_success 'show -F notes' ' |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 146 | git log -3 > output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 147 | test_cmp expect-F output |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 148 | ' |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 149 | |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 150 | cat >expect << EOF |
| 151 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 152 | tree e070e3af51011e47b183c33adf9736736a525709 |
| 153 | parent 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 154 | author A U Thor <author@example.com> 1112912173 -0700 |
| 155 | committer C O Mitter <committer@example.com> 1112912173 -0700 |
| 156 | |
| 157 | 4th |
| 158 | EOF |
| 159 | test_expect_success 'git log --pretty=raw does not show notes' ' |
| 160 | git log -1 --pretty=raw >output && |
| 161 | test_cmp expect output |
| 162 | ' |
| 163 | |
| 164 | cat >>expect <<EOF |
| 165 | |
| 166 | Notes: |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 167 | xyzzy |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 168 | EOF |
| 169 | test_expect_success 'git log --show-notes' ' |
| 170 | git log -1 --pretty=raw --show-notes >output && |
| 171 | test_cmp expect output |
| 172 | ' |
| 173 | |
| 174 | test_expect_success 'git log --no-notes' ' |
| 175 | git log -1 --no-notes >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 176 | ! grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 177 | ' |
| 178 | |
| 179 | test_expect_success 'git format-patch does not show notes' ' |
| 180 | git format-patch -1 --stdout >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 181 | ! grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 182 | ' |
| 183 | |
| 184 | test_expect_success 'git format-patch --show-notes does show notes' ' |
| 185 | git format-patch --show-notes -1 --stdout >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 186 | grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 187 | ' |
| 188 | |
Junio C Hamano | 7dccadf | 2010-01-21 14:57:41 -0800 | [diff] [blame] | 189 | for pretty in \ |
| 190 | "" --pretty --pretty=raw --pretty=short --pretty=medium \ |
| 191 | --pretty=full --pretty=fuller --pretty=format:%s --oneline |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 192 | do |
| 193 | case "$pretty" in |
| 194 | "") p= not= negate="" ;; |
Junio C Hamano | 7dccadf | 2010-01-21 14:57:41 -0800 | [diff] [blame] | 195 | ?*) p="$pretty" not=" not" negate="!" ;; |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 196 | esac |
| 197 | test_expect_success "git show $pretty does$not show notes" ' |
| 198 | git show $p >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 199 | eval "$negate grep xyzzy output" |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 200 | ' |
| 201 | done |
| 202 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 203 | test_expect_success 'create -m notes (setup)' ' |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 204 | : > a5 && |
| 205 | git add a5 && |
| 206 | test_tick && |
| 207 | git commit -m 5th && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 208 | git notes edit -m spam -m "foo |
| 209 | bar |
| 210 | baz" |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 211 | ' |
| 212 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 213 | whitespace=" " |
| 214 | cat > expect-m << EOF |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 215 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 216 | Author: A U Thor <author@example.com> |
| 217 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 218 | |
| 219 | 5th |
| 220 | |
| 221 | Notes: |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 222 | spam |
| 223 | $whitespace |
| 224 | foo |
| 225 | bar |
| 226 | baz |
| 227 | EOF |
| 228 | |
| 229 | printf "\n" >> expect-m |
| 230 | cat expect-F >> expect-m |
| 231 | |
| 232 | test_expect_success 'show -m notes' ' |
| 233 | git log -4 > output && |
| 234 | test_cmp expect-m output |
| 235 | ' |
| 236 | |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 237 | test_expect_success 'remove note with -F /dev/null (setup)' ' |
| 238 | git notes edit -F /dev/null |
| 239 | ' |
| 240 | |
| 241 | cat > expect-rm-F << EOF |
| 242 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 243 | Author: A U Thor <author@example.com> |
| 244 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 245 | |
| 246 | 5th |
| 247 | EOF |
| 248 | |
| 249 | printf "\n" >> expect-rm-F |
| 250 | cat expect-F >> expect-rm-F |
| 251 | |
| 252 | test_expect_success 'verify note removal with -F /dev/null' ' |
| 253 | git log -4 > output && |
| 254 | test_cmp expect-rm-F output && |
| 255 | ! git notes show |
| 256 | ' |
| 257 | |
| 258 | test_expect_success 'do not create empty note with -m "" (setup)' ' |
| 259 | git notes edit -m "" |
| 260 | ' |
| 261 | |
| 262 | test_expect_success 'verify non-creation of note with -m ""' ' |
| 263 | git log -4 > output && |
| 264 | test_cmp expect-rm-F output && |
| 265 | ! git notes show |
| 266 | ' |
| 267 | |
Johan Herland | 92b3385 | 2010-02-13 22:28:25 +0100 | [diff] [blame] | 268 | test_expect_success 'remove note with "git notes remove" (setup)' ' |
| 269 | git notes remove HEAD^ |
| 270 | ' |
| 271 | |
| 272 | cat > expect-rm-remove << EOF |
| 273 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 274 | Author: A U Thor <author@example.com> |
| 275 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 276 | |
| 277 | 5th |
| 278 | |
| 279 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 280 | Author: A U Thor <author@example.com> |
| 281 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 282 | |
| 283 | 4th |
| 284 | EOF |
| 285 | |
| 286 | printf "\n" >> expect-rm-remove |
| 287 | cat expect-multiline >> expect-rm-remove |
| 288 | |
| 289 | test_expect_success 'verify note removal with "git notes remove"' ' |
| 290 | git log -4 > output && |
| 291 | test_cmp expect-rm-remove output && |
| 292 | ! git notes show HEAD^ |
| 293 | ' |
| 294 | |
Johan Herland | e397421 | 2010-02-13 22:28:30 +0100 | [diff] [blame^] | 295 | cat > expect << EOF |
| 296 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 297 | c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 |
| 298 | EOF |
| 299 | |
| 300 | test_expect_success 'list notes with "git notes list"' ' |
| 301 | git notes list > output && |
| 302 | test_cmp expect output |
| 303 | ' |
| 304 | |
| 305 | test_expect_success 'list notes with "git notes"' ' |
| 306 | git notes > output && |
| 307 | test_cmp expect output |
| 308 | ' |
| 309 | |
| 310 | cat > expect << EOF |
| 311 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 |
| 312 | EOF |
| 313 | |
| 314 | test_expect_success 'list specific note with "git notes list <object>"' ' |
| 315 | git notes list HEAD^^ > output && |
| 316 | test_cmp expect output |
| 317 | ' |
| 318 | |
| 319 | cat > expect << EOF |
| 320 | EOF |
| 321 | |
| 322 | test_expect_success 'listing non-existing notes fails' ' |
| 323 | test_must_fail git notes list HEAD > output && |
| 324 | test_cmp expect output |
| 325 | ' |
| 326 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 327 | test_expect_success 'create other note on a different notes ref (setup)' ' |
| 328 | : > a6 && |
| 329 | git add a6 && |
| 330 | test_tick && |
| 331 | git commit -m 6th && |
| 332 | GIT_NOTES_REF="refs/notes/other" git notes edit -m "other note" |
| 333 | ' |
| 334 | |
| 335 | cat > expect-other << EOF |
| 336 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 337 | Author: A U Thor <author@example.com> |
| 338 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 339 | |
| 340 | 6th |
| 341 | |
| 342 | Notes: |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 343 | other note |
| 344 | EOF |
| 345 | |
| 346 | cat > expect-not-other << EOF |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 347 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 348 | Author: A U Thor <author@example.com> |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 349 | Date: Thu Apr 7 15:18:13 2005 -0700 |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 350 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 351 | 6th |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 352 | EOF |
| 353 | |
| 354 | test_expect_success 'Do not show note on other ref by default' ' |
| 355 | git log -1 > output && |
| 356 | test_cmp expect-not-other output |
| 357 | ' |
| 358 | |
| 359 | test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' |
| 360 | GIT_NOTES_REF="refs/notes/other" git log -1 > output && |
| 361 | test_cmp expect-other output |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'Do show note when ref is given in core.notesRef config' ' |
| 365 | git config core.notesRef "refs/notes/other" && |
| 366 | git log -1 > output && |
| 367 | test_cmp expect-other output |
| 368 | ' |
| 369 | |
| 370 | test_expect_success 'Do not show note when core.notesRef is overridden' ' |
| 371 | GIT_NOTES_REF="refs/notes/wrong" git log -1 > output && |
| 372 | test_cmp expect-not-other output |
| 373 | ' |
| 374 | |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 375 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
| 376 | echo "Note on a tree" > expect |
| 377 | git notes edit -m "Note on a tree" HEAD: && |
| 378 | git notes show HEAD: > actual && |
| 379 | test_cmp expect actual && |
| 380 | echo "Note on a blob" > expect |
| 381 | filename=$(git ls-tree --name-only HEAD | head -n1) && |
| 382 | git notes edit -m "Note on a blob" HEAD:$filename && |
| 383 | git notes show HEAD:$filename > actual && |
| 384 | test_cmp expect actual && |
| 385 | echo "Note on a tag" > expect |
| 386 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
| 387 | git notes edit -m "Note on a tag" foobar && |
| 388 | git notes show foobar > actual && |
| 389 | test_cmp expect actual |
| 390 | ' |
| 391 | |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 392 | test_done |