Created
January 17, 2021 07:18
-
-
Save gpeal/5fce5b443c155fbbcc2fa0d5b9300133 to your computer and use it in GitHub Desktop.
This file contains 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/bash -e | |
# Run Detekt on pre-push on changed files | |
cd Android | |
while read -r local_ref local_sha remote_ref remote_sha; do | |
if [[ "$local_sha" =~ ^0+$ ]]; then | |
# Handle delete | |
: | |
else | |
if [[ "$remote_sha" =~ ^0+$ ]]; then | |
# New branch: find first parent that exists on remote to compute diff | |
remote_sha=$( | |
git rev-list "$local_sha" | while read -r ref; do | |
remote_branches=$( git branch -r --contains "$ref" ) | |
if [ -n "$remote_branches" ]; then | |
printf "%s" "$ref" | |
break | |
fi | |
done | |
) | |
fi | |
range="$remote_sha..$local_sha" | |
# List Added (A), Copied (C), Modified (M), Renamed (R), have their type changed (T) files | |
IFS= read -rd '' changed_files < <( git diff --name-only --relative --diff-filter=ACMRT "$range" "**/src/main/**/*.kt" ) || true | |
echo "Commit range: $range; number of changed kt files: $( printf "%s" "$changed_files" | wc -l | xargs )" | |
if [ -n "$changed_files" ] | |
then | |
# `paste -sd "," -` replaces newlines with commas | |
./detekt -i "$( printf "%s" "$changed_files" | paste -sd "," - )" | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment