t3301: modernize style

Make this test script appear somewhat less old-fashioned: - Use test helper functions: - write_script - test_commit - test_write_lines - test_line_count - test_config - test_unconfig - test_path_is_missing - Remove whitespace between redirection operators and their targets. - Move preparation of "expect" files into tests. - Rename "output" files to "actual". - More consistent quoting, especially around commands that might expand to nothing. - More visibility of important whitespace with ${indent}. - Combine pairs of tests that unnecessarily split setup and verification. Improved-by: Eric Sunshine <sunshine@sunshineco.com> Improved-by: Junio C Hamano <gitster@pobox.com> Improved-by: Michael Blume <blume.mike@gmail.com> Improved-by: Jeff King <peff@peff.net> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johan Herland committed Nov 12, 2014 at 01:40 UTC 908a3203632a02568df230c0fccf9a2cd8da24e6
1 file changed +601 -699
t/t3301-notes.sh
+601 -699
@@ -7,28 +7,22 @@ test_description='Test commit notes'
7
8 . ./test-lib.sh
9
10 -cat > fake_editor.sh << \EOF
11 -#!/bin/sh
12 -echo "$MSG" > "$1"
13 -echo "$MSG" >& 2
10 +write_script fake_editor <<\EOF
11 +echo "$MSG" >"$1"
12 +echo "$MSG" >&2
13 EOF
15 -chmod a+x fake_editor.sh
16 -GIT_EDITOR=./fake_editor.sh
14 +GIT_EDITOR=./fake_editor
15 export GIT_EDITOR
16
17 +indent=" "
18 +
19 test_expect_success 'cannot annotate non-existing HEAD' '
20 test_must_fail env MSG=3 git notes add
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
23 +test_expect_success 'setup' '
24 + test_commit 1st &&
25 + test_commit 2nd
26 '
27
28 test_expect_success 'need valid notes ref' '
@@ -50,206 +44,186 @@ test_expect_success 'handle empty notes gracefully' '
44 '
45
46 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
47 + test_write_lines A B >expect &&
48 + git show -s --format="A%n%NB" >actual &&
49 + test_cmp expect actual
50 '
51
52 test_expect_success 'create notes' '
62 - git config core.notesRef refs/notes/commits &&
53 MSG=b4 git notes add &&
64 - test ! -f .git/NOTES_EDITMSG &&
65 - test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
66 - test b4 = $(git notes show) &&
54 + test_path_is_missing .git/NOTES_EDITMSG &&
55 + git ls-tree -r refs/notes/commits >actual &&
56 + test_line_count = 1 actual &&
57 + test "b4" = "$(git notes show)" &&
58 git show HEAD^ &&
59 test_must_fail git notes show HEAD^
60 '
61
62 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
63 + test_write_lines A b4 B >expect &&
64 + git show -s --format="A%n%NB" >actual &&
65 + test_cmp expect actual
66 '
67
80 -cat >expect <<EOF
81 -d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add'
82 -EOF
83 -
68 test_expect_success 'create reflog entry' '
85 - git reflog show refs/notes/commits >output &&
86 - test_cmp expect output
69 + cat <<-EOF >expect &&
70 + a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
71 + EOF
72 + git reflog show refs/notes/commits >actual &&
73 + test_cmp expect actual
74 '
75
76 test_expect_success 'edit existing notes' '
77 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) &&
78 + test_path_is_missing .git/NOTES_EDITMSG &&
79 + git ls-tree -r refs/notes/commits >actual &&
80 + test_line_count = 1 actual &&
81 + test "b3" = "$(git notes show)" &&
82 git show HEAD^ &&
83 test_must_fail git notes show HEAD^
84 '
85
86 test_expect_success 'cannot "git notes add -m" where notes already exists' '
87 test_must_fail git notes add -m "b2" &&
100 - test ! -f .git/NOTES_EDITMSG &&
101 - test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
102 - test b3 = $(git notes show) &&
88 + test_path_is_missing .git/NOTES_EDITMSG &&
89 + git ls-tree -r refs/notes/commits >actual &&
90 + test_line_count = 1 actual &&
91 + test "b3" = "$(git notes show)" &&
92 git show HEAD^ &&
93 test_must_fail git notes show HEAD^
94 '
95
96 test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
97 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) &&
98 + test_path_is_missing .git/NOTES_EDITMSG &&
99 + git ls-tree -r refs/notes/commits >actual &&
100 + test_line_count = 1 actual &&
101 + test "b1" = "$(git notes show)" &&
102 git show HEAD^ &&
103 test_must_fail git notes show HEAD^
104 '
105
106 test_expect_success 'add w/no options on existing note morphs into edit' '
107 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) &&
108 + test_path_is_missing .git/NOTES_EDITMSG &&
109 + git ls-tree -r refs/notes/commits >actual &&
110 + test_line_count = 1 actual &&
111 + test "b2" = "$(git notes show)" &&
112 git show HEAD^ &&
113 test_must_fail git notes show HEAD^
114 '
115
116 test_expect_success 'can overwrite existing note with "git notes add -f"' '
117 MSG=b1 git notes add -f &&
127 - test ! -f .git/NOTES_EDITMSG &&
128 - test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
129 - test b1 = $(git notes show) &&
118 + test_path_is_missing .git/NOTES_EDITMSG &&
119 + git ls-tree -r refs/notes/commits >actual &&
120 + test_line_count = 1 actual &&
121 + test "b1" = "$(git notes show)" &&
122 git show HEAD^ &&
123 test_must_fail git notes show HEAD^
124 '
125
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
126 +test_expect_success 'show notes' '
127 + cat >expect <<-EOF &&
128 + commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691
129 + Author: A U Thor <author@example.com>
130 + Date: Thu Apr 7 15:14:13 2005 -0700
131
141 -Notes:
142 - b1
143 -EOF
132 + ${indent}2nd
133
145 -test_expect_success 'show notes' '
134 + Notes:
135 + ${indent}b1
136 + EOF
137 ! (git cat-file commit HEAD | grep b1) &&
147 - git log -1 > output &&
148 - test_cmp expect output
149 -'
150 -
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
158 -d3d3d3" git notes add
138 + git log -1 >actual &&
139 + test_cmp expect actual
140 '
141
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
142 +test_expect_success 'show multi-line notes' '
143 + test_commit 3rd &&
144 + MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
145 + cat >expect-multiline <<-EOF &&
146 + commit d07d62e5208f22eb5695e7eb47667dc8b9860290
147 + Author: A U Thor <author@example.com>
148 + Date: Thu Apr 7 15:15:13 2005 -0700
149
168 -Notes:
169 - b3
170 - c3c3c3c3
171 - d3d3d3
172 -EOF
150 + ${indent}3rd
151
174 -printf "\n" >> expect-multiline
175 -cat expect >> expect-multiline
152 + Notes:
153 + ${indent}b3
154 + ${indent}c3c3c3c3
155 + ${indent}d3d3d3
156
177 -test_expect_success 'show multi-line notes' '
178 - git log -2 > output &&
179 - test_cmp expect-multiline output
157 + EOF
158 + cat expect >>expect-multiline &&
159 + git log -2 >actual &&
160 + test_cmp expect-multiline actual
161 '
181 -test_expect_success 'create -F notes (setup)' '
182 - : > a4 &&
183 - git add a4 &&
184 - test_tick &&
185 - git commit -m 4th &&
186 - echo "xyzzy" > note5 &&
187 - git notes add -F note5
188 -'
189 -
190 -cat > expect-F << EOF
191 -commit 15023535574ded8b1a89052b32673f84cf9582b8
192 -Author: A U Thor <author@example.com>
193 -Date: Thu Apr 7 15:16:13 2005 -0700
162
195 - 4th
163 +test_expect_success 'show -F notes' '
164 + test_commit 4th &&
165 + echo "xyzzy" >note5 &&
166 + git notes add -F note5 &&
167 + cat >expect-F <<-EOF &&
168 + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
169 + Author: A U Thor <author@example.com>
170 + Date: Thu Apr 7 15:16:13 2005 -0700
171
197 -Notes:
198 - xyzzy
199 -EOF
172 + ${indent}4th
173
201 -printf "\n" >> expect-F
202 -cat expect-multiline >> expect-F
174 + Notes:
175 + ${indent}xyzzy
176
204 -test_expect_success 'show -F notes' '
205 - git log -3 > output &&
206 - test_cmp expect-F output
177 + EOF
178 + cat expect-multiline >>expect-F &&
179 + git log -3 >actual &&
180 + test_cmp expect-F actual
181 '
182
183 test_expect_success 'Re-adding -F notes without -f fails' '
210 - echo "zyxxy" > note5 &&
184 + echo "zyxxy" >note5 &&
185 test_must_fail git notes add -F note5 &&
212 - git log -3 > output &&
213 - test_cmp expect-F output
186 + git log -3 >actual &&
187 + test_cmp expect-F actual
188 '
189
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
190 test_expect_success 'git log --pretty=raw does not show notes' '
226 - git log -1 --pretty=raw >output &&
227 - test_cmp expect output
191 + cat >expect <<-EOF &&
192 + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
193 + tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae
194 + parent d07d62e5208f22eb5695e7eb47667dc8b9860290
195 + author A U Thor <author@example.com> 1112912173 -0700
196 + committer C O Mitter <committer@example.com> 1112912173 -0700
197 +
198 + ${indent}4th
199 + EOF
200 + git log -1 --pretty=raw >actual &&
201 + test_cmp expect actual
202 '
203
230 -cat >>expect <<EOF
231 -
232 -Notes:
233 - xyzzy
234 -EOF
204 test_expect_success 'git log --show-notes' '
236 - git log -1 --pretty=raw --show-notes >output &&
237 - test_cmp expect output
205 + cat >>expect <<-EOF &&
206 +
207 + Notes:
208 + ${indent}xyzzy
209 + EOF
210 + git log -1 --pretty=raw --show-notes >actual &&
211 + test_cmp expect actual
212 '
213
214 test_expect_success 'git log --no-notes' '
241 - git log -1 --no-notes >output &&
242 - ! grep xyzzy output
215 + git log -1 --no-notes >actual &&
216 + ! grep xyzzy actual
217 '
218
219 test_expect_success 'git format-patch does not show notes' '
246 - git format-patch -1 --stdout >output &&
247 - ! grep xyzzy output
220 + git format-patch -1 --stdout >actual &&
221 + ! grep xyzzy actual
222 '
223
224 test_expect_success 'git format-patch --show-notes does show notes' '
251 - git format-patch --show-notes -1 --stdout >output &&
252 - grep xyzzy output
225 + git format-patch --show-notes -1 --stdout >actual &&
226 + grep xyzzy actual
227 '
228
229 for pretty in \
@@ -261,8 +235,8 @@ do
235 ?*) p="$pretty" not=" not" negate="!" ;;
236 esac
237 test_expect_success "git show $pretty does$not show notes" '
264 - git show $p >output &&
265 - eval "$negate grep xyzzy output"
238 + git show $p >actual &&
239 + eval "$negate grep xyzzy actual"
240 '
241 done
242
@@ -271,161 +245,131 @@ test_expect_success 'setup alternate notes ref' '
245 '
246
247 test_expect_success 'git log --notes shows default notes' '
274 - git log -1 --notes >output &&
275 - grep xyzzy output &&
276 - ! grep alternate output
248 + git log -1 --notes >actual &&
249 + grep xyzzy actual &&
250 + ! grep alternate actual
251 '
252
253 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
254 + git log -1 --notes=alternate >actual &&
255 + ! grep xyzzy actual &&
256 + grep alternate actual
257 '
258
259 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
260 + git log -1 --notes --notes=alternate >actual &&
261 + grep xyzzy actual &&
262 + grep alternate actual
263 '
264
265 test_expect_success 'git log --no-notes resets default state' '
266 git log -1 --notes --notes=alternate \
267 --no-notes --notes=alternate \
294 - >output &&
295 - ! grep xyzzy output &&
296 - grep alternate output
268 + >actual &&
269 + ! grep xyzzy actual &&
270 + grep alternate actual
271 '
272
273 test_expect_success 'git log --no-notes resets ref list' '
274 git log -1 --notes --notes=alternate \
275 --no-notes --notes \
302 - >output &&
303 - grep xyzzy output &&
304 - ! grep alternate output
305 -'
306 -
307 -test_expect_success 'create -m notes (setup)' '
308 - : > a5 &&
309 - git add a5 &&
310 - test_tick &&
311 - git commit -m 5th &&
312 - git notes add -m spam -m "foo
313 -bar
314 -baz"
315 -'
316 -
317 -whitespace=" "
318 -cat > expect-m << EOF
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:
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
276 + >actual &&
277 + grep xyzzy actual &&
278 + ! grep alternate actual
279 '
280
341 -test_expect_success 'remove note with add -f -F /dev/null (setup)' '
342 - git notes add -f -F /dev/null
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 &&
281 +test_expect_success 'show -m notes' '
282 + test_commit 5th &&
283 + git notes add -m spam -m "foo${LF}bar${LF}baz" &&
284 + cat >expect-m <<-EOF &&
285 + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
286 + Author: A U Thor <author@example.com>
287 + Date: Thu Apr 7 15:17:13 2005 -0700
288 +
289 + ${indent}5th
290 +
291 + Notes:
292 + ${indent}spam
293 + ${indent}
294 + ${indent}foo
295 + ${indent}bar
296 + ${indent}baz
297 +
298 + EOF
299 + cat expect-F >>expect-m &&
300 + git log -4 >actual &&
301 + test_cmp expect-m actual
302 +'
303 +
304 +test_expect_success 'remove note with add -f -F /dev/null' '
305 + git notes add -f -F /dev/null &&
306 + cat >expect-rm-F <<-EOF &&
307 + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
308 + Author: A U Thor <author@example.com>
309 + Date: Thu Apr 7 15:17:13 2005 -0700
310 +
311 + ${indent}5th
312 +
313 + EOF
314 + cat expect-F >>expect-rm-F &&
315 + git log -4 >actual &&
316 + test_cmp expect-rm-F actual &&
317 test_must_fail git notes show
318 '
319
362 -test_expect_success 'do not create empty note with -m "" (setup)' '
363 - git notes add -m ""
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 &&
320 +test_expect_success 'do not create empty note with -m ""' '
321 + git notes add -m "" &&
322 + git log -4 >actual &&
323 + test_cmp expect-rm-F actual &&
324 test_must_fail git notes show
325 '
326
372 -cat > expect-combine_m_and_F << EOF
373 -foo
374 -
375 -xyzzy
327 +test_expect_success 'create note with combination of -m and -F' '
328 + cat >expect-combine_m_and_F <<-EOF &&
329 + foo
330
377 -bar
331 + xyzzy
332
379 -zyxxy
333 + bar
334
381 -baz
382 -EOF
335 + zyxxy
336
384 -test_expect_success 'create note with combination of -m and -F' '
385 - echo "xyzzy" > note_a &&
386 - echo "zyxxy" > note_b &&
337 + baz
338 + EOF
339 + echo "xyzzy" >note_a &&
340 + echo "zyxxy" >note_b &&
341 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
342 + git notes show >actual &&
343 + test_cmp expect-combine_m_and_F actual
344 '
345
392 -test_expect_success 'remove note with "git notes remove" (setup)' '
346 +test_expect_success 'remove note with "git notes remove"' '
347 git notes remove HEAD^ &&
394 - git notes remove
395 -'
348 + git notes remove &&
349 + cat >expect-rm-remove <<-EOF &&
350 + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
351 + Author: A U Thor <author@example.com>
352 + Date: Thu Apr 7 15:17:13 2005 -0700
353
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
354 + ${indent}5th
355
402 - 5th
356 + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11
357 + Author: A U Thor <author@example.com>
358 + Date: Thu Apr 7 15:16:13 2005 -0700
359
404 -commit 15023535574ded8b1a89052b32673f84cf9582b8
405 -Author: A U Thor <author@example.com>
406 -Date: Thu Apr 7 15:16:13 2005 -0700
360 + ${indent}4th
361
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 &&
362 + EOF
363 + cat expect-multiline >>expect-rm-remove &&
364 + git log -4 >actual &&
365 + test_cmp expect-rm-remove actual &&
366 test_must_fail git notes show HEAD^
367 '
368
420 -cat > expect << EOF
421 -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
422 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
423 -EOF
424 -
369 test_expect_success 'removing non-existing note should not create new commit' '
426 - git rev-parse --verify refs/notes/commits > before_commit &&
370 + git rev-parse --verify refs/notes/commits >before_commit &&
371 test_must_fail git notes remove HEAD^ &&
428 - git rev-parse --verify refs/notes/commits > after_commit &&
372 + git rev-parse --verify refs/notes/commits >after_commit &&
373 test_cmp before_commit after_commit
374 '
375
@@ -505,70 +449,68 @@ test_expect_success 'removing with --stdin --ignore-missing' '
449 '
450
451 test_expect_success 'list notes with "git notes list"' '
508 - git notes list > output &&
509 - test_cmp expect output
452 + cat >expect <<-EOF &&
453 + c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
454 + c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
455 + EOF
456 + git notes list >actual &&
457 + test_cmp expect actual
458 '
459
460 test_expect_success 'list notes with "git notes"' '
513 - git notes > output &&
514 - test_cmp expect output
461 + git notes >actual &&
462 + test_cmp expect actual
463 '
464
517 -cat > expect << EOF
518 -c18dc024e14f08d18d14eea0d747ff692d66d6a3
519 -EOF
520 -
465 test_expect_success 'list specific note with "git notes list <object>"' '
522 - git notes list HEAD^^ > output &&
523 - test_cmp expect output
466 + cat >expect <<-EOF &&
467 + c18dc024e14f08d18d14eea0d747ff692d66d6a3
468 + EOF
469 + git notes list HEAD^^ >actual &&
470 + test_cmp expect actual
471 '
472
526 -cat > expect << EOF
527 -EOF
528 -
473 test_expect_success 'listing non-existing notes fails' '
530 - test_must_fail git notes list HEAD > output &&
531 - test_cmp expect output
474 + cat >expect <<-EOF &&
475 + EOF
476 + test_must_fail git notes list HEAD >actual &&
477 + test_cmp expect actual
478 '
479
534 -cat > expect << EOF
535 -Initial set of notes
536 -
537 -More notes appended with git notes append
538 -EOF
539 -
480 test_expect_success 'append to existing note with "git notes append"' '
481 + cat >expect <<-EOF &&
482 + Initial set of notes
483 +
484 + More notes appended with git notes append
485 + EOF
486 git notes add -m "Initial set of notes" &&
487 git notes append -m "More notes appended with git notes append" &&
543 - git notes show > output &&
544 - test_cmp expect output
488 + git notes show >actual &&
489 + test_cmp expect actual
490 '
491
547 -cat > expect_list << EOF
548 -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75
549 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5
550 -4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d
551 -EOF
552 -
492 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
493 + cat >expect_list <<-EOF &&
494 + c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691
495 + 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
496 + c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290
497 + EOF
498 + git notes list >actual &&
499 + test_cmp expect_list actual
500 '
501
502 test_expect_success 'appending empty string does not change existing note' '
503 git notes append -m "" &&
560 - git notes show > output &&
561 - test_cmp expect output
504 + git notes show >actual &&
505 + test_cmp expect actual
506 '
507
508 test_expect_success 'git notes append == add when there is no existing note' '
509 git notes remove HEAD &&
510 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
511 + git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
512 + git notes show >actual &&
513 + test_cmp expect actual
514 '
515
516 test_expect_success 'appending empty string to non-existing note does not create note' '
@@ -579,229 +521,208 @@ test_expect_success 'appending empty string to non-existing note does not create
521 '
522
523 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 &&
586 - GIT_NOTES_REF="refs/notes/other" git notes add -m "other note"
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
524 + test_commit 6th &&
525 + GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
526 + cat >expect-not-other <<-EOF &&
527 + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
528 + Author: A U Thor <author@example.com>
529 + Date: Thu Apr 7 15:18:13 2005 -0700
530
594 - 6th
531 + ${indent}6th
532 + EOF
533 + cp expect-not-other expect-other &&
534 + cat >>expect-other <<-EOF
535
596 -Notes (other):
597 - other note
598 -EOF
599 -
600 -cat > expect-not-other << EOF
601 -commit 387a89921c73d7ed72cd94d179c1c7048ca47756
602 -Author: A U Thor <author@example.com>
603 -Date: Thu Apr 7 15:18:13 2005 -0700
604 -
605 - 6th
606 -EOF
536 + Notes (other):
537 + ${indent}other note
538 + EOF
539 +'
540
541 test_expect_success 'Do not show note on other ref by default' '
609 - git log -1 > output &&
610 - test_cmp expect-not-other output
542 + git log -1 >actual &&
543 + test_cmp expect-not-other actual
544 '
545
546 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
547 + GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
548 + test_cmp expect-other actual
549 '
550
551 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
552 + test_config core.notesRef "refs/notes/other" &&
553 + git log -1 >actual &&
554 + test_cmp expect-other actual
555 '
556
557 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
558 + test_config core.notesRef "refs/notes/other" &&
559 + GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
560 + test_cmp expect-not-other actual
561 '
562
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
563 +test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
564 + cat >expect-both <<-EOF &&
565 + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
566 + Author: A U Thor <author@example.com>
567 + Date: Thu Apr 7 15:18:13 2005 -0700
568
636 -Notes:
637 - order test
569 + ${indent}6th
570
639 -Notes (other):
640 - other note
571 + Notes:
572 + ${indent}order test
573
642 -commit bd1753200303d0a0344be813e504253b3d98e74d
643 -Author: A U Thor <author@example.com>
644 -Date: Thu Apr 7 15:17:13 2005 -0700
574 + Notes (other):
575 + ${indent}other note
576
646 - 5th
577 + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
578 + Author: A U Thor <author@example.com>
579 + Date: Thu Apr 7 15:17:13 2005 -0700
580
648 -Notes:
649 - replacement for deleted note
650 -EOF
581 + ${indent}5th
582
652 -test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
583 + Notes:
584 + ${indent}replacement for deleted note
585 + EOF
586 GIT_NOTES_REF=refs/notes/commits git notes add \
587 -m"replacement for deleted note" HEAD^ &&
588 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
589 + test_unconfig core.notesRef &&
590 + test_config notes.displayRef "refs/notes/*" &&
591 + git log -2 >actual &&
592 + test_cmp expect-both actual
593 '
594
595 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
596 + test_config core.notesRef refs/notes/commits &&
597 + test_config notes.displayRef refs/notes/other &&
598 + git log -2 >actual &&
599 + test_cmp expect-both actual
600 '
601
602 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 &&
603 + test_unconfig core.notesRef &&
604 + test_config notes.displayRef refs/notes/commits &&
605 git config --add notes.displayRef refs/notes/other &&
673 - git log -2 > output &&
674 - test_cmp expect-both output
606 + git log -2 >actual &&
607 + test_cmp expect-both actual
608 '
609
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
610 +test_expect_success 'notes.displayRef respects order' '
611 + cat >expect-both-reversed <<-EOF &&
612 + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
613 + Author: A U Thor <author@example.com>
614 + Date: Thu Apr 7 15:18:13 2005 -0700
615
684 -Notes (other):
685 - other note
616 + ${indent}6th
617
687 -Notes:
688 - order test
689 -EOF
618 + Notes (other):
619 + ${indent}other note
620
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
621 + Notes:
622 + ${indent}order test
623 + EOF
624 + test_config core.notesRef refs/notes/other &&
625 + test_config notes.displayRef refs/notes/commits &&
626 + git log -1 >actual &&
627 + test_cmp expect-both-reversed actual
628 '
629
630 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
700 - git config --unset-all core.notesRef &&
701 - git config --unset-all notes.displayRef &&
631 GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
703 - git log -2 > output &&
704 - test_cmp expect-both output
632 + git log -2 >actual &&
633 + test_cmp expect-both actual
634 '
635
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
636 +test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
637 + cat >expect-none <<-EOF &&
638 + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
639 + Author: A U Thor <author@example.com>
640 + Date: Thu Apr 7 15:18:13 2005 -0700
641
714 -commit bd1753200303d0a0344be813e504253b3d98e74d
715 -Author: A U Thor <author@example.com>
716 -Date: Thu Apr 7 15:17:13 2005 -0700
642 + ${indent}6th
643
718 - 5th
719 -EOF
644 + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361
645 + Author: A U Thor <author@example.com>
646 + Date: Thu Apr 7 15:17:13 2005 -0700
647
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
648 + ${indent}5th
649 + EOF
650 + test_config notes.displayRef "refs/notes/*" &&
651 + GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
652 + test_cmp expect-none actual
653 '
654
655 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
656 + GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
657 + test_cmp expect-both actual
658 '
659
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
660 +test_expect_success '--no-standard-notes' '
661 + cat >expect-commits <<EOF
662 + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c
663 + Author: A U Thor <author@example.com>
664 + Date: Thu Apr 7 15:18:13 2005 -0700
665
739 -Notes:
740 - order test
741 -EOF
666 + ${indent}6th
667
743 -test_expect_success '--no-standard-notes' '
744 - git log --no-standard-notes --show-notes=commits -1 > output &&
745 - test_cmp expect-commits output
668 + Notes:
669 + ${indent}order test
670 + EOF
671 + git log --no-standard-notes --show-notes=commits -1 >actual &&
672 + test_cmp expect-commits actual
673 '
674
675 test_expect_success '--standard-notes' '
676 + test_config notes.displayRef "refs/notes/*" &&
677 git log --no-standard-notes --show-notes=commits \
750 - --standard-notes -2 > output &&
751 - test_cmp expect-both output
678 + --standard-notes -2 >actual &&
679 + test_cmp expect-both actual
680 '
681
682 test_expect_success '--show-notes=ref accumulates' '
683 git log --show-notes=other --show-notes=commits \
756 - --no-standard-notes -1 > output &&
757 - test_cmp expect-both-reversed output
684 + --no-standard-notes -1 >actual &&
685 + test_cmp expect-both-reversed actual
686 '
687
688 test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
761 - git config core.notesRef refs/notes/other &&
762 - echo "Note on a tree" > expect &&
689 + test_config core.notesRef refs/notes/other &&
690 + echo "Note on a tree" >expect &&
691 git notes add -m "Note on a tree" HEAD: &&
764 - git notes show HEAD: > actual &&
692 + git notes show HEAD: >actual &&
693 test_cmp expect actual &&
766 - echo "Note on a blob" > expect &&
694 + echo "Note on a blob" >expect &&
695 filename=$(git ls-tree --name-only HEAD | head -n1) &&
696 git notes add -m "Note on a blob" HEAD:$filename &&
769 - git notes show HEAD:$filename > actual &&
697 + git notes show HEAD:$filename >actual &&
698 test_cmp expect actual &&
771 - echo "Note on a tag" > expect &&
699 + echo "Note on a tag" >expect &&
700 git tag -a -m "This is an annotated tag" foobar HEAD^ &&
701 git notes add -m "Note on a tag" foobar &&
774 - git notes show foobar > actual &&
702 + git notes show foobar >actual &&
703 test_cmp expect actual
704 '
705
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
706 +test_expect_success 'create note from other note with "git notes add -C"' '
707 + cat >expect <<-EOF &&
708 + commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c
709 + Author: A U Thor <author@example.com>
710 + Date: Thu Apr 7 15:19:13 2005 -0700
711
785 -Notes (other):
786 - other note
787 -EOF
712 + ${indent}7th
713
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 &&
714 + Notes:
715 + ${indent}order test
716 + EOF
717 + test_commit 7th &&
718 git notes add -C $(git notes list HEAD^) &&
795 - git log -1 > actual &&
719 + git log -1 >actual &&
720 test_cmp expect actual &&
721 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
722 '
723
724 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 &&
725 + test_commit 8th &&
726 test_must_fail git notes add -C deadbeef &&
727 test_must_fail git notes list HEAD
728 '
@@ -814,405 +735,386 @@ test_expect_success 'create note from non-blob with "git notes add -C" fails' '
735 test_must_fail git notes list HEAD
736 '
737
817 -cat > expect << EOF
818 -commit 80d796defacd5db327b7a4e50099663902fbdc5c
819 -Author: A U Thor <author@example.com>
820 -Date: Thu Apr 7 15:20:13 2005 -0700
821 -
822 - 8th
738 +test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
739 + cat >expect <<-EOF &&
740 + commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf
741 + Author: A U Thor <author@example.com>
742 + Date: Thu Apr 7 15:20:13 2005 -0700
743
824 -Notes (other):
825 - This is a blob object
826 -EOF
744 + ${indent}8th
745
828 -test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
746 + Notes:
747 + ${indent}This is a blob object
748 + EOF
749 blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
750 git notes add -C $blob &&
831 - git log -1 > actual &&
751 + git log -1 >actual &&
752 test_cmp expect actual &&
753 test "$(git notes list HEAD)" = "$blob"
754 '
755
836 -cat > expect << EOF
837 -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
838 -Author: A U Thor <author@example.com>
839 -Date: Thu Apr 7 15:21:13 2005 -0700
756 +test_expect_success 'create note from other note with "git notes add -c"' '
757 + cat >expect <<-EOF &&
758 + commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
759 + Author: A U Thor <author@example.com>
760 + Date: Thu Apr 7 15:21:13 2005 -0700
761
841 - 9th
762 + ${indent}9th
763
843 -Notes (other):
844 - yet another note
845 -EOF
846 -
847 -test_expect_success 'create note from other note with "git notes add -c"' '
848 - : > a9 &&
849 - git add a9 &&
850 - test_tick &&
851 - git commit -m 9th &&
764 + Notes:
765 + ${indent}yet another note
766 + EOF
767 + test_commit 9th &&
768 MSG="yet another note" git notes add -c $(git notes list HEAD^^) &&
853 - git log -1 > actual &&
769 + git log -1 >actual &&
770 test_cmp expect actual
771 '
772
773 test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
858 - : > a10 &&
859 - git add a10 &&
860 - test_tick &&
861 - git commit -m 10th &&
774 + test_commit 10th &&
775 test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
776 test_must_fail git notes list HEAD
777 '
778
866 -cat > expect << EOF
867 -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
868 -Author: A U Thor <author@example.com>
869 -Date: Thu Apr 7 15:21:13 2005 -0700
870 -
871 - 9th
872 -
873 -Notes (other):
874 - yet another note
875 -$whitespace
876 - yet another note
877 -EOF
878 -
779 test_expect_success 'append to note from other note with "git notes append -C"' '
780 + cat >expect <<-EOF &&
781 + commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2
782 + Author: A U Thor <author@example.com>
783 + Date: Thu Apr 7 15:21:13 2005 -0700
784 +
785 + ${indent}9th
786 +
787 + Notes:
788 + ${indent}yet another note
789 + ${indent}
790 + ${indent}yet another note
791 + EOF
792 git notes append -C $(git notes list HEAD^) HEAD^ &&
881 - git log -1 HEAD^ > actual &&
793 + git log -1 HEAD^ >actual &&
794 test_cmp expect actual
795 '
796
885 -cat > expect << EOF
886 -commit ffed603236bfa3891c49644257a83598afe8ae5a
887 -Author: A U Thor <author@example.com>
888 -Date: Thu Apr 7 15:22:13 2005 -0700
889 -
890 - 10th
797 +test_expect_success 'create note from other note with "git notes append -c"' '
798 + cat >expect <<-EOF &&
799 + commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
800 + Author: A U Thor <author@example.com>
801 + Date: Thu Apr 7 15:22:13 2005 -0700
802
892 -Notes (other):
893 - other note
894 -EOF
803 + ${indent}10th
804
896 -test_expect_success 'create note from other note with "git notes append -c"' '
805 + Notes:
806 + ${indent}other note
807 + EOF
808 MSG="other note" git notes append -c $(git notes list HEAD^) &&
898 - git log -1 > actual &&
809 + git log -1 >actual &&
810 test_cmp expect actual
811 '
812
902 -cat > expect << EOF
903 -commit ffed603236bfa3891c49644257a83598afe8ae5a
904 -Author: A U Thor <author@example.com>
905 -Date: Thu Apr 7 15:22:13 2005 -0700
906 -
907 - 10th
908 -
909 -Notes (other):
910 - other note
911 -$whitespace
912 - yet another note
913 -EOF
914 -
813 test_expect_success 'append to note from other note with "git notes append -c"' '
814 + cat >expect <<-EOF &&
815 + commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406
816 + Author: A U Thor <author@example.com>
817 + Date: Thu Apr 7 15:22:13 2005 -0700
818 +
819 + ${indent}10th
820 +
821 + Notes:
822 + ${indent}other note
823 + ${indent}
824 + ${indent}yet another note
825 + EOF
826 MSG="yet another note" git notes append -c $(git notes list HEAD) &&
917 - git log -1 > actual &&
827 + git log -1 >actual &&
828 test_cmp expect actual
829 '
830
921 -cat > expect << EOF
922 -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
923 -Author: A U Thor <author@example.com>
924 -Date: Thu Apr 7 15:23:13 2005 -0700
925 -
926 - 11th
927 -
928 -Notes (other):
929 - other note
930 -$whitespace
931 - yet another note
932 -EOF
933 -
831 test_expect_success 'copy note with "git notes copy"' '
935 - : > a11 &&
936 - git add a11 &&
937 - test_tick &&
938 - git commit -m 11th &&
832 + cat >expect <<-EOF &&
833 + commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
834 + Author: A U Thor <author@example.com>
835 + Date: Thu Apr 7 15:23:13 2005 -0700
836 +
837 + ${indent}11th
838 +
839 + Notes:
840 + ${indent}other note
841 + ${indent}
842 + ${indent}yet another note
843 + EOF
844 + test_commit 11th &&
845 git notes copy HEAD^ HEAD &&
940 - git log -1 > actual &&
846 + git log -1 >actual &&
847 test_cmp expect actual &&
848 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
849 '
850
851 test_expect_success 'prevent overwrite with "git notes copy"' '
852 test_must_fail git notes copy HEAD~2 HEAD &&
947 - git log -1 > actual &&
853 + git log -1 >actual &&
854 test_cmp expect actual &&
855 test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
856 '
857
952 -cat > expect << EOF
953 -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
954 -Author: A U Thor <author@example.com>
955 -Date: Thu Apr 7 15:23:13 2005 -0700
956 -
957 - 11th
958 -
959 -Notes (other):
960 - yet another note
961 -$whitespace
962 - yet another note
963 -EOF
964 -
858 test_expect_success 'allow overwrite with "git notes copy -f"' '
859 + cat >expect <<-EOF &&
860 + commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5
861 + Author: A U Thor <author@example.com>
862 + Date: Thu Apr 7 15:23:13 2005 -0700
863 +
864 + ${indent}11th
865 +
866 + Notes:
867 + ${indent}yet another note
868 + ${indent}
869 + ${indent}yet another note
870 + EOF
871 git notes copy -f HEAD~2 HEAD &&
967 - git log -1 > actual &&
872 + git log -1 >actual &&
873 test_cmp expect actual &&
874 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
875 '
876
877 test_expect_success 'cannot copy note from object without notes' '
973 - : > a12 &&
974 - git add a12 &&
975 - test_tick &&
976 - git commit -m 12th &&
977 - : > a13 &&
978 - git add a13 &&
979 - test_tick &&
980 - git commit -m 13th &&
878 + test_commit 12th &&
879 + test_commit 13th &&
880 test_must_fail git notes copy HEAD^ HEAD
881 '
882
984 -cat > expect << EOF
985 -commit e5d4fb5698d564ab8c73551538ecaf2b0c666185
986 -Author: A U Thor <author@example.com>
987 -Date: Thu Apr 7 15:25:13 2005 -0700
988 -
989 - 13th
883 +test_expect_success 'git notes copy --stdin' '
884 + cat >expect <<-EOF &&
885 + commit e871aa61182b1d95d0a6fb75445d891722863b6b
886 + Author: A U Thor <author@example.com>
887 + Date: Thu Apr 7 15:25:13 2005 -0700
888
991 -Notes (other):
992 - yet another note
993 -$whitespace
994 - yet another note
889 + ${indent}13th
890
996 -commit 7038787dfe22a14c3867ce816dbba39845359719
997 -Author: A U Thor <author@example.com>
998 -Date: Thu Apr 7 15:24:13 2005 -0700
891 + Notes:
892 + ${indent}yet another note
893 + ${indent}
894 + ${indent}yet another note
895
1000 - 12th
896 + commit 65e263ded02ae4e8839bc151095113737579dc12
897 + Author: A U Thor <author@example.com>
898 + Date: Thu Apr 7 15:24:13 2005 -0700
899
1002 -Notes (other):
1003 - other note
1004 -$whitespace
1005 - yet another note
1006 -EOF
900 + ${indent}12th
901
1008 -test_expect_success 'git notes copy --stdin' '
902 + Notes:
903 + ${indent}other note
904 + ${indent}
905 + ${indent}yet another note
906 + EOF
907 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
908 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
909 git notes copy --stdin &&
1012 - git log -2 > output &&
1013 - test_cmp expect output &&
910 + git log -2 >actual &&
911 + test_cmp expect actual &&
912 test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" &&
913 test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)"
914 '
915
1018 -cat > expect << EOF
1019 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1020 -Author: A U Thor <author@example.com>
1021 -Date: Thu Apr 7 15:27:13 2005 -0700
1022 -
1023 - 15th
916 +test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
917 + cat >expect <<-EOF &&
918 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
919 + Author: A U Thor <author@example.com>
920 + Date: Thu Apr 7 15:27:13 2005 -0700
921
1025 -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
1026 -Author: A U Thor <author@example.com>
1027 -Date: Thu Apr 7 15:26:13 2005 -0700
922 + ${indent}15th
923
1029 - 14th
1030 -EOF
924 + commit 07c85d77059393ed0154b8c96906547a59dfcddd
925 + Author: A U Thor <author@example.com>
926 + Date: Thu Apr 7 15:26:13 2005 -0700
927
1032 -test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
928 + ${indent}14th
929 + EOF
930 test_commit 14th &&
931 test_commit 15th &&
932 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
933 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
934 git notes copy --for-rewrite=foo &&
1038 - git log -2 > output &&
1039 - test_cmp expect output
935 + git log -2 >actual &&
936 + test_cmp expect actual
937 '
938
1042 -cat > expect << EOF
1043 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1044 -Author: A U Thor <author@example.com>
1045 -Date: Thu Apr 7 15:27:13 2005 -0700
1046 -
1047 - 15th
1048 -
1049 -Notes (other):
1050 - yet another note
1051 -$whitespace
1052 - yet another note
1053 -
1054 -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d
1055 -Author: A U Thor <author@example.com>
1056 -Date: Thu Apr 7 15:26:13 2005 -0700
1057 -
1058 - 14th
1059 -
1060 -Notes (other):
1061 - other note
1062 -$whitespace
1063 - yet another note
1064 -EOF
1065 -
939 test_expect_success 'git notes copy --for-rewrite (enabled)' '
1067 - git config notes.rewriteMode overwrite &&
1068 - git config notes.rewriteRef "refs/notes/*" &&
940 + cat >expect <<-EOF &&
941 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
942 + Author: A U Thor <author@example.com>
943 + Date: Thu Apr 7 15:27:13 2005 -0700
944 +
945 + ${indent}15th
946 +
947 + Notes:
948 + ${indent}yet another note
949 + ${indent}
950 + ${indent}yet another note
951 +
952 + commit 07c85d77059393ed0154b8c96906547a59dfcddd
953 + Author: A U Thor <author@example.com>
954 + Date: Thu Apr 7 15:26:13 2005 -0700
955 +
956 + ${indent}14th
957 +
958 + Notes:
959 + ${indent}other note
960 + ${indent}
961 + ${indent}yet another note
962 + EOF
963 + test_config notes.rewriteMode overwrite &&
964 + test_config notes.rewriteRef "refs/notes/*" &&
965 (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \
966 echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) |
967 git notes copy --for-rewrite=foo &&
1072 - git log -2 > output &&
1073 - test_cmp expect output
968 + git log -2 >actual &&
969 + test_cmp expect actual
970 '
971
972 test_expect_success 'git notes copy --for-rewrite (disabled)' '
1077 - git config notes.rewrite.bar false &&
973 + test_config notes.rewrite.bar false &&
974 echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) |
975 git notes copy --for-rewrite=bar &&
1080 - git log -2 > output &&
1081 - test_cmp expect output
976 + git log -2 >actual &&
977 + test_cmp expect actual
978 '
979
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
980 +test_expect_success 'git notes copy --for-rewrite (overwrite)' '
981 + cat >expect <<-EOF &&
982 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
983 + Author: A U Thor <author@example.com>
984 + Date: Thu Apr 7 15:27:13 2005 -0700
985
1089 - 15th
986 + ${indent}15th
987
1091 -Notes (other):
1092 - a fresh note
1093 -EOF
1094 -
1095 -test_expect_success 'git notes copy --for-rewrite (overwrite)' '
988 + Notes:
989 + ${indent}a fresh note
990 + EOF
991 git notes add -f -m"a fresh note" HEAD^ &&
992 + test_config notes.rewriteMode overwrite &&
993 + test_config notes.rewriteRef "refs/notes/*" &&
994 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
995 git notes copy --for-rewrite=foo &&
1099 - git log -1 > output &&
1100 - test_cmp expect output
996 + git log -1 >actual &&
997 + test_cmp expect actual
998 '
999
1000 test_expect_success 'git notes copy --for-rewrite (ignore)' '
1104 - git config notes.rewriteMode ignore &&
1001 + test_config notes.rewriteMode ignore &&
1002 + test_config notes.rewriteRef "refs/notes/*" &&
1003 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1004 git notes copy --for-rewrite=foo &&
1107 - git log -1 > output &&
1108 - test_cmp expect output
1005 + git log -1 >actual &&
1006 + test_cmp expect actual
1007 '
1008
1111 -cat > expect << EOF
1112 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1113 -Author: A U Thor <author@example.com>
1114 -Date: Thu Apr 7 15:27:13 2005 -0700
1115 -
1116 - 15th
1117 -
1118 -Notes (other):
1119 - a fresh note
1120 -$whitespace
1121 - another fresh note
1122 -EOF
1123 -
1009 test_expect_success 'git notes copy --for-rewrite (append)' '
1010 + cat >expect <<-EOF &&
1011 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1012 + Author: A U Thor <author@example.com>
1013 + Date: Thu Apr 7 15:27:13 2005 -0700
1014 +
1015 + ${indent}15th
1016 +
1017 + Notes:
1018 + ${indent}a fresh note
1019 + ${indent}
1020 + ${indent}another fresh note
1021 + EOF
1022 git notes add -f -m"another fresh note" HEAD^ &&
1126 - git config notes.rewriteMode concatenate &&
1023 + test_config notes.rewriteMode concatenate &&
1024 + test_config notes.rewriteRef "refs/notes/*" &&
1025 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1026 git notes copy --for-rewrite=foo &&
1129 - git log -1 > output &&
1130 - test_cmp expect output
1027 + git log -1 >actual &&
1028 + test_cmp expect actual
1029 '
1030
1133 -cat > expect << EOF
1134 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1135 -Author: A U Thor <author@example.com>
1136 -Date: Thu Apr 7 15:27:13 2005 -0700
1137 -
1138 - 15th
1139 -
1140 -Notes (other):
1141 - a fresh note
1142 -$whitespace
1143 - another fresh note
1144 -$whitespace
1145 - append 1
1146 -$whitespace
1147 - append 2
1148 -EOF
1149 -
1031 test_expect_success 'git notes copy --for-rewrite (append two to one)' '
1032 + cat >expect <<-EOF &&
1033 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1034 + Author: A U Thor <author@example.com>
1035 + Date: Thu Apr 7 15:27:13 2005 -0700
1036 +
1037 + ${indent}15th
1038 +
1039 + Notes:
1040 + ${indent}a fresh note
1041 + ${indent}
1042 + ${indent}another fresh note
1043 + ${indent}
1044 + ${indent}append 1
1045 + ${indent}
1046 + ${indent}append 2
1047 + EOF
1048 git notes add -f -m"append 1" HEAD^ &&
1049 git notes add -f -m"append 2" HEAD^^ &&
1050 + test_config notes.rewriteMode concatenate &&
1051 + test_config notes.rewriteRef "refs/notes/*" &&
1052 (echo $(git rev-parse HEAD^) $(git rev-parse HEAD);
1053 echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) |
1054 git notes copy --for-rewrite=foo &&
1156 - git log -1 > output &&
1157 - test_cmp expect output
1055 + git log -1 >actual &&
1056 + test_cmp expect actual
1057 '
1058
1059 test_expect_success 'git notes copy --for-rewrite (append empty)' '
1060 git notes remove HEAD^ &&
1061 + test_config notes.rewriteMode concatenate &&
1062 + test_config notes.rewriteRef "refs/notes/*" &&
1063 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1064 git notes copy --for-rewrite=foo &&
1164 - git log -1 > output &&
1165 - test_cmp expect output
1065 + git log -1 >actual &&
1066 + test_cmp expect actual
1067 '
1068
1168 -cat > expect << EOF
1169 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1170 -Author: A U Thor <author@example.com>
1171 -Date: Thu Apr 7 15:27:13 2005 -0700
1172 -
1173 - 15th
1174 -
1175 -Notes (other):
1176 - replacement note 1
1177 -EOF
1178 -
1069 test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
1070 + cat >expect <<-EOF &&
1071 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1072 + Author: A U Thor <author@example.com>
1073 + Date: Thu Apr 7 15:27:13 2005 -0700
1074 +
1075 + ${indent}15th
1076 +
1077 + Notes:
1078 + ${indent}replacement note 1
1079 + EOF
1080 + test_config notes.rewriteMode concatenate &&
1081 + test_config notes.rewriteRef "refs/notes/*" &&
1082 git notes add -f -m"replacement note 1" HEAD^ &&
1083 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1084 GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo &&
1183 - git log -1 > output &&
1184 - test_cmp expect output
1085 + git log -1 >actual &&
1086 + test_cmp expect actual
1087 '
1088
1187 -cat > expect << EOF
1188 -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b
1189 -Author: A U Thor <author@example.com>
1190 -Date: Thu Apr 7 15:27:13 2005 -0700
1191 -
1192 - 15th
1089 +test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1090 + cat >expect <<-EOF &&
1091 + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89
1092 + Author: A U Thor <author@example.com>
1093 + Date: Thu Apr 7 15:27:13 2005 -0700
1094
1194 -Notes (other):
1195 - replacement note 2
1196 -EOF
1095 + ${indent}15th
1096
1198 -test_expect_success 'GIT_NOTES_REWRITE_REF works' '
1199 - git config notes.rewriteMode overwrite &&
1097 + Notes:
1098 + ${indent}replacement note 2
1099 + EOF
1100 git notes add -f -m"replacement note 2" HEAD^ &&
1201 - git config --unset-all notes.rewriteRef &&
1101 + test_config notes.rewriteMode overwrite &&
1102 + test_unconfig notes.rewriteRef &&
1103 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1104 GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
1105 git notes copy --for-rewrite=foo &&
1205 - git log -1 > output &&
1206 - test_cmp expect output
1106 + git log -1 >actual &&
1107 + test_cmp expect actual
1108 '
1109
1110 test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
1210 - git config notes.rewriteRef refs/notes/other &&
1111 git notes add -f -m"replacement note 3" HEAD^ &&
1112 + test_config notes.rewriteMode overwrite &&
1113 + test_config notes.rewriteRef refs/notes/other &&
1114 echo $(git rev-parse HEAD^) $(git rev-parse HEAD) |
1115 GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo &&
1214 - git log -1 > output &&
1215 - test_cmp expect output
1116 + git log -1 >actual &&
1117 + test_cmp expect actual
1118 '
1119
1120 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
@@ -1221,13 +1123,13 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1123 '
1124
1125 test_expect_success 'git notes get-ref (no overrides)' '
1224 - git config --unset core.notesRef &&
1126 + test_unconfig core.notesRef &&
1127 sane_unset GIT_NOTES_REF &&
1128 test "$(git notes get-ref)" = "refs/notes/commits"
1129 '
1130
1131 test_expect_success 'git notes get-ref (core.notesRef)' '
1230 - git config core.notesRef refs/notes/foo &&
1132 + test_config core.notesRef refs/notes/foo &&
1133 test "$(git notes get-ref)" = "refs/notes/foo"
1134 '
1135
@@ -1277,10 +1179,10 @@ EOF
1179 test_expect_success 'empty notes are displayed by git log' '
1180 test_commit 17th &&
1181 git log -1 >expect &&
1280 - cat >>expect <<\EOF &&
1182 + cat >>expect <<-EOF &&
1183
1282 -Notes:
1283 -EOF
1184 + Notes:
1185 + EOF
1186 git notes add -C "$empty_blob" --allow-empty &&
1187 git log -1 >actual &&
1188 test_cmp expect actual