3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='Test commit notes'
10 cat > fake_editor.sh
<< \EOF
14 chmod a
+x fake_editor.sh
15 GIT_EDITOR
=.
/fake_editor.sh
18 test_expect_success
'cannot annotate non-existing HEAD' '
19 (MSG=3 && export MSG && test_must_fail git notes edit)
22 test_expect_success setup
'
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)
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)
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)
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 = $?
57 test_expect_success
'create notes' '
58 git config core.notesRef refs/notes/commits &&
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) &&
64 test_must_fail git notes show HEAD^
67 test_expect_success
'edit existing notes' '
68 MSG=b1 git notes edit &&
69 test ! -f .git/NOTES_EDITMSG &&
70 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
71 test b1 = $(git notes show) &&
73 test_must_fail git notes show HEAD^
77 commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
78 Author: A U Thor <author@example.com>
79 Date: Thu Apr 7 15:14:13 2005 -0700
87 test_expect_success
'show notes' '
88 ! (git cat-file commit HEAD | grep b1) &&
89 git log -1 > output &&
90 test_cmp expect output
92 test_expect_success
'create multi-line notes (setup)' '
99 d3d3d3" git notes edit
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
115 printf "\n" >> expect-multiline
116 cat expect
>> expect-multiline
118 test_expect_success
'show multi-line notes' '
119 git log -2 > output &&
120 test_cmp expect-multiline output
122 test_expect_success
'create -F notes (setup)' '
127 echo "xyzzy" > note5 &&
128 git notes edit -F note5
131 cat > expect-F
<< EOF
132 commit 15023535574ded8b1a89052b32673f84cf9582b8
133 Author: A U Thor <author@example.com>
134 Date: Thu Apr 7 15:16:13 2005 -0700
142 printf "\n" >> expect-F
143 cat expect-multiline
>> expect-F
145 test_expect_success
'show -F notes' '
146 git log -3 > output &&
147 test_cmp expect-F output
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
159 test_expect_success
'git log --pretty=raw does not show notes' '
160 git log -1 --pretty=raw >output &&
161 test_cmp expect output
169 test_expect_success
'git log --show-notes' '
170 git log -1 --pretty=raw --show-notes >output &&
171 test_cmp expect output
174 test_expect_success
'git log --no-notes' '
175 git log -1 --no-notes >output &&
179 test_expect_success
'git format-patch does not show notes' '
180 git format-patch -1 --stdout >output &&
184 test_expect_success
'git format-patch --show-notes does show notes' '
185 git format-patch --show-notes -1 --stdout >output &&
190 "" --pretty --pretty=raw
--pretty=short
--pretty=medium \
191 --pretty=full
--pretty=fuller
--pretty=format
:%s
--oneline
194 "") p
= not
= negate
="" ;;
195 ?
*) p
="$pretty" not
=" not" negate
="!" ;;
197 test_expect_success
"git show $pretty does$not show notes" '
198 git show $p >output &&
199 eval "$negate grep xyzzy output"
203 test_expect_success
'create -m notes (setup)' '
208 git notes edit -m spam -m "foo
214 cat > expect-m
<< EOF
215 commit bd1753200303d0a0344be813e504253b3d98e74d
216 Author: A U Thor <author@example.com>
217 Date: Thu Apr 7 15:17:13 2005 -0700
229 printf "\n" >> expect-m
230 cat expect-F
>> expect-m
232 test_expect_success
'show -m notes' '
233 git log -4 > output &&
234 test_cmp expect-m output
237 test_expect_success
'remove note with -F /dev/null (setup)' '
238 git notes edit -F /dev/null
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
249 printf "\n" >> expect-rm-F
250 cat expect-F
>> expect-rm-F
252 test_expect_success
'verify note removal with -F /dev/null' '
253 git log -4 > output &&
254 test_cmp expect-rm-F output &&
258 test_expect_success
'do not create empty note with -m "" (setup)' '
262 test_expect_success
'verify non-creation of note with -m ""' '
263 git log -4 > output &&
264 test_cmp expect-rm-F output &&
268 test_expect_success
'remove note with "git notes remove" (setup)' '
269 git notes remove HEAD^
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
279 commit 15023535574ded8b1a89052b32673f84cf9582b8
280 Author: A U Thor <author@example.com>
281 Date: Thu Apr 7 15:16:13 2005 -0700
286 printf "\n" >> expect-rm-remove
287 cat expect-multiline
>> expect-rm-remove
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^
295 test_expect_success
'create other note on a different notes ref (setup)' '
300 GIT_NOTES_REF="refs/notes/other" git notes edit -m "other note"
303 cat > expect-other
<< EOF
304 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
305 Author: A U Thor <author@example.com>
306 Date: Thu Apr 7 15:18:13 2005 -0700
314 cat > expect-not-other
<< EOF
315 commit 387a89921c73d7ed72cd94d179c1c7048ca47756
316 Author: A U Thor <author@example.com>
317 Date: Thu Apr 7 15:18:13 2005 -0700
322 test_expect_success
'Do not show note on other ref by default' '
323 git log -1 > output &&
324 test_cmp expect-not-other output
327 test_expect_success
'Do show note when ref is given in GIT_NOTES_REF' '
328 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
329 test_cmp expect-other output
332 test_expect_success
'Do show note when ref is given in core.notesRef config' '
333 git config core.notesRef "refs/notes/other" &&
334 git log -1 > output &&
335 test_cmp expect-other output
338 test_expect_success
'Do not show note when core.notesRef is overridden' '
339 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
340 test_cmp expect-not-other output
343 test_expect_success
'Allow notes on non-commits (trees, blobs, tags)' '
344 echo "Note on a tree" > expect
345 git notes edit -m "Note on a tree" HEAD: &&
346 git notes show HEAD: > actual &&
347 test_cmp expect actual &&
348 echo "Note on a blob" > expect
349 filename=$(git ls-tree --name-only HEAD | head -n1) &&
350 git notes edit -m "Note on a blob" HEAD:$filename &&
351 git notes show HEAD:$filename > actual &&
352 test_cmp expect actual &&
353 echo "Note on a tag" > expect
354 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
355 git notes edit -m "Note on a tag" foobar &&
356 git notes show foobar > actual &&
357 test_cmp expect actual