t3321: add test cases about the notes stripspace behavior

Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Teng Long committed May 27, 2023 at 15:57 UTC 59587049e2724d762c52f8c475e7ecd79dc96b18
1 file changed +291
t/t3321-notes-stripspace.sh new
+291
@@ -0,0 +1,291 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2023 Teng Long
4 +#
5 +
6 +test_description='Test commit notes with stripspace behavior'
7 +
8 +. ./test-lib.sh
9 +
10 +MULTI_LF="$LF$LF$LF"
11 +write_script fake_editor <<\EOF
12 +echo "$MSG" >"$1"
13 +echo "$MSG" >&2
14 +EOF
15 +GIT_EDITOR=./fake_editor
16 +export GIT_EDITOR
17 +
18 +test_expect_success 'setup the commit' '
19 + test_commit 1st
20 +'
21 +
22 +test_expect_success 'add note by editor' '
23 + test_when_finished "git notes remove" &&
24 + cat >expect <<-EOF &&
25 + first-line
26 +
27 + second-line
28 + EOF
29 +
30 + MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add &&
31 + git notes show >actual &&
32 + test_cmp expect actual
33 +'
34 +
35 +test_expect_success 'add note by specifying single "-m"' '
36 + test_when_finished "git notes remove" &&
37 + cat >expect <<-EOF &&
38 + first-line
39 +
40 + second-line
41 + EOF
42 +
43 + git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
44 + git notes show >actual &&
45 + test_cmp expect actual
46 +'
47 +
48 +test_expect_success 'add note by specifying multiple "-m"' '
49 + test_when_finished "git notes remove" &&
50 + cat >expect <<-EOF &&
51 + first-line
52 +
53 + second-line
54 + EOF
55 +
56 + git notes add -m "${LF}" \
57 + -m "first-line" \
58 + -m "${MULTI_LF}" \
59 + -m "second-line" \
60 + -m "${LF}" &&
61 + git notes show >actual &&
62 + test_cmp expect actual
63 +'
64 +
65 +
66 +test_expect_success 'append note by editor' '
67 + test_when_finished "git notes remove" &&
68 + cat >expect <<-EOF &&
69 + first-line
70 +
71 + second-line
72 + EOF
73 +
74 + git notes add -m "first-line" &&
75 + MSG="${MULTI_LF}second-line${LF}" git notes append &&
76 + git notes show >actual &&
77 + test_cmp expect actual
78 +'
79 +
80 +test_expect_success 'append note by specifying single "-m"' '
81 + test_when_finished "git notes remove" &&
82 + cat >expect <<-EOF &&
83 + first-line
84 +
85 + second-line
86 + EOF
87 +
88 + git notes add -m "${LF}first-line" &&
89 + git notes append -m "${MULTI_LF}second-line${LF}" &&
90 + git notes show >actual &&
91 + test_cmp expect actual
92 +'
93 +
94 +test_expect_success 'append note by specifying multiple "-m"' '
95 + test_when_finished "git notes remove" &&
96 + cat >expect <<-EOF &&
97 + first-line
98 +
99 + second-line
100 + EOF
101 +
102 + git notes add -m "${LF}first-line" &&
103 + git notes append -m "${MULTI_LF}" \
104 + -m "second-line" \
105 + -m "${LF}" &&
106 + git notes show >actual &&
107 + test_cmp expect actual
108 +'
109 +
110 +test_expect_success 'add note by specifying single "-F"' '
111 + test_when_finished "git notes remove" &&
112 + cat >expect <<-EOF &&
113 + first-line
114 +
115 + second-line
116 + EOF
117 +
118 + cat >note-file <<-EOF &&
119 + ${LF}
120 + first-line
121 + ${MULTI_LF}
122 + second-line
123 + ${LF}
124 + EOF
125 +
126 + git notes add -F note-file &&
127 + git notes show >actual &&
128 + test_cmp expect actual
129 +'
130 +
131 +test_expect_success 'add notes by specifying multiple "-F"' '
132 + test_when_finished "git notes remove" &&
133 + cat >expect <<-EOF &&
134 + file-1-first-line
135 +
136 + file-1-second-line
137 +
138 + file-2-first-line
139 +
140 + file-2-second-line
141 + EOF
142 +
143 + cat >note-file-1 <<-EOF &&
144 + ${LF}
145 + file-1-first-line
146 + ${MULTI_LF}
147 + file-1-second-line
148 + ${LF}
149 + EOF
150 +
151 + cat >note-file-2 <<-EOF &&
152 + ${LF}
153 + file-2-first-line
154 + ${MULTI_LF}
155 + file-2-second-line
156 + ${LF}
157 + EOF
158 +
159 + git notes add -F note-file-1 -F note-file-2 &&
160 + git notes show >actual &&
161 + test_cmp expect actual
162 +'
163 +
164 +test_expect_success 'append note by specifying single "-F"' '
165 + test_when_finished "git notes remove" &&
166 + cat >expect <<-EOF &&
167 + initial-line
168 +
169 + first-line
170 +
171 + second-line
172 + EOF
173 +
174 + cat >note-file <<-EOF &&
175 + ${LF}
176 + first-line
177 + ${MULTI_LF}
178 + second-line
179 + ${LF}
180 + EOF
181 +
182 + git notes add -m "initial-line" &&
183 + git notes append -F note-file &&
184 + git notes show >actual &&
185 + test_cmp expect actual
186 +'
187 +
188 +test_expect_success 'append notes by specifying multiple "-F"' '
189 + test_when_finished "git notes remove" &&
190 + cat >expect <<-EOF &&
191 + initial-line
192 +
193 + file-1-first-line
194 +
195 + file-1-second-line
196 +
197 + file-2-first-line
198 +
199 + file-2-second-line
200 + EOF
201 +
202 + cat >note-file-1 <<-EOF &&
203 + ${LF}
204 + file-1-first-line
205 + ${MULTI_LF}
206 + file-1-second-line
207 + ${LF}
208 + EOF
209 +
210 + cat >note-file-2 <<-EOF &&
211 + ${LF}
212 + file-2-first-line
213 + ${MULTI_LF}
214 + file-2-second-line
215 + ${LF}
216 + EOF
217 +
218 + git notes add -m "initial-line" &&
219 + git notes append -F note-file-1 -F note-file-2 &&
220 + git notes show >actual &&
221 + test_cmp expect actual
222 +'
223 +
224 +test_expect_success 'add notes with empty messages' '
225 + rev=$(git rev-parse HEAD) &&
226 + git notes add -m "${LF}" \
227 + -m "${MULTI_LF}" \
228 + -m "${LF}" >actual 2>&1 &&
229 + test_i18ngrep "Removing note for object" actual
230 +'
231 +
232 +test_expect_success 'add note by specifying "-C" , do not stripspace is the default behavior' '
233 + test_when_finished "git notes remove" &&
234 + cat >expect <<-EOF &&
235 + ${LF}
236 + first-line
237 + ${MULTI_LF}
238 + second-line
239 + ${LF}
240 + EOF
241 +
242 + cat expect | git hash-object -w --stdin >blob &&
243 + git notes add -C $(cat blob) &&
244 + git notes show >actual &&
245 + test_cmp expect actual
246 +'
247 +
248 +test_expect_success 'add notes with "-C" and "-m", "-m" will stripspace all together' '
249 + test_when_finished "git notes remove" &&
250 + cat >data <<-EOF &&
251 + ${LF}
252 + first-line
253 + ${MULTI_LF}
254 + second-line
255 + ${LF}
256 + EOF
257 +
258 + cat >expect <<-EOF &&
259 + first-line
260 +
261 + second-line
262 +
263 + third-line
264 + EOF
265 +
266 + cat data | git hash-object -w --stdin >blob &&
267 + git notes add -C $(cat blob) -m "third-line" &&
268 + git notes show >actual &&
269 + test_cmp expect actual
270 +'
271 +
272 +test_expect_success 'add notes with "-m" and "-C", "-C" will not stripspace all together' '
273 + test_when_finished "git notes remove" &&
274 + cat >data <<-EOF &&
275 +
276 + second-line
277 + EOF
278 +
279 + cat >expect <<-EOF &&
280 + first-line
281 + ${LF}
282 + second-line
283 + EOF
284 +
285 + cat data | git hash-object -w --stdin >blob &&
286 + git notes add -m "first-line" -C $(cat blob) &&
287 + git notes show >actual &&
288 + test_cmp expect actual
289 +'
290 +
291 +test_done