Open mobilekosmos opened 1 year ago
Can you share the commit hook file that was generated for you?
I htink it always generates the same file:
#!/bin/sh
######## KTLINT-GRADLE HOOK START ########
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $NF ~ /\.kts?$/ { print $NF }')"
if [ -z "$CHANGED_FILES" ]; then
echo "No Kotlin staged files."
exit 0
fi;
echo "Running ktlint over these files:"
echo "$CHANGED_FILES"
diff=.git/unstaged-ktlint-git-hook.diff
git diff --color=never > $diff
if [ -s $diff ]; then
git apply -R $diff
fi
./gradlew --quiet ktlintCheck -PinternalKtlintGitFilter="$CHANGED_FILES"
gradle_command_exit_code=$?
echo "Completed ktlint run."
if [ -s $diff ]; then
git apply --ignore-whitespace $diff
fi
rm $diff
unset diff
echo "Completed ktlint hook."
exit $gradle_command_exit_code
######## KTLINT-GRADLE HOOK END ########
Just stumbled up this, probably resolved already, but in your case the script only seems to look for changed .kts
files.
Try changing the CHANGED_FILES
assignment to:
CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $NF ~ /\.kts|\.kt/ { print $NF }')"
if I add the plug-in and run
gradlew ktlintCheck
in the Android Studio terminal the checks works, but if I generate the git hook with gradlew addKtlintCheckGitPreCommitHook, the file pre-commit is generated but then when committing the check doesn't find any issues. What I see in the console is: