如何将错误从git-hooks打印到Android Studio事件日志?

时间:2019-04-11 10:10:19

标签: git android-studio githooks

我有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"

输出在terminal,对我来说没关系: enter image description here

但是当我使用Android Studio-> VCS-> Commit... Ctrl + K 输出在Event Log中,并且无法理解:enter image description here

1 个答案:

答案 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