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

标签 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

最佳答案

找到的解决方案:

#!/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

关于git - 如何将错误从git-hooks打印到Android Studio事件日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55629974/

相关文章:

Python 用意外的间距诅咒 Git 子进程输出

git - Xcode 5 - 未找到 Remote

python - GitPython 检查 git pull 是否更改了本地文件

android-studio - 错误 :(1, 0) 未找到 ID 为 'kotlin-android-extensions' 的插件

git - 理解 Git Hook - post-receive hook

git - 为什么git不 pull ?

Android Studio SVN 1.8 此客户端太旧,无法使用工作副本

git - 禁用 Android Studio 中的新 Git 分支选项

bash - 从 git hook 调用脚本

Git 钩子(Hook)检测包含特定字符串的文件更改