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>
maint
Denton Liu 2019-04-17 11:23:24 +01:00 committed by Junio C Hamano
parent b720e1e3c3
commit 94ca361bfb
1 changed files with 53 additions and 40 deletions

View File

@ -16,7 +16,8 @@ commit_msg_is () {
# Arguments: [<prefix] [<commit message>] [<commit options>] # Arguments: [<prefix] [<commit message>] [<commit options>]
check_summary_oneline() { check_summary_oneline() {
test_tick && test_tick &&
git commit ${3+"$3"} -m "$2" | head -1 > act && git commit ${3+"$3"} -m "$2" >raw &&
head -n 1 raw >act &&


# branch name # branch name
SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" &&
@ -68,7 +69,7 @@ test_expect_success 'output summary format for merges' '
git checkout recursive-a && git checkout recursive-a &&
test_must_fail git merge recursive-b && test_must_fail git merge recursive-b &&
# resolve the conflict # resolve the conflict
echo commit-a > file1 && echo commit-a >file1 &&
git add file1 && git add file1 &&
check_summary_oneline "" "Merge" check_summary_oneline "" "Merge"
' '
@ -142,9 +143,11 @@ test_expect_success 'sign off' '
>positive && >positive &&
git add positive && git add positive &&
git commit -s -m "thank you" && git commit -s -m "thank you" &&
actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") && git cat-file commit HEAD >commit.msg &&
expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") && sed -ne "s/Signed-off-by: //p" commit.msg >actual &&
test "z$actual" = "z$expected" git var GIT_COMMITTER_IDENT >ident &&
sed -e "s/>.*/>/" ident >expected &&
test_cmp expected actual


' '


@ -153,8 +156,8 @@ test_expect_success 'multiple -m' '
>negative && >negative &&
git add negative && git add negative &&
git commit -m "one" -m "two" -m "three" && git commit -m "one" -m "two" -m "three" &&
actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") && actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) &&
expected=$(echo one; echo; echo two; echo; echo three) && expected=$(test_write_lines "one" "" "two" "" "three") &&
test "z$actual" = "z$expected" test "z$actual" = "z$expected"


' '
@ -163,7 +166,8 @@ test_expect_success 'verbose' '


echo minus >negative && echo minus >negative &&
git add negative && git add negative &&
git status -v | sed -ne "/^diff --git /p" >actual && git status -v >raw &&
sed -ne "/^diff --git /p" raw >actual &&
echo "diff --git a/negative b/negative" >expect && echo "diff --git a/negative b/negative" >expect &&
test_cmp expect actual test_cmp expect actual


@ -189,7 +193,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-t)' '


echo >>negative && echo >>negative &&
git commit --cleanup=verbatim --no-status -t expect -a && git commit --cleanup=verbatim --no-status -t expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d" >actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -198,7 +203,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '


echo >>negative && echo >>negative &&
git commit --cleanup=verbatim -F expect -a && git commit --cleanup=verbatim -F expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -207,7 +213,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' '


echo >>negative && echo >>negative &&
git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a && git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -215,10 +222,11 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' '
test_expect_success 'cleanup commit messages (whitespace option,-F)' ' test_expect_success 'cleanup commit messages (whitespace option,-F)' '


echo >>negative && echo >>negative &&
{ echo;echo "# text";echo; } >text && test_write_lines "" "# text" "" >text &&
echo "# text" >expect && echo "# text" >expect &&
git commit --cleanup=whitespace -F text -a && git commit --cleanup=whitespace -F text -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -226,48 +234,51 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '


echo >>negative && echo >>negative &&
cat >text <<EOF && cat >text <<-\EOF &&


# to be kept # to be kept


# ------------------------ >8 ------------------------ # ------------------------ >8 ------------------------
# to be kept, too # to be kept, too
# ------------------------ >8 ------------------------ # ------------------------ >8 ------------------------
to be removed to be removed
# ------------------------ >8 ------------------------ # ------------------------ >8 ------------------------
to be removed, too to be removed, too
EOF EOF


cat >expect <<EOF && cat >expect <<-\EOF &&
# to be kept # to be kept


# ------------------------ >8 ------------------------ # ------------------------ >8 ------------------------
# to be kept, too # to be kept, too
EOF EOF
git commit --cleanup=scissors -e -F text -a && git commit --cleanup=scissors -e -F text -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual
' '


test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' ' test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' '


echo >>negative && echo >>negative &&
cat >text <<EOF && cat >text <<-\EOF &&
# ------------------------ >8 ------------------------ # ------------------------ >8 ------------------------
to be removed to be removed
EOF EOF
git commit --cleanup=scissors -e -F text -a --allow-empty-message && git commit --cleanup=scissors -e -F text -a --allow-empty-message &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_must_be_empty actual test_must_be_empty actual
' '


test_expect_success 'cleanup commit messages (strip option,-F)' ' test_expect_success 'cleanup commit messages (strip option,-F)' '


echo >>negative && echo >>negative &&
{ echo;echo "# text";echo sample;echo; } >text && test_write_lines "" "# text" "sample" "" >text &&
echo sample >expect && echo sample >expect &&
git commit --cleanup=strip -F text -a && git commit --cleanup=strip -F text -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual && git cat-file -p HEAD >raw &&
sed -e "1,/^\$/d" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -275,7 +286,7 @@ test_expect_success 'cleanup commit messages (strip option,-F)' '
test_expect_success 'cleanup commit messages (strip option,-F,-e)' ' test_expect_success 'cleanup commit messages (strip option,-F,-e)' '


echo >>negative && echo >>negative &&
{ echo;echo sample;echo; } >text && test_write_lines "" "sample" "" >text &&
git commit -e -F text -a && git commit -e -F text -a &&
head -n 4 .git/COMMIT_EDITMSG >actual head -n 4 .git/COMMIT_EDITMSG >actual
' '
@ -387,7 +398,7 @@ test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
' '


write_script .git/FAKE_EDITOR <<EOF write_script .git/FAKE_EDITOR <<EOF
echo editor started > "$(pwd)/.git/result" echo editor started >"$(pwd)/.git/result"
exit 0 exit 0
EOF EOF


@ -455,7 +466,7 @@ EOF
test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' '
echo >>negative && echo >>negative &&
! "$SHELL_PATH" -c '\'' ! "$SHELL_PATH" -c '\''
echo kill -TERM $$ >> .git/FAKE_EDITOR echo kill -TERM $$ >>.git/FAKE_EDITOR
GIT_EDITOR=.git/FAKE_EDITOR GIT_EDITOR=.git/FAKE_EDITOR
export GIT_EDITOR export GIT_EDITOR
exec git commit -a'\'' && exec git commit -a'\'' &&
@ -471,7 +482,8 @@ test_expect_success 'Hand committing of a redundant merge removes dups' '
test_must_fail git merge second master && test_must_fail git merge second master &&
git checkout master g && git checkout master g &&
EDITOR=: git commit -a && EDITOR=: git commit -a &&
git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual && git cat-file commit HEAD >raw &&
sed -n -e "s/^parent //p" -e "/^$/q" raw >actual &&
test_cmp expect actual test_cmp expect actual


' '
@ -480,7 +492,8 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo


git reset --hard && git reset --hard &&
git commit -s -m "hello: kitty" --allow-empty && git commit -s -m "hello: kitty" --allow-empty &&
git cat-file commit HEAD | sed -e "1,/^$/d" >actual && git cat-file commit HEAD >raw &&
sed -e "1,/^$/d" raw >actual &&
test_line_count = 3 actual test_line_count = 3 actual


' '