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 |
Johannes Sixt | 97a449e | 2010-02-25 11:39:50 +0100 | [diff] [blame] | 11 | #!/bin/sh |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 12 | echo "$MSG" > "$1" |
| 13 | echo "$MSG" >& 2 |
| 14 | EOF |
| 15 | chmod a+x fake_editor.sh |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 16 | GIT_EDITOR=./fake_editor.sh |
| 17 | export GIT_EDITOR |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 18 | |
| 19 | test_expect_success 'cannot annotate non-existing HEAD' ' |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame^] | 20 | test_must_fail env MSG=3 git notes add |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 21 | ' |
| 22 | |
| 23 | test_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 | |
| 34 | test_expect_success 'need valid notes ref' ' |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame^] | 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 |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 37 | ' |
| 38 | |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 39 | test_expect_success 'refusing to add notes in refs/heads/' ' |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame^] | 40 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 41 | ' |
| 42 | |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 43 | test_expect_success 'refusing to edit notes in refs/remotes/' ' |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame^] | 44 | test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 45 | ' |
| 46 | |
| 47 | # 1 indicates caught gracefully by die, 128 means git-show barked |
| 48 | test_expect_success 'handle empty notes gracefully' ' |
Jonathan Nieder | 0155a64 | 2010-10-31 02:36:57 -0500 | [diff] [blame] | 49 | test_expect_code 1 git notes show |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 50 | ' |
| 51 | |
Junio C Hamano | 636db2c | 2010-04-18 11:19:39 -0700 | [diff] [blame] | 52 | test_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 | |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 61 | test_expect_success 'create notes' ' |
| 62 | git config core.notesRef refs/notes/commits && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 63 | MSG=b4 git notes add && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 64 | test ! -f .git/NOTES_EDITMSG && |
| 65 | test 1 = $(git ls-tree refs/notes/commits | wc -l) && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 66 | test b4 = $(git notes show) && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 67 | git show HEAD^ && |
| 68 | test_must_fail git notes show HEAD^ |
| 69 | ' |
| 70 | |
Junio C Hamano | 636db2c | 2010-04-18 11:19:39 -0700 | [diff] [blame] | 71 | test_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 | |
Michael J Gruber | 4d80fa8 | 2010-03-29 15:05:57 +0200 | [diff] [blame] | 80 | cat >expect <<EOF |
| 81 | d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add' |
| 82 | EOF |
| 83 | |
Michael J Gruber | b2e256b | 2010-03-29 15:05:58 +0200 | [diff] [blame] | 84 | test_expect_success 'create reflog entry' ' |
Michael J Gruber | 4d80fa8 | 2010-03-29 15:05:57 +0200 | [diff] [blame] | 85 | git reflog show refs/notes/commits >output && |
| 86 | test_cmp expect output |
| 87 | ' |
| 88 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 89 | test_expect_success 'edit existing notes' ' |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 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 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 98 | test_expect_success 'cannot "git notes add -m" where notes already exists' ' |
| 99 | test_must_fail git notes add -m "b2" && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 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 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 107 | test_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 | |
| 116 | test_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 | |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 125 | test_expect_success 'can overwrite existing note with "git notes add -f"' ' |
| 126 | MSG=b1 git notes add -f && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 127 | test ! -f .git/NOTES_EDITMSG && |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 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 | |
| 134 | cat > expect << EOF |
| 135 | commit 268048bfb8a1fb38e703baceb8ab235421bf80c5 |
| 136 | Author: A U Thor <author@example.com> |
| 137 | Date: Thu Apr 7 15:14:13 2005 -0700 |
| 138 | |
| 139 | 2nd |
| 140 | |
| 141 | Notes: |
| 142 | b1 |
| 143 | EOF |
| 144 | |
| 145 | test_expect_success 'show notes' ' |
| 146 | ! (git cat-file commit HEAD | grep b1) && |
| 147 | git log -1 > output && |
| 148 | test_cmp expect output |
| 149 | ' |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 150 | |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 151 | test_expect_success 'create multi-line notes (setup)' ' |
| 152 | : > a3 && |
| 153 | git add a3 && |
| 154 | test_tick && |
| 155 | git commit -m 3rd && |
| 156 | MSG="b3 |
| 157 | c3c3c3c3 |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 158 | d3d3d3" git notes add |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 159 | ' |
| 160 | |
| 161 | cat > expect-multiline << EOF |
| 162 | commit 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 163 | Author: A U Thor <author@example.com> |
| 164 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 165 | |
| 166 | 3rd |
| 167 | |
| 168 | Notes: |
| 169 | b3 |
| 170 | c3c3c3c3 |
| 171 | d3d3d3 |
| 172 | EOF |
| 173 | |
| 174 | printf "\n" >> expect-multiline |
| 175 | cat expect >> expect-multiline |
| 176 | |
| 177 | test_expect_success 'show multi-line notes' ' |
| 178 | git log -2 > output && |
| 179 | test_cmp expect-multiline output |
| 180 | ' |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 181 | test_expect_success 'create -F notes (setup)' ' |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 182 | : > a4 && |
| 183 | git add a4 && |
| 184 | test_tick && |
| 185 | git commit -m 4th && |
| 186 | echo "xyzzy" > note5 && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 187 | git notes add -F note5 |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 188 | ' |
| 189 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 190 | cat > expect-F << EOF |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 191 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 192 | Author: A U Thor <author@example.com> |
| 193 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 194 | |
| 195 | 4th |
| 196 | |
| 197 | Notes: |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 198 | xyzzy |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 199 | EOF |
| 200 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 201 | printf "\n" >> expect-F |
| 202 | cat expect-multiline >> expect-F |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 203 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 204 | test_expect_success 'show -F notes' ' |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 205 | git log -3 > output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 206 | test_cmp expect-F output |
Johan Herland | d9246d4 | 2009-10-09 12:22:01 +0200 | [diff] [blame] | 207 | ' |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 208 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 209 | test_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 | |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 216 | cat >expect << EOF |
| 217 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 218 | tree e070e3af51011e47b183c33adf9736736a525709 |
| 219 | parent 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 220 | author A U Thor <author@example.com> 1112912173 -0700 |
| 221 | committer C O Mitter <committer@example.com> 1112912173 -0700 |
| 222 | |
| 223 | 4th |
| 224 | EOF |
| 225 | test_expect_success 'git log --pretty=raw does not show notes' ' |
| 226 | git log -1 --pretty=raw >output && |
| 227 | test_cmp expect output |
| 228 | ' |
| 229 | |
| 230 | cat >>expect <<EOF |
| 231 | |
| 232 | Notes: |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 233 | xyzzy |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 234 | EOF |
| 235 | test_expect_success 'git log --show-notes' ' |
| 236 | git log -1 --pretty=raw --show-notes >output && |
| 237 | test_cmp expect output |
| 238 | ' |
| 239 | |
| 240 | test_expect_success 'git log --no-notes' ' |
| 241 | git log -1 --no-notes >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 242 | ! grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 243 | ' |
| 244 | |
| 245 | test_expect_success 'git format-patch does not show notes' ' |
| 246 | git format-patch -1 --stdout >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 247 | ! grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 248 | ' |
| 249 | |
| 250 | test_expect_success 'git format-patch --show-notes does show notes' ' |
| 251 | git format-patch --show-notes -1 --stdout >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 252 | grep xyzzy output |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 253 | ' |
| 254 | |
Junio C Hamano | 7dccadf | 2010-01-21 14:57:41 -0800 | [diff] [blame] | 255 | for pretty in \ |
| 256 | "" --pretty --pretty=raw --pretty=short --pretty=medium \ |
| 257 | --pretty=full --pretty=fuller --pretty=format:%s --oneline |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 258 | do |
| 259 | case "$pretty" in |
| 260 | "") p= not= negate="" ;; |
Junio C Hamano | 7dccadf | 2010-01-21 14:57:41 -0800 | [diff] [blame] | 261 | ?*) p="$pretty" not=" not" negate="!" ;; |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 262 | esac |
| 263 | test_expect_success "git show $pretty does$not show notes" ' |
| 264 | git show $p >output && |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 265 | eval "$negate grep xyzzy output" |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 266 | ' |
| 267 | done |
| 268 | |
Jeff King | 7249e91 | 2011-03-29 16:57:47 -0400 | [diff] [blame] | 269 | test_expect_success 'setup alternate notes ref' ' |
| 270 | git notes --ref=alternate add -m alternate |
| 271 | ' |
| 272 | |
| 273 | test_expect_success 'git log --notes shows default notes' ' |
| 274 | git log -1 --notes >output && |
| 275 | grep xyzzy output && |
| 276 | ! grep alternate output |
| 277 | ' |
| 278 | |
| 279 | test_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 | |
| 285 | test_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 | |
Jeff King | 92e0d42 | 2011-03-29 16:59:42 -0400 | [diff] [blame] | 291 | test_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 | |
| 299 | test_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 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 307 | test_expect_success 'create -m notes (setup)' ' |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 308 | : > a5 && |
| 309 | git add a5 && |
| 310 | test_tick && |
| 311 | git commit -m 5th && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 312 | git notes add -m spam -m "foo |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 313 | bar |
| 314 | baz" |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 315 | ' |
| 316 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 317 | whitespace=" " |
| 318 | cat > expect-m << EOF |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 319 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 320 | Author: A U Thor <author@example.com> |
| 321 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 322 | |
| 323 | 5th |
| 324 | |
| 325 | Notes: |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 326 | spam |
| 327 | $whitespace |
| 328 | foo |
| 329 | bar |
| 330 | baz |
| 331 | EOF |
| 332 | |
| 333 | printf "\n" >> expect-m |
| 334 | cat expect-F >> expect-m |
| 335 | |
| 336 | test_expect_success 'show -m notes' ' |
| 337 | git log -4 > output && |
| 338 | test_cmp expect-m output |
| 339 | ' |
| 340 | |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 341 | test_expect_success 'remove note with add -f -F /dev/null (setup)' ' |
| 342 | git notes add -f -F /dev/null |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 343 | ' |
| 344 | |
| 345 | cat > expect-rm-F << EOF |
| 346 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 347 | Author: A U Thor <author@example.com> |
| 348 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 349 | |
| 350 | 5th |
| 351 | EOF |
| 352 | |
| 353 | printf "\n" >> expect-rm-F |
| 354 | cat expect-F >> expect-rm-F |
| 355 | |
| 356 | test_expect_success 'verify note removal with -F /dev/null' ' |
| 357 | git log -4 > output && |
| 358 | test_cmp expect-rm-F output && |
Jared Hance | ce14e0b | 2010-07-20 19:18:34 -0400 | [diff] [blame] | 359 | test_must_fail git notes show |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 360 | ' |
| 361 | |
| 362 | test_expect_success 'do not create empty note with -m "" (setup)' ' |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 363 | git notes add -m "" |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 364 | ' |
| 365 | |
| 366 | test_expect_success 'verify non-creation of note with -m ""' ' |
| 367 | git log -4 > output && |
| 368 | test_cmp expect-rm-F output && |
Jared Hance | ce14e0b | 2010-07-20 19:18:34 -0400 | [diff] [blame] | 369 | test_must_fail git notes show |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 370 | ' |
| 371 | |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 372 | cat > expect-combine_m_and_F << EOF |
| 373 | foo |
| 374 | |
| 375 | xyzzy |
| 376 | |
| 377 | bar |
| 378 | |
| 379 | zyxxy |
| 380 | |
| 381 | baz |
| 382 | EOF |
| 383 | |
| 384 | test_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 | |
Johan Herland | 92b3385 | 2010-02-13 22:28:25 +0100 | [diff] [blame] | 392 | test_expect_success 'remove note with "git notes remove" (setup)' ' |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 393 | git notes remove HEAD^ && |
| 394 | git notes remove |
Johan Herland | 92b3385 | 2010-02-13 22:28:25 +0100 | [diff] [blame] | 395 | ' |
| 396 | |
| 397 | cat > expect-rm-remove << EOF |
| 398 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 399 | Author: A U Thor <author@example.com> |
| 400 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 401 | |
| 402 | 5th |
| 403 | |
| 404 | commit 15023535574ded8b1a89052b32673f84cf9582b8 |
| 405 | Author: A U Thor <author@example.com> |
| 406 | Date: Thu Apr 7 15:16:13 2005 -0700 |
| 407 | |
| 408 | 4th |
| 409 | EOF |
| 410 | |
| 411 | printf "\n" >> expect-rm-remove |
| 412 | cat expect-multiline >> expect-rm-remove |
| 413 | |
| 414 | test_expect_success 'verify note removal with "git notes remove"' ' |
| 415 | git log -4 > output && |
| 416 | test_cmp expect-rm-remove output && |
Jared Hance | ce14e0b | 2010-07-20 19:18:34 -0400 | [diff] [blame] | 417 | test_must_fail git notes show HEAD^ |
Johan Herland | 92b3385 | 2010-02-13 22:28:25 +0100 | [diff] [blame] | 418 | ' |
| 419 | |
Johan Herland | e397421 | 2010-02-13 22:28:30 +0100 | [diff] [blame] | 420 | cat > expect << EOF |
| 421 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 422 | c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 |
| 423 | EOF |
| 424 | |
Johan Herland | 1ee1e43 | 2010-08-31 17:56:50 +0200 | [diff] [blame] | 425 | test_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 | |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 432 | test_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 | |
| 444 | test_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 | |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 452 | test_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 | |
| 464 | test_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 | |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 472 | test_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 | |
| 485 | test_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 | |
| 494 | test_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 | |
Johan Herland | e397421 | 2010-02-13 22:28:30 +0100 | [diff] [blame] | 507 | test_expect_success 'list notes with "git notes list"' ' |
| 508 | git notes list > output && |
| 509 | test_cmp expect output |
| 510 | ' |
| 511 | |
| 512 | test_expect_success 'list notes with "git notes"' ' |
| 513 | git notes > output && |
| 514 | test_cmp expect output |
| 515 | ' |
| 516 | |
| 517 | cat > expect << EOF |
| 518 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 |
| 519 | EOF |
| 520 | |
| 521 | test_expect_success 'list specific note with "git notes list <object>"' ' |
| 522 | git notes list HEAD^^ > output && |
| 523 | test_cmp expect output |
| 524 | ' |
| 525 | |
| 526 | cat > expect << EOF |
| 527 | EOF |
| 528 | |
| 529 | test_expect_success 'listing non-existing notes fails' ' |
| 530 | test_must_fail git notes list HEAD > output && |
| 531 | test_cmp expect output |
| 532 | ' |
| 533 | |
Johan Herland | 2347fae | 2010-02-13 22:28:33 +0100 | [diff] [blame] | 534 | cat > expect << EOF |
| 535 | Initial set of notes |
| 536 | |
| 537 | More notes appended with git notes append |
| 538 | EOF |
| 539 | |
| 540 | test_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 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 547 | cat > expect_list << EOF |
| 548 | c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 |
| 549 | c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 |
| 550 | 4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d |
| 551 | EOF |
| 552 | |
| 553 | test_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 | |
Johan Herland | 2347fae | 2010-02-13 22:28:33 +0100 | [diff] [blame] | 558 | test_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 | |
| 564 | test_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 | |
| 569 | More notes appended with git notes append" && |
| 570 | git notes show > output && |
| 571 | test_cmp expect output |
| 572 | ' |
| 573 | |
| 574 | test_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 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 581 | test_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 && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 586 | GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 587 | ' |
| 588 | |
| 589 | cat > expect-other << EOF |
| 590 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 591 | Author: A U Thor <author@example.com> |
| 592 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 593 | |
| 594 | 6th |
| 595 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 596 | Notes (other): |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 597 | other note |
| 598 | EOF |
| 599 | |
| 600 | cat > expect-not-other << EOF |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 601 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 602 | Author: A U Thor <author@example.com> |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 603 | Date: Thu Apr 7 15:18:13 2005 -0700 |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 604 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 605 | 6th |
Johan Herland | 3b78cdb | 2010-02-13 22:28:11 +0100 | [diff] [blame] | 606 | EOF |
| 607 | |
| 608 | test_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 | |
| 613 | test_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 | |
| 618 | test_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 | |
| 624 | test_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 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 629 | cat > expect-both << EOF |
| 630 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 631 | Author: A U Thor <author@example.com> |
| 632 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 633 | |
| 634 | 6th |
| 635 | |
| 636 | Notes: |
| 637 | order test |
| 638 | |
| 639 | Notes (other): |
| 640 | other note |
| 641 | |
| 642 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 643 | Author: A U Thor <author@example.com> |
| 644 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 645 | |
| 646 | 5th |
| 647 | |
| 648 | Notes: |
| 649 | replacement for deleted note |
| 650 | EOF |
| 651 | |
| 652 | test_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 | |
| 662 | test_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 | |
| 669 | test_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 | |
| 677 | cat > expect-both-reversed << EOF |
| 678 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 679 | Author: A U Thor <author@example.com> |
| 680 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 681 | |
| 682 | 6th |
| 683 | |
| 684 | Notes (other): |
| 685 | other note |
| 686 | |
| 687 | Notes: |
| 688 | order test |
| 689 | EOF |
| 690 | |
| 691 | test_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 | |
| 699 | test_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 | |
| 707 | cat > expect-none << EOF |
| 708 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 709 | Author: A U Thor <author@example.com> |
| 710 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 711 | |
| 712 | 6th |
| 713 | |
| 714 | commit bd1753200303d0a0344be813e504253b3d98e74d |
| 715 | Author: A U Thor <author@example.com> |
| 716 | Date: Thu Apr 7 15:17:13 2005 -0700 |
| 717 | |
| 718 | 5th |
| 719 | EOF |
| 720 | |
| 721 | test_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 | |
| 727 | test_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 | |
| 732 | cat > expect-commits << EOF |
| 733 | commit 387a89921c73d7ed72cd94d179c1c7048ca47756 |
| 734 | Author: A U Thor <author@example.com> |
| 735 | Date: Thu Apr 7 15:18:13 2005 -0700 |
| 736 | |
| 737 | 6th |
| 738 | |
| 739 | Notes: |
| 740 | order test |
| 741 | EOF |
| 742 | |
| 743 | test_expect_success '--no-standard-notes' ' |
| 744 | git log --no-standard-notes --show-notes=commits -1 > output && |
| 745 | test_cmp expect-commits output |
| 746 | ' |
| 747 | |
| 748 | test_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 | |
| 754 | test_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 | |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 760 | test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 761 | git config core.notesRef refs/notes/other && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 762 | echo "Note on a tree" > expect && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 763 | git notes add -m "Note on a tree" HEAD: && |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 764 | git notes show HEAD: > actual && |
| 765 | test_cmp expect actual && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 766 | echo "Note on a blob" > expect && |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 767 | filename=$(git ls-tree --name-only HEAD | head -n1) && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 768 | git notes add -m "Note on a blob" HEAD:$filename && |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 769 | git notes show HEAD:$filename > actual && |
| 770 | test_cmp expect actual && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 771 | echo "Note on a tag" > expect && |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 772 | git tag -a -m "This is an annotated tag" foobar HEAD^ && |
Johan Herland | 7aa4754 | 2010-02-13 22:28:32 +0100 | [diff] [blame] | 773 | git notes add -m "Note on a tag" foobar && |
Johan Herland | b24bb99 | 2010-02-13 22:28:21 +0100 | [diff] [blame] | 774 | git notes show foobar > actual && |
| 775 | test_cmp expect actual |
| 776 | ' |
| 777 | |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 778 | cat > expect << EOF |
| 779 | commit 2ede89468182a62d0bde2583c736089bcf7d7e92 |
| 780 | Author: A U Thor <author@example.com> |
| 781 | Date: Thu Apr 7 15:19:13 2005 -0700 |
| 782 | |
| 783 | 7th |
| 784 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 785 | Notes (other): |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 786 | other note |
| 787 | EOF |
| 788 | |
| 789 | test_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 | |
| 800 | test_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 | |
| 809 | cat > expect << EOF |
| 810 | commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b |
| 811 | Author: A U Thor <author@example.com> |
| 812 | Date: Thu Apr 7 15:21:13 2005 -0700 |
| 813 | |
| 814 | 9th |
| 815 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 816 | Notes (other): |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 817 | yet another note |
| 818 | EOF |
| 819 | |
| 820 | test_expect_success 'create note from other note with "git notes add -c"' ' |
| 821 | : > a9 && |
| 822 | git add a9 && |
| 823 | test_tick && |
| 824 | git commit -m 9th && |
| 825 | MSG="yet another note" git notes add -c $(git notes list HEAD^^) && |
| 826 | git log -1 > actual && |
| 827 | test_cmp expect actual |
| 828 | ' |
| 829 | |
| 830 | test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' |
| 831 | : > a10 && |
| 832 | git add a10 && |
| 833 | test_tick && |
| 834 | git commit -m 10th && |
David Tran | 512477b | 2014-03-18 18:54:05 +0000 | [diff] [blame^] | 835 | test_must_fail env MSG="yet another note" git notes add -c deadbeef && |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 836 | test_must_fail git notes list HEAD |
| 837 | ' |
| 838 | |
| 839 | cat > expect << EOF |
| 840 | commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b |
| 841 | Author: A U Thor <author@example.com> |
| 842 | Date: Thu Apr 7 15:21:13 2005 -0700 |
| 843 | |
| 844 | 9th |
| 845 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 846 | Notes (other): |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 847 | yet another note |
| 848 | $whitespace |
| 849 | yet another note |
| 850 | EOF |
| 851 | |
| 852 | test_expect_success 'append to note from other note with "git notes append -C"' ' |
| 853 | git notes append -C $(git notes list HEAD^) HEAD^ && |
| 854 | git log -1 HEAD^ > actual && |
| 855 | test_cmp expect actual |
| 856 | ' |
| 857 | |
| 858 | cat > expect << EOF |
| 859 | commit ffed603236bfa3891c49644257a83598afe8ae5a |
| 860 | Author: A U Thor <author@example.com> |
| 861 | Date: Thu Apr 7 15:22:13 2005 -0700 |
| 862 | |
| 863 | 10th |
| 864 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 865 | Notes (other): |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 866 | other note |
| 867 | EOF |
| 868 | |
| 869 | test_expect_success 'create note from other note with "git notes append -c"' ' |
| 870 | MSG="other note" git notes append -c $(git notes list HEAD^) && |
| 871 | git log -1 > actual && |
| 872 | test_cmp expect actual |
| 873 | ' |
| 874 | |
| 875 | cat > expect << EOF |
| 876 | commit ffed603236bfa3891c49644257a83598afe8ae5a |
| 877 | Author: A U Thor <author@example.com> |
| 878 | Date: Thu Apr 7 15:22:13 2005 -0700 |
| 879 | |
| 880 | 10th |
| 881 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 882 | Notes (other): |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 883 | other note |
| 884 | $whitespace |
| 885 | yet another note |
| 886 | EOF |
| 887 | |
| 888 | test_expect_success 'append to note from other note with "git notes append -c"' ' |
| 889 | MSG="yet another note" git notes append -c $(git notes list HEAD) && |
| 890 | git log -1 > actual && |
| 891 | test_cmp expect actual |
| 892 | ' |
| 893 | |
Johan Herland | e73bbd9 | 2010-02-13 22:28:38 +0100 | [diff] [blame] | 894 | cat > expect << EOF |
| 895 | commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be |
| 896 | Author: A U Thor <author@example.com> |
| 897 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 898 | |
| 899 | 11th |
| 900 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 901 | Notes (other): |
Johan Herland | e73bbd9 | 2010-02-13 22:28:38 +0100 | [diff] [blame] | 902 | other note |
| 903 | $whitespace |
| 904 | yet another note |
| 905 | EOF |
| 906 | |
| 907 | test_expect_success 'copy note with "git notes copy"' ' |
| 908 | : > a11 && |
| 909 | git add a11 && |
| 910 | test_tick && |
| 911 | git commit -m 11th && |
| 912 | git notes copy HEAD^ HEAD && |
| 913 | git log -1 > actual && |
| 914 | test_cmp expect actual && |
| 915 | test "$(git notes list HEAD)" = "$(git notes list HEAD^)" |
| 916 | ' |
| 917 | |
| 918 | test_expect_success 'prevent overwrite with "git notes copy"' ' |
| 919 | test_must_fail git notes copy HEAD~2 HEAD && |
| 920 | git log -1 > actual && |
| 921 | test_cmp expect actual && |
| 922 | test "$(git notes list HEAD)" = "$(git notes list HEAD^)" |
| 923 | ' |
| 924 | |
| 925 | cat > expect << EOF |
| 926 | commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be |
| 927 | Author: A U Thor <author@example.com> |
| 928 | Date: Thu Apr 7 15:23:13 2005 -0700 |
| 929 | |
| 930 | 11th |
| 931 | |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 932 | Notes (other): |
Johan Herland | e73bbd9 | 2010-02-13 22:28:38 +0100 | [diff] [blame] | 933 | yet another note |
| 934 | $whitespace |
| 935 | yet another note |
| 936 | EOF |
| 937 | |
| 938 | test_expect_success 'allow overwrite with "git notes copy -f"' ' |
| 939 | git notes copy -f HEAD~2 HEAD && |
| 940 | git log -1 > actual && |
| 941 | test_cmp expect actual && |
| 942 | test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" |
| 943 | ' |
| 944 | |
| 945 | test_expect_success 'cannot copy note from object without notes' ' |
| 946 | : > a12 && |
| 947 | git add a12 && |
| 948 | test_tick && |
| 949 | git commit -m 12th && |
| 950 | : > a13 && |
| 951 | git add a13 && |
| 952 | test_tick && |
| 953 | git commit -m 13th && |
| 954 | test_must_fail git notes copy HEAD^ HEAD |
| 955 | ' |
| 956 | |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 957 | cat > expect << EOF |
| 958 | commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 |
| 959 | Author: A U Thor <author@example.com> |
| 960 | Date: Thu Apr 7 15:25:13 2005 -0700 |
| 961 | |
| 962 | 13th |
| 963 | |
| 964 | Notes (other): |
| 965 | yet another note |
| 966 | $whitespace |
| 967 | yet another note |
| 968 | |
| 969 | commit 7038787dfe22a14c3867ce816dbba39845359719 |
| 970 | Author: A U Thor <author@example.com> |
| 971 | Date: Thu Apr 7 15:24:13 2005 -0700 |
| 972 | |
| 973 | 12th |
| 974 | |
| 975 | Notes (other): |
| 976 | other note |
| 977 | $whitespace |
| 978 | yet another note |
| 979 | EOF |
| 980 | |
| 981 | test_expect_success 'git notes copy --stdin' ' |
| 982 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ |
| 983 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
| 984 | git notes copy --stdin && |
| 985 | git log -2 > output && |
| 986 | test_cmp expect output && |
| 987 | test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && |
| 988 | test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" |
| 989 | ' |
| 990 | |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 991 | cat > expect << EOF |
| 992 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 993 | Author: A U Thor <author@example.com> |
| 994 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 995 | |
| 996 | 15th |
| 997 | |
| 998 | commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d |
| 999 | Author: A U Thor <author@example.com> |
| 1000 | Date: Thu Apr 7 15:26:13 2005 -0700 |
| 1001 | |
| 1002 | 14th |
| 1003 | EOF |
| 1004 | |
| 1005 | test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' |
| 1006 | test_commit 14th && |
| 1007 | test_commit 15th && |
| 1008 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ |
| 1009 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
| 1010 | git notes copy --for-rewrite=foo && |
| 1011 | git log -2 > output && |
| 1012 | test_cmp expect output |
| 1013 | ' |
| 1014 | |
| 1015 | cat > expect << EOF |
| 1016 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1017 | Author: A U Thor <author@example.com> |
| 1018 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1019 | |
| 1020 | 15th |
| 1021 | |
| 1022 | Notes (other): |
| 1023 | yet another note |
| 1024 | $whitespace |
| 1025 | yet another note |
| 1026 | |
| 1027 | commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d |
| 1028 | Author: A U Thor <author@example.com> |
| 1029 | Date: Thu Apr 7 15:26:13 2005 -0700 |
| 1030 | |
| 1031 | 14th |
| 1032 | |
| 1033 | Notes (other): |
| 1034 | other note |
| 1035 | $whitespace |
| 1036 | yet another note |
| 1037 | EOF |
| 1038 | |
| 1039 | test_expect_success 'git notes copy --for-rewrite (enabled)' ' |
| 1040 | git config notes.rewriteMode overwrite && |
| 1041 | git config notes.rewriteRef "refs/notes/*" && |
| 1042 | (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ |
| 1043 | echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | |
| 1044 | git notes copy --for-rewrite=foo && |
| 1045 | git log -2 > output && |
| 1046 | test_cmp expect output |
| 1047 | ' |
| 1048 | |
| 1049 | test_expect_success 'git notes copy --for-rewrite (disabled)' ' |
| 1050 | git config notes.rewrite.bar false && |
| 1051 | echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | |
| 1052 | git notes copy --for-rewrite=bar && |
| 1053 | git log -2 > output && |
| 1054 | test_cmp expect output |
| 1055 | ' |
| 1056 | |
| 1057 | cat > expect << EOF |
| 1058 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1059 | Author: A U Thor <author@example.com> |
| 1060 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1061 | |
| 1062 | 15th |
| 1063 | |
| 1064 | Notes (other): |
| 1065 | a fresh note |
| 1066 | EOF |
| 1067 | |
| 1068 | test_expect_success 'git notes copy --for-rewrite (overwrite)' ' |
| 1069 | git notes add -f -m"a fresh note" HEAD^ && |
| 1070 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1071 | git notes copy --for-rewrite=foo && |
| 1072 | git log -1 > output && |
| 1073 | test_cmp expect output |
| 1074 | ' |
| 1075 | |
| 1076 | test_expect_success 'git notes copy --for-rewrite (ignore)' ' |
| 1077 | git config notes.rewriteMode ignore && |
| 1078 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1079 | git notes copy --for-rewrite=foo && |
| 1080 | git log -1 > output && |
| 1081 | test_cmp expect output |
| 1082 | ' |
| 1083 | |
| 1084 | cat > expect << EOF |
| 1085 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1086 | Author: A U Thor <author@example.com> |
| 1087 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1088 | |
| 1089 | 15th |
| 1090 | |
| 1091 | Notes (other): |
| 1092 | a fresh note |
Johan Herland | d4990c4 | 2010-11-09 22:49:44 +0100 | [diff] [blame] | 1093 | $whitespace |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 1094 | another fresh note |
| 1095 | EOF |
| 1096 | |
| 1097 | test_expect_success 'git notes copy --for-rewrite (append)' ' |
| 1098 | git notes add -f -m"another fresh note" HEAD^ && |
| 1099 | git config notes.rewriteMode concatenate && |
| 1100 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1101 | git notes copy --for-rewrite=foo && |
| 1102 | git log -1 > output && |
| 1103 | test_cmp expect output |
| 1104 | ' |
| 1105 | |
| 1106 | cat > expect << EOF |
| 1107 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1108 | Author: A U Thor <author@example.com> |
| 1109 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1110 | |
| 1111 | 15th |
| 1112 | |
| 1113 | Notes (other): |
| 1114 | a fresh note |
Johan Herland | d4990c4 | 2010-11-09 22:49:44 +0100 | [diff] [blame] | 1115 | $whitespace |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 1116 | another fresh note |
Johan Herland | d4990c4 | 2010-11-09 22:49:44 +0100 | [diff] [blame] | 1117 | $whitespace |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 1118 | append 1 |
Johan Herland | d4990c4 | 2010-11-09 22:49:44 +0100 | [diff] [blame] | 1119 | $whitespace |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 1120 | append 2 |
| 1121 | EOF |
| 1122 | |
| 1123 | test_expect_success 'git notes copy --for-rewrite (append two to one)' ' |
| 1124 | git notes add -f -m"append 1" HEAD^ && |
| 1125 | git notes add -f -m"append 2" HEAD^^ && |
| 1126 | (echo $(git rev-parse HEAD^) $(git rev-parse HEAD); |
| 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 | |
| 1133 | test_expect_success 'git notes copy --for-rewrite (append empty)' ' |
| 1134 | git notes remove HEAD^ && |
| 1135 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1136 | git notes copy --for-rewrite=foo && |
| 1137 | git log -1 > output && |
| 1138 | test_cmp expect output |
| 1139 | ' |
| 1140 | |
| 1141 | cat > expect << EOF |
| 1142 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1143 | Author: A U Thor <author@example.com> |
| 1144 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1145 | |
| 1146 | 15th |
| 1147 | |
| 1148 | Notes (other): |
| 1149 | replacement note 1 |
| 1150 | EOF |
| 1151 | |
| 1152 | test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' |
| 1153 | git notes add -f -m"replacement note 1" HEAD^ && |
| 1154 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1155 | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && |
| 1156 | git log -1 > output && |
| 1157 | test_cmp expect output |
| 1158 | ' |
| 1159 | |
| 1160 | cat > expect << EOF |
| 1161 | commit 37a0d4cba38afef96ba54a3ea567e6dac575700b |
| 1162 | Author: A U Thor <author@example.com> |
| 1163 | Date: Thu Apr 7 15:27:13 2005 -0700 |
| 1164 | |
| 1165 | 15th |
| 1166 | |
| 1167 | Notes (other): |
| 1168 | replacement note 2 |
| 1169 | EOF |
| 1170 | |
| 1171 | test_expect_success 'GIT_NOTES_REWRITE_REF works' ' |
| 1172 | git config notes.rewriteMode overwrite && |
| 1173 | git notes add -f -m"replacement note 2" HEAD^ && |
| 1174 | git config --unset-all notes.rewriteRef && |
| 1175 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1176 | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ |
| 1177 | git notes copy --for-rewrite=foo && |
| 1178 | git log -1 > output && |
| 1179 | test_cmp expect output |
| 1180 | ' |
| 1181 | |
| 1182 | test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' |
| 1183 | git config notes.rewriteRef refs/notes/other && |
| 1184 | git notes add -f -m"replacement note 3" HEAD^ && |
| 1185 | echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | |
| 1186 | GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo && |
| 1187 | git log -1 > output && |
| 1188 | test_cmp expect output |
| 1189 | ' |
Jeff King | bbb1b8a | 2010-06-28 04:59:07 -0400 | [diff] [blame] | 1190 | |
| 1191 | test_expect_success 'git notes copy diagnoses too many or too few parameters' ' |
| 1192 | test_must_fail git notes copy && |
| 1193 | test_must_fail git notes copy one two three |
| 1194 | ' |
| 1195 | |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 1196 | test_expect_success 'git notes get-ref (no overrides)' ' |
| 1197 | git config --unset core.notesRef && |
Brandon Casey | ed40ec5 | 2011-01-05 18:30:02 -0600 | [diff] [blame] | 1198 | sane_unset GIT_NOTES_REF && |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 1199 | test "$(git notes get-ref)" = "refs/notes/commits" |
| 1200 | ' |
| 1201 | |
| 1202 | test_expect_success 'git notes get-ref (core.notesRef)' ' |
| 1203 | git config core.notesRef refs/notes/foo && |
| 1204 | test "$(git notes get-ref)" = "refs/notes/foo" |
| 1205 | ' |
| 1206 | |
| 1207 | test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' |
| 1208 | test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" |
| 1209 | ' |
| 1210 | |
| 1211 | test_expect_success 'git notes get-ref (--ref)' ' |
| 1212 | test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" |
| 1213 | ' |
| 1214 | |
Johannes Schindelin | 65d9fb4 | 2009-10-09 12:21:58 +0200 | [diff] [blame] | 1215 | test_done |