t7502: clean up style

Refactor out Git commands that were upstream of a pipe. Remove spaces after "> ". Indent here-docs appropriately. Convert echo chains to use the test_write_lines function. Refactor 'sign off' test to use test_cmp instead of comparing variables. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 17, 2019 at 11:23 UTC 94ca361bfb87b00fad7c19cbb518656279e4329d
1 file changed +53 -40
t/t7502-commit-porcelain.sh
+53 -40
@@ -16,7 +16,8 @@ commit_msg_is () {
16 # Arguments: [<prefix] [<commit message>] [<commit options>]
17 check_summary_oneline() {
18 test_tick &&
19 - git commit ${3+"$3"} -m "$2" | head -1 > act &&
19 + git commit ${3+"$3"} -m "$2" >raw &&
20 + head -n 1 raw >act &&
21
22 # branch name
23 SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
@@ -68,7 +69,7 @@ test_expect_success 'output summary format for merges' '
69 git checkout recursive-a &&
70 test_must_fail git merge recursive-b &&
71 # resolve the conflict
71 - echo commit-a > file1 &&
72 + echo commit-a >file1 &&
73 git add file1 &&
74 check_summary_oneline "" "Merge"
75 '
@@ -142,9 +143,11 @@ test_expect_success 'sign off' '
143 >positive &&
144 git add positive &&
145 git commit -s -m "thank you" &&
145 - actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
146 - expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
147 - test "z$actual" = "z$expected"
146 + git cat-file commit HEAD >commit.msg &&
147 + sed -ne "s/Signed-off-by: //p" commit.msg >actual &&
148 + git var GIT_COMMITTER_IDENT >ident &&
149 + sed -e "s/>.*/>/" ident >expected &&
150 + test_cmp expected actual
151
152 '
153
@@ -153,8 +156,8 @@ test_expect_success 'multiple -m' '
156 >negative &&
157 git add negative &&
158 git commit -m "one" -m "two" -m "three" &&
156 - actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
157 - expected=$(echo one; echo; echo two; echo; echo three) &&
159 + actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) &&
160 + expected=$(test_write_lines "one" "" "two" "" "three") &&
161 test "z$actual" = "z$expected"
162
163 '
@@ -163,7 +166,8 @@ test_expect_success 'verbose' '
166
167 echo minus >negative &&
168 git add negative &&
166 - git status -v | sed -ne "/^diff --git /p" >actual &&
169 + git status -v >raw &&
170 + sed -ne "/^diff --git /p" raw >actual &&
171 echo "diff --git a/negative b/negative" >expect &&
172 test_cmp expect actual
173
@@ -189,7 +193,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-t)' '
193
194 echo >>negative &&
195 git commit --cleanup=verbatim --no-status -t expect -a &&
192 - git cat-file -p HEAD |sed -e "1,/^\$/d" >actual &&
196 + git cat-file -p HEAD >raw &&
197 + sed -e "1,/^\$/d" raw >actual &&
198 test_cmp expect actual
199
200 '
@@ -198,7 +203,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
203
204 echo >>negative &&
205 git commit --cleanup=verbatim -F expect -a &&
201 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
206 + git cat-file -p HEAD >raw &&
207 + sed -e "1,/^\$/d" raw >actual &&
208 test_cmp expect actual
209
210 '
@@ -207,7 +213,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' '
213
214 echo >>negative &&
215 git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
210 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
216 + git cat-file -p HEAD >raw &&
217 + sed -e "1,/^\$/d" raw >actual &&
218 test_cmp expect actual
219
220 '
@@ -215,10 +222,11 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' '
222 test_expect_success 'cleanup commit messages (whitespace option,-F)' '
223
224 echo >>negative &&
218 - { echo;echo "# text";echo; } >text &&
225 + test_write_lines "" "# text" "" >text &&
226 echo "# text" >expect &&
227 git commit --cleanup=whitespace -F text -a &&
221 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
228 + git cat-file -p HEAD >raw &&
229 + sed -e "1,/^\$/d" raw >actual &&
230 test_cmp expect actual
231
232 '
@@ -226,48 +234,51 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
234 test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
235
236 echo >>negative &&
229 - cat >text <<EOF &&
237 + cat >text <<-\EOF &&
238
231 -# to be kept
239 + # to be kept
240
233 - # ------------------------ >8 ------------------------
234 -# to be kept, too
235 -# ------------------------ >8 ------------------------
236 -to be removed
237 -# ------------------------ >8 ------------------------
238 -to be removed, too
239 -EOF
241 + # ------------------------ >8 ------------------------
242 + # to be kept, too
243 + # ------------------------ >8 ------------------------
244 + to be removed
245 + # ------------------------ >8 ------------------------
246 + to be removed, too
247 + EOF
248
241 - cat >expect <<EOF &&
242 -# to be kept
249 + cat >expect <<-\EOF &&
250 + # to be kept
251
244 - # ------------------------ >8 ------------------------
245 -# to be kept, too
246 -EOF
252 + # ------------------------ >8 ------------------------
253 + # to be kept, too
254 + EOF
255 git commit --cleanup=scissors -e -F text -a &&
248 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
256 + git cat-file -p HEAD >raw &&
257 + sed -e "1,/^\$/d" raw >actual &&
258 test_cmp expect actual
259 '
260
261 test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '
262
263 echo >>negative &&
255 - cat >text <<EOF &&
256 -# ------------------------ >8 ------------------------
257 -to be removed
258 -EOF
264 + cat >text <<-\EOF &&
265 + # ------------------------ >8 ------------------------
266 + to be removed
267 + EOF
268 git commit --cleanup=scissors -e -F text -a --allow-empty-message &&
260 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
269 + git cat-file -p HEAD >raw &&
270 + sed -e "1,/^\$/d" raw >actual &&
271 test_must_be_empty actual
272 '
273
274 test_expect_success 'cleanup commit messages (strip option,-F)' '
275
276 echo >>negative &&
267 - { echo;echo "# text";echo sample;echo; } >text &&
277 + test_write_lines "" "# text" "sample" "" >text &&
278 echo sample >expect &&
279 git commit --cleanup=strip -F text -a &&
270 - git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
280 + git cat-file -p HEAD >raw &&
281 + sed -e "1,/^\$/d" raw >actual &&
282 test_cmp expect actual
283
284 '
@@ -275,7 +286,7 @@ test_expect_success 'cleanup commit messages (strip option,-F)' '
286 test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
287
288 echo >>negative &&
278 - { echo;echo sample;echo; } >text &&
289 + test_write_lines "" "sample" "" >text &&
290 git commit -e -F text -a &&
291 head -n 4 .git/COMMIT_EDITMSG >actual
292 '
@@ -387,7 +398,7 @@ test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
398 '
399
400 write_script .git/FAKE_EDITOR <<EOF
390 -echo editor started > "$(pwd)/.git/result"
401 +echo editor started >"$(pwd)/.git/result"
402 exit 0
403 EOF
404
@@ -455,7 +466,7 @@ EOF
466 test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
467 echo >>negative &&
468 ! "$SHELL_PATH" -c '\''
458 - echo kill -TERM $$ >> .git/FAKE_EDITOR
469 + echo kill -TERM $$ >>.git/FAKE_EDITOR
470 GIT_EDITOR=.git/FAKE_EDITOR
471 export GIT_EDITOR
472 exec git commit -a'\'' &&
@@ -471,7 +482,8 @@ test_expect_success 'Hand committing of a redundant merge removes dups' '
482 test_must_fail git merge second master &&
483 git checkout master g &&
484 EDITOR=: git commit -a &&
474 - git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
485 + git cat-file commit HEAD >raw &&
486 + sed -n -e "s/^parent //p" -e "/^$/q" raw >actual &&
487 test_cmp expect actual
488
489 '
@@ -480,7 +492,8 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
492
493 git reset --hard &&
494 git commit -s -m "hello: kitty" --allow-empty &&
483 - git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
495 + git cat-file commit HEAD >raw &&
496 + sed -e "1,/^$/d" raw >actual &&
497 test_line_count = 3 actual
498
499 '