forked from dhis2/dhis2-android-capture-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit_windows.sample
More file actions
40 lines (31 loc) · 934 Bytes
/
pre-commit_windows.sample
File metadata and controls
40 lines (31 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
####### Instructions ########
# 1. Save this file in /.git/hooks directory of the project
# 2. Rename this file "pre-commit" file
##############################
#!/bin/sh
set -e
######## KTLINT-GRADLE HOOK START ########
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.kt/ { print $2}' | sed 's/\//\\/g')"
if [ -z "$CHANGED_FILES" ]; then
echo "No Kotlin staged files."
exit 0
fi;
echo "Running ktlint over these files:"
echo "$CHANGED_FILES"
./gradlew --continue ktlintCheck -PinternalKtlintGitFilter="$CHANGED_FILES"
echo "Completed ktlint run."
status=$?
if [ "$status" = 0 ]; then
echo "ktlint found no problems."
echo "$CHANGED_FILES" | while read -r file; do
if [ -f $file ]; then
git add $file
fi
done
exit 0
else
echo "Please fix before committing files."
exit 1
fi
echo "Completed ktlint hook."
######## KTLINT-GRADLE HOOK END ########