Skip to content

Commit 94ca361

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Helped-by: SZEDER Gábor <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b720e1e commit 94ca361

File tree

1 file changed

+53
-40
lines changed

1 file changed

+53
-40
lines changed

t/t7502-commit-porcelain.sh

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ commit_msg_is () {
1616
# Arguments: [<prefix] [<commit message>] [<commit options>]
1717
check_summary_oneline() {
1818
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 &&
2021

2122
# branch name
2223
SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
@@ -68,7 +69,7 @@ test_expect_success 'output summary format for merges' '
6869
git checkout recursive-a &&
6970
test_must_fail git merge recursive-b &&
7071
# resolve the conflict
71-
echo commit-a > file1 &&
72+
echo commit-a >file1 &&
7273
git add file1 &&
7374
check_summary_oneline "" "Merge"
7475
'
@@ -142,9 +143,11 @@ test_expect_success 'sign off' '
142143
>positive &&
143144
git add positive &&
144145
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
148151
149152
'
150153

@@ -153,8 +156,8 @@ test_expect_success 'multiple -m' '
153156
>negative &&
154157
git add negative &&
155158
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") &&
158161
test "z$actual" = "z$expected"
159162
160163
'
@@ -163,7 +166,8 @@ test_expect_success 'verbose' '
163166
164167
echo minus >negative &&
165168
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 &&
167171
echo "diff --git a/negative b/negative" >expect &&
168172
test_cmp expect actual
169173
@@ -189,7 +193,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-t)' '
189193
190194
echo >>negative &&
191195
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 &&
193198
test_cmp expect actual
194199
195200
'
@@ -198,7 +203,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
198203
199204
echo >>negative &&
200205
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 &&
202208
test_cmp expect actual
203209
204210
'
@@ -207,75 +213,80 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' '
207213
208214
echo >>negative &&
209215
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 &&
211218
test_cmp expect actual
212219
213220
'
214221

215222
test_expect_success 'cleanup commit messages (whitespace option,-F)' '
216223
217224
echo >>negative &&
218-
{ echo;echo "# text";echo; } >text &&
225+
test_write_lines "" "# text" "" >text &&
219226
echo "# text" >expect &&
220227
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 &&
222230
test_cmp expect actual
223231
224232
'
225233

226234
test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
227235
228236
echo >>negative &&
229-
cat >text <<EOF &&
237+
cat >text <<-\EOF &&
230238
231-
# to be kept
239+
# to be kept
232240
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
240248
241-
cat >expect <<EOF &&
242-
# to be kept
249+
cat >expect <<-\EOF &&
250+
# to be kept
243251
244-
# ------------------------ >8 ------------------------
245-
# to be kept, too
246-
EOF
252+
# ------------------------ >8 ------------------------
253+
# to be kept, too
254+
EOF
247255
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 &&
249258
test_cmp expect actual
250259
'
251260

252261
test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '
253262
254263
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
259268
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 &&
261271
test_must_be_empty actual
262272
'
263273

264274
test_expect_success 'cleanup commit messages (strip option,-F)' '
265275
266276
echo >>negative &&
267-
{ echo;echo "# text";echo sample;echo; } >text &&
277+
test_write_lines "" "# text" "sample" "" >text &&
268278
echo sample >expect &&
269279
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 &&
271282
test_cmp expect actual
272283
273284
'
274285

275286
test_expect_success 'cleanup commit messages (strip option,-F,-e)' '
276287
277288
echo >>negative &&
278-
{ echo;echo sample;echo; } >text &&
289+
test_write_lines "" "sample" "" >text &&
279290
git commit -e -F text -a &&
280291
head -n 4 .git/COMMIT_EDITMSG >actual
281292
'
@@ -387,7 +398,7 @@ test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
387398
'
388399

389400
write_script .git/FAKE_EDITOR <<EOF
390-
echo editor started > "$(pwd)/.git/result"
401+
echo editor started >"$(pwd)/.git/result"
391402
exit 0
392403
EOF
393404

@@ -455,7 +466,7 @@ EOF
455466
test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
456467
echo >>negative &&
457468
! "$SHELL_PATH" -c '\''
458-
echo kill -TERM $$ >> .git/FAKE_EDITOR
469+
echo kill -TERM $$ >>.git/FAKE_EDITOR
459470
GIT_EDITOR=.git/FAKE_EDITOR
460471
export GIT_EDITOR
461472
exec git commit -a'\'' &&
@@ -471,7 +482,8 @@ test_expect_success 'Hand committing of a redundant merge removes dups' '
471482
test_must_fail git merge second master &&
472483
git checkout master g &&
473484
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 &&
475487
test_cmp expect actual
476488
477489
'
@@ -480,7 +492,8 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
480492
481493
git reset --hard &&
482494
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 &&
484497
test_line_count = 3 actual
485498
486499
'

0 commit comments

Comments
 (0)