Skip to content

Commit 17c44b2

Browse files
committed
Merge #12098: [scripts] lint-whitespace: add param to check last N commits
8dbf740 [scripts] lint-whitespace: check last N commits or unstaged changes (Sjors Provoost) Pull request description: E.g. before you push three commits to Github and upset Travis, check if you didn't make any whitespace mistakes: ```sh contrib/devtools/lint-whitespace.sh 3 ``` This is slightly more convenient than doing: ```sh TRAVIS_COMMIT_RANGE=HEAD~3...HEAD contrib/devtools/lint-whitespace.sh ``` Tree-SHA512: 5d9c1ae978ccbe59477e8cf53391e9bd697d2da87f417a2519264af560d4768138e0b2d320dd497a1f1e704e18ab279d724f523b57c17a80ccd753133a5445bf
2 parents 14475e2 + 8dbf740 commit 17c44b2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

contrib/devtools/lint-whitespace.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@
77
# Check for new lines in diff that introduce trailing whitespace.
88

99
# We can't run this check unless we know the commit range for the PR.
10+
11+
while getopts "?" opt; do
12+
case $opt in
13+
?)
14+
echo "Usage: .lint-whitespace.sh [N]"
15+
echo " TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
16+
echo " .lint-whitespace.sh -?"
17+
echo "Checks unstaged changes, the previous N commits, or a commit range."
18+
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
19+
exit 0
20+
;;
21+
esac
22+
done
23+
1024
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
11-
echo "Cannot run lint-whitespace.sh without commit range. To run locally, use:"
12-
echo "TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
13-
echo "For example:"
14-
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
15-
exit 1
25+
if [ "$1" ]; then
26+
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
27+
else
28+
TRAVIS_COMMIT_RANGE="HEAD"
29+
fi
1630
fi
1731

1832
showdiff() {

0 commit comments

Comments
 (0)