aboutsummaryrefslogtreecommitdiff
path: root/contrib/devtools/lint-whitespace.sh
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-03-06 23:14:06 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-03-06 23:17:26 +0100
commit17c44b208f1ced3dad372650d769d42d9e23fb35 (patch)
tree34bf94ac21b7892381eae8f08be93fe678e59535 /contrib/devtools/lint-whitespace.sh
parent14475e2dcdc8cc3a0ded2b1185fc6a9eb59102f3 (diff)
parent8dbf740f8055b095f172772d457acca56115d9d1 (diff)
Merge #12098: [scripts] lint-whitespace: add param to check last N commits
8dbf740f8 [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
Diffstat (limited to 'contrib/devtools/lint-whitespace.sh')
-rwxr-xr-xcontrib/devtools/lint-whitespace.sh24
1 files changed, 19 insertions, 5 deletions
diff --git a/contrib/devtools/lint-whitespace.sh b/contrib/devtools/lint-whitespace.sh
index 670a56285d..c5b9408ff2 100755
--- a/contrib/devtools/lint-whitespace.sh
+++ b/contrib/devtools/lint-whitespace.sh
@@ -7,12 +7,26 @@
# Check for new lines in diff that introduce trailing whitespace.
# We can't run this check unless we know the commit range for the PR.
+
+while getopts "?" opt; do
+ case $opt in
+ ?)
+ echo "Usage: .lint-whitespace.sh [N]"
+ echo " TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
+ echo " .lint-whitespace.sh -?"
+ echo "Checks unstaged changes, the previous N commits, or a commit range."
+ echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
+ exit 0
+ ;;
+ esac
+done
+
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
- echo "Cannot run lint-whitespace.sh without commit range. To run locally, use:"
- echo "TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
- echo "For example:"
- echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
- exit 1
+ if [ "$1" ]; then
+ TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
+ else
+ TRAVIS_COMMIT_RANGE="HEAD"
+ fi
fi
showdiff() {