NotallyX/.scripts/pre-commit

26 lines
663 B
Text
Raw Normal View History

2024-10-06 12:25:15 +02:00
#!/bin/sh
# Capture the list of initially staged Kotlin files
initial_staged_files=$(git diff --name-only --cached -- '*.kt')
if [ -z "$initial_staged_files" ]; then
echo "No Kotlin files staged for commit."
exit 0
fi
formatted_files=$(echo "$initial_staged_files" | sed 's|^app/||' | paste -sd "," -)
echo "Formatting Kotlin files: $formatted_files"
./gradlew ktfmtPrecommit --include-only="$formatted_files"
if [ $? -ne 0 ]; then
echo "Kotlin formatting failed. Please fix the issues."
exit 1
fi
2024-10-06 12:25:15 +02:00
# Re-stage only the initially staged Kotlin files
2024-10-31 13:17:37 +01:00
for file in $initial_staged_files; do
git add "$file"
done
echo "Kotlin files formatted"