Skip to content

Commit bc9a467

Browse files
Merge pull request #110 from cavega/master
Pre commit hook for lint #109
2 parents 61b1501 + 7448337 commit bc9a467

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ To avoid memory leaks is your code, you must dispose the buttons in the onDestro
101101

102102
progressButton.dispose()
103103
}
104+
105+
106+
## Contributing
107+
###Setup Git Pre-commit hook script (Optional)
108+
109+
The purpose of setting up this optional pre-commit hook is so that the `lintKotlin` Gradle task runs each time you as a developer create a commit. Although the Travis build will run `lintKotlin` in the cloud, running this locally will allow you to catch Kotlin Lint violations early in the development cycle without having to wait for Travis's build report.
110+
111+
To enable the script, execute the following commands starting from the project's root directory:
112+
113+
cd .git/hooks
114+
ln -s ../../scripts/pre-commit.sh pre-commit
104115

105116
## Bugs and Feedback
106117

scripts/pre-commit.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
abort()
4+
{
5+
echo >&2 '
6+
***************
7+
*** ABORTED ***
8+
***************
9+
'
10+
echo "An error occurred. Exiting..." >&2
11+
exit 1
12+
}
13+
14+
trap 'abort' 0
15+
16+
set -e
17+
set -o pipefail
18+
19+
# Add your script below....
20+
# If an error occurs, the abort() function will be called.
21+
#----------------------------------------------------------
22+
# ===> Your script goes here
23+
24+
# pre-commit.sh
25+
STASH_NAME="pre-commit-$(date +%s)"
26+
git stash save -q --keep-index $STASH_NAME
27+
28+
# Run lintKotlin task
29+
./gradlew lintKotlin
30+
31+
STASHES=$(git stash list)
32+
if [[ $STASHES == "$STASH_NAME" ]]; then
33+
git stash pop -q
34+
fi
35+
36+
# Done!
37+
trap : 0
38+
39+
echo >&2 '
40+
************
41+
*** DONE ***
42+
************
43+
'
44+

0 commit comments

Comments
 (0)