Skip to content

Commit 9bef980

Browse files
jltoblergitster
authored andcommitted
ci: make the whitespace report optional
The `check-whitespace` CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66820fb commit 9bef980

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

ci/check-whitespace.sh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#!/usr/bin/env bash
2+
#
3+
# Check that commits after a specified point do not contain new or modified
4+
# lines with whitespace errors. An optional formatted summary can be generated
5+
# by providing an output file path and url as additional arguments.
6+
#
27

38
baseCommit=$1
49
outputFile=$2
510
url=$3
611

12+
if test "$#" -ne 1 && test "$#" -ne 3
13+
then
14+
echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
15+
exit 1
16+
fi
17+
718
problems=()
819
commit=
920
commitText=
@@ -56,19 +67,29 @@ then
5667
goodParent=${baseCommit: 0:7}
5768
fi
5869

59-
echo "🛑 Please review the Summary output for further information."
60-
echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
61-
echo "" >>"$outputFile"
62-
echo "Run these commands to correct the problem:" >>"$outputFile"
63-
echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
64-
echo "1. \`git push --force\`" >>"$outputFile"
65-
echo " " >>"$outputFile"
66-
echo "Errors:" >>"$outputFile"
70+
echo "A whitespace issue was found in onen of more of the commits."
71+
echo "Run the following command to resolve whitespace issues:"
72+
echo "git rebase --whitespace=fix ${goodParent}"
73+
74+
# If target output file is provided, write formatted output.
75+
if test -n "$outputFile"
76+
then
77+
echo "🛑 Please review the Summary output for further information."
78+
(
79+
echo "### :x: A whitespace issue was found in one or more of the commits."
80+
echo ""
81+
echo "Run these commands to correct the problem:"
82+
echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
83+
echo "1. \`git push --force\`"
84+
echo ""
85+
echo "Errors:"
6786

68-
for i in "${problems[@]}"
69-
do
70-
echo "${i}" >>"$outputFile"
71-
done
87+
for i in "${problems[@]}"
88+
do
89+
echo "${i}"
90+
done
91+
) >"$outputFile"
92+
fi
7293

7394
exit 2
7495
fi

0 commit comments

Comments
 (0)