Skip to content

Instantly share code, notes, and snippets.

@aiKrice
Created February 25, 2024 21:04
Show Gist options
  • Select an option

  • Save aiKrice/eab2120b53ba34f8649f9b15be6a527f to your computer and use it in GitHub Desktop.

Select an option

Save aiKrice/eab2120b53ba34f8649f9b15be6a527f to your computer and use it in GitHub Desktop.
AndroidLint: pre-commit
#!/bin/sh
# Get kotlin files that are staged
staged_files=$(git diff --cached --name-only --diff-filter=d | grep ".kt$")
# Check if we have any Kotlin files to format
if [[ "$staged_files" = "" ]]; then
echo "Android lint skipped: No source files to format."
exit 0
fi
./gradlew lint
if [ $? -ne 0 ]; then
echo "Android lint failed, commit denied"
exit 1
fi
# Add changes to git
echo "$staged_files" | xargs git add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment