我有git-hook:
预提交
#!/bin/bash
java -jar ktlint --color "/\**/src/**/*.kt"
if [[ $? -gt 0 ]]; then
echo -e "\033[0;31mKotlin Code style violation. Please check errors above!\033[0m\n"
echo -e "Hint: use \"./ktlint -F <file pattern>\" for autocorrection.\n"
exit 1
fi
当我使用终端命令时:
>git commit -m "Any message"
但是当我使用Android Studio
-> VCS
-> Commit...
Ctrl + K
输出在Event Log
中,并且无法理解:
答案 0 :(得分:0)
找到解决方案:
#!/bin/sh
KOTLIN_LINTER_FILE=ktlint
TEMP_DIRECTORY=.temp
git diff --name-only --cached --relative | grep '.*kt$' | xargs ${TEMP_DIRECTORY}\\${KOTLIN_LINTER_FILE} --relative .
if [[ $? -ne 0 ]]; then exit 1; fi