Created
August 18, 2022 15:05
-
-
Save laithnurie/90a30b5e8e8abd39175b9070c2673359 to your computer and use it in GitHub Desktop.
Pre push hook android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
filesToFormat="$( | |
git --no-pager diff --cached --diff-filter=d --name-only | |
)" | |
echo '[git hook] executing gradle detekt and lint before push' | |
SHOULD_RESET=0 | |
if [[ -n $(git status -s) ]]; then | |
echo '[git hook] there are uncommited changes, stashing them' | |
# there are uncommited changes, stage them | |
git stash -qu --keep-index | |
SHOULD_RESET=1 | |
fi | |
CHANGELOG_BEFORE_FIX="$(git diff HEAD)" | |
echo '[git hook] running detektFix' | |
./gradlew detektFix > /dev/null | |
CHANGELOG_BEFORE_FIX="$(git diff HEAD)" | |
if [[ $SHOULD_RESET -eq 1 ]]; then | |
echo '[git hook] restoring uncommited changes from stash' | |
git reset --hard HEAD > /dev/null | |
# unstash the unstashed changes | |
git stash pop -q | |
echo '[git hook] running detektFix' | |
./gradlew detektFix > /dev/null | |
fi | |
if [[ "$CHANGELOG_BEFORE_FIX" != "$CHANGELOG_BEFORE_FIX" ]]; then | |
echo "[git hook] detekFix changed formatting on your files. Please commit the changes before pushing them" | |
exit -1 | |
fi | |
for sourceFilePath in $filesToFormat | |
do | |
git add "$sourceFilePath" | |
done; | |
echo "[git hook] executing gradle detekt before push" | |
./gradlew detektCheck | |
if [[ $? -ne 0 ]]; then | |
echo "[git hook] detekt found errors in your changes" | |
exit -1 | |
fi | |
echo "[git hook] running Lint debug" | |
./gradlew lintDebug | |
if [[ $? -ne 0 ]]; then | |
echo "[git hook] lint Debug failed" | |
exit -1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment