config.mak.dev: fix a typo
[git/gitster.git] / ci / check-whitespace.sh
blobdb399097a52db65c3a8d00830e578049de96801d
1 #!/usr/bin/env bash
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.
8 baseCommit=$1
9 outputFile=$2
10 url=$3
12 if test "$#" -ne 1 && test "$#" -ne 3
13 then
14 echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
15 exit 1
18 problems=()
19 commit=
20 commitText=
21 commitTextmd=
22 goodParent=
24 while read dash sha etc
26 case "${dash}" in
27 "---") # Line contains commit information.
28 if test -z "${goodParent}"
29 then
30 # Assume the commit has no whitespace errors until detected otherwise.
31 goodParent=${sha}
34 commit="${sha}"
35 commitText="${sha} ${etc}"
36 commitTextmd="[${sha}](${url}/commit/${sha}) ${etc}"
38 "")
40 *) # Line contains whitespace error information for current commit.
41 if test -n "${goodParent}"
42 then
43 problems+=("1) --- ${commitTextmd}")
44 echo ""
45 echo "--- ${commitText}"
46 goodParent=
49 case "${dash}" in
50 *:[1-9]*:) # contains file and line number information
51 dashend=${dash#*:}
52 problems+=("[${dash}](${url}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
55 problems+=("\`${dash} ${sha} ${etc}\`")
57 esac
58 echo "${dash} ${sha} ${etc}"
60 esac
61 done <<< "$(git log --check --pretty=format:"---% h% s" "${baseCommit}"..)"
63 if test ${#problems[*]} -gt 0
64 then
65 if test -z "${goodParent}"
66 then
67 goodParent=${baseCommit: 0:7}
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}"
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."
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:"
87 for i in "${problems[@]}"
89 echo "${i}"
90 done
91 ) >"$outputFile"
94 exit 2