2024-10-06 12:25:15 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-10-29 17:47:29 +01:00
|
|
|
# Capture the list of initially staged Kotlin files
|
|
|
|
initial_staged_files=$(git diff --name-only --cached -- '*.kt')
|
2024-10-11 16:45:10 +02:00
|
|
|
|
2024-10-29 17:47:29 +01:00
|
|
|
if [ -z "$initial_staged_files" ]; then
|
|
|
|
echo "No Kotlin files staged for commit."
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-10-11 16:45:10 +02:00
|
|
|
|
2024-10-29 17:47:29 +01:00
|
|
|
formatted_files=$(echo "$initial_staged_files" | sed 's|^app/||' | paste -sd "," -)
|
|
|
|
echo "Formatting Kotlin files: $formatted_files"
|
|
|
|
./gradlew ktfmtPrecommit --include-only="$formatted_files"
|
2024-10-11 16:45:10 +02:00
|
|
|
|
2024-10-29 17:47:29 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Kotlin formatting failed. Please fix the issues."
|
|
|
|
exit 1
|
2024-10-11 16:45:10 +02:00
|
|
|
fi
|
2024-10-06 12:25:15 +02:00
|
|
|
|
2024-10-29 17:47:29 +01: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
|
2024-10-29 17:47:29 +01:00
|
|
|
|
|
|
|
echo "Kotlin files formatted"
|