]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3301-notes.sh
Builtin-ify git-notes
[thirdparty/git.git] / t / t3301-notes.sh
CommitLineData
65d9fb48
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test commit notes'
7
8. ./test-lib.sh
9
10cat > fake_editor.sh << \EOF
11echo "$MSG" > "$1"
12echo "$MSG" >& 2
13EOF
14chmod a+x fake_editor.sh
cd067d3b
JH
15GIT_EDITOR=./fake_editor.sh
16export GIT_EDITOR
65d9fb48
JS
17
18test_expect_success 'cannot annotate non-existing HEAD' '
19 (MSG=3 && export MSG && test_must_fail git notes edit)
20'
21
22test_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
33test_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
40test_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
46test_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
53test_expect_success 'handle empty notes gracefully' '
54 git notes show ; test 1 = $?
55'
56
57test_expect_success 'create notes' '
58 git config core.notesRef refs/notes/commits &&
cd067d3b
JH
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
67test_expect_success 'edit existing notes' '
65d9fb48 68 MSG=b1 git notes edit &&
cd067d3b 69 test ! -f .git/NOTES_EDITMSG &&
65d9fb48
JS
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
76cat > expect << EOF
77commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
78Author: A U Thor <author@example.com>
79Date: Thu Apr 7 15:14:13 2005 -0700
80
81 2nd
82
83Notes:
84 b1
85EOF
86
87test_expect_success 'show notes' '
88 ! (git cat-file commit HEAD | grep b1) &&
89 git log -1 > output &&
90 test_cmp expect output
91'
92test_expect_success 'create multi-line notes (setup)' '
93 : > a3 &&
94 git add a3 &&
95 test_tick &&
96 git commit -m 3rd &&
97 MSG="b3
98c3c3c3c3
99d3d3d3" git notes edit
100'
101
102cat > expect-multiline << EOF
103commit 1584215f1d29c65e99c6c6848626553fdd07fd75
104Author: A U Thor <author@example.com>
105Date: Thu Apr 7 15:15:13 2005 -0700
106
107 3rd
108
109Notes:
110 b3
111 c3c3c3c3
112 d3d3d3
113EOF
114
115printf "\n" >> expect-multiline
116cat expect >> expect-multiline
117
118test_expect_success 'show multi-line notes' '
119 git log -2 > output &&
120 test_cmp expect-multiline output
121'
cd067d3b 122test_expect_success 'create -F notes (setup)' '
d9246d43
JH
123 : > a4 &&
124 git add a4 &&
125 test_tick &&
126 git commit -m 4th &&
127 echo "xyzzy" > note5 &&
cd067d3b 128 git notes edit -F note5
d9246d43
JH
129'
130
cd067d3b 131cat > expect-F << EOF
d9246d43
JH
132commit 15023535574ded8b1a89052b32673f84cf9582b8
133Author: A U Thor <author@example.com>
134Date: Thu Apr 7 15:16:13 2005 -0700
135
136 4th
137
138Notes:
d9246d43 139 xyzzy
d9246d43
JH
140EOF
141
cd067d3b
JH
142printf "\n" >> expect-F
143cat expect-multiline >> expect-F
d9246d43 144
cd067d3b 145test_expect_success 'show -F notes' '
d9246d43 146 git log -3 > output &&
cd067d3b 147 test_cmp expect-F output
d9246d43 148'
65d9fb48 149
66b2ed09
JH
150cat >expect << EOF
151commit 15023535574ded8b1a89052b32673f84cf9582b8
152tree e070e3af51011e47b183c33adf9736736a525709
153parent 1584215f1d29c65e99c6c6848626553fdd07fd75
154author A U Thor <author@example.com> 1112912173 -0700
155committer C O Mitter <committer@example.com> 1112912173 -0700
156
157 4th
158EOF
159test_expect_success 'git log --pretty=raw does not show notes' '
160 git log -1 --pretty=raw >output &&
161 test_cmp expect output
162'
163
164cat >>expect <<EOF
165
166Notes:
66b2ed09 167 xyzzy
66b2ed09
JH
168EOF
169test_expect_success 'git log --show-notes' '
170 git log -1 --pretty=raw --show-notes >output &&
171 test_cmp expect output
172'
173
174test_expect_success 'git log --no-notes' '
175 git log -1 --no-notes >output &&
cd067d3b 176 ! grep xyzzy output
66b2ed09
JH
177'
178
179test_expect_success 'git format-patch does not show notes' '
180 git format-patch -1 --stdout >output &&
cd067d3b 181 ! grep xyzzy output
66b2ed09
JH
182'
183
184test_expect_success 'git format-patch --show-notes does show notes' '
185 git format-patch --show-notes -1 --stdout >output &&
cd067d3b 186 grep xyzzy output
66b2ed09
JH
187'
188
7dccadf3
JH
189for pretty in \
190 "" --pretty --pretty=raw --pretty=short --pretty=medium \
191 --pretty=full --pretty=fuller --pretty=format:%s --oneline
66b2ed09
JH
192do
193 case "$pretty" in
194 "") p= not= negate="" ;;
7dccadf3 195 ?*) p="$pretty" not=" not" negate="!" ;;
66b2ed09
JH
196 esac
197 test_expect_success "git show $pretty does$not show notes" '
198 git show $p >output &&
cd067d3b 199 eval "$negate grep xyzzy output"
66b2ed09
JH
200 '
201done
202
cd067d3b 203test_expect_success 'create -m notes (setup)' '
3b78cdbe
JH
204 : > a5 &&
205 git add a5 &&
206 test_tick &&
207 git commit -m 5th &&
cd067d3b
JH
208 git notes edit -m spam -m "foo
209bar
210baz"
3b78cdbe
JH
211'
212
cd067d3b
JH
213whitespace=" "
214cat > expect-m << EOF
3b78cdbe
JH
215commit bd1753200303d0a0344be813e504253b3d98e74d
216Author: A U Thor <author@example.com>
217Date: Thu Apr 7 15:17:13 2005 -0700
218
219 5th
220
cd067d3b
JH
221Notes:
222 spam
223$whitespace
224 foo
225 bar
226 baz
227EOF
228
229printf "\n" >> expect-m
230cat expect-F >> expect-m
231
232test_expect_success 'show -m notes' '
233 git log -4 > output &&
234 test_cmp expect-m output
235'
236
237test_expect_success 'create other note on a different notes ref (setup)' '
238 : > a6 &&
239 git add a6 &&
240 test_tick &&
241 git commit -m 6th &&
242 GIT_NOTES_REF="refs/notes/other" git notes edit -m "other note"
243'
244
245cat > expect-other << EOF
246commit 387a89921c73d7ed72cd94d179c1c7048ca47756
247Author: A U Thor <author@example.com>
248Date: Thu Apr 7 15:18:13 2005 -0700
249
250 6th
251
3b78cdbe
JH
252Notes:
253 other note
254EOF
255
256cat > expect-not-other << EOF
cd067d3b 257commit 387a89921c73d7ed72cd94d179c1c7048ca47756
3b78cdbe 258Author: A U Thor <author@example.com>
cd067d3b 259Date: Thu Apr 7 15:18:13 2005 -0700
3b78cdbe 260
cd067d3b 261 6th
3b78cdbe
JH
262EOF
263
264test_expect_success 'Do not show note on other ref by default' '
265 git log -1 > output &&
266 test_cmp expect-not-other output
267'
268
269test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
270 GIT_NOTES_REF="refs/notes/other" git log -1 > output &&
271 test_cmp expect-other output
272'
273
274test_expect_success 'Do show note when ref is given in core.notesRef config' '
275 git config core.notesRef "refs/notes/other" &&
276 git log -1 > output &&
277 test_cmp expect-other output
278'
279
280test_expect_success 'Do not show note when core.notesRef is overridden' '
281 GIT_NOTES_REF="refs/notes/wrong" git log -1 > output &&
282 test_cmp expect-not-other output
283'
284
65d9fb48 285test_done