|
1 | 1 | #!/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 | +# |
2 | 7 |
|
3 | 8 | baseCommit=$1
|
4 | 9 | outputFile=$2
|
5 | 10 | url=$3
|
6 | 11 |
|
| 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 | + |
7 | 18 | problems=()
|
8 | 19 | commit=
|
9 | 20 | commitText=
|
|
56 | 67 | goodParent=${baseCommit: 0:7}
|
57 | 68 | fi
|
58 | 69 |
|
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:" |
67 | 86 |
|
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 |
72 | 93 |
|
73 | 94 | exit 2
|
74 | 95 | fi
|
0 commit comments