forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·25 lines (20 loc) · 788 Bytes
/
pre-commit
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
#!/bin/sh
set -e
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.kts|\.kt/ { print $2 }')"
if [ -z "$CHANGED_FILES" ]; then
echo "No Kotlin staged files. Hence, skipping pre-commit Ktlint run."
exit 0
fi;
echo "Running Ktlint over these files:"
echo "$CHANGED_FILES"
# -q removes noise from the output if it fails.
# TODO: -w is better, but https://github.com/JLLeitschuh/ktlint-gradle/issues/457 adds noise
# -w should display: "CriticalExceptionTest.kt:19:1 Wildcard import (cannot be auto-corrected)"
./gradlew -q ktlintFormat
echo "Completed ./gradlew ktlintFormat run."
echo "$CHANGED_FILES" | while read -r file; do
if [ -f "$file" ]; then
git add "$file"
fi
done
echo "Completed the pre-commit hook."