Git 钩子(Hook)不适用于源代码树

标签 git atlassian-sourcetree githooks

通过终端一切正常但在源代码树中不工作

这是我的预提交 Hook

#!/bin/bash
#
# hook script for swiftlint. It will triggered when you make a commit.
#
# If you want to use, type commands in your console.
# $ ln -s ../../pre-commit-swiftlint.sh .git/hooks/pre-commit
# $ chmod +x .git/hooks/pre-commit

LINT=$(which swiftlint)

if [[ -e "${LINT}" ]]; then
   echo "SwiftLint Start..."
else
echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint"
exit 1
fi

RESULT=$($LINT lint --quiet)

if [ "$RESULT" == '' ]; then
printf "\e[32mSwiftLint Finished.\e[39m\n"
else
echo ""
printf "\e[41mSwiftLint Failed.\e[49m Please check below:\n"

while read -r line; do

    FILEPATH=$(echo $line | cut -d : -f 1)
    L=$(echo $line | cut -d : -f 2)
    C=$(echo $line | cut -d : -f 3)
    TYPE=$(echo $line | cut -d : -f 4 | cut -c 2-)
    MESSAGE=$(echo $line | cut -d : -f 5 | cut -c 2-)
    DESCRIPTION=$(echo $line | cut -d : -f 6 | cut -c 2-)
    if [ "$TYPE" == 'error' ]; then
        printf "\n  \e[31m$TYPE\e[39m\n"
    else
        printf "\n  \e[33m$TYPE\e[39m\n"
    fi
    printf "    \e[90m$FILEPATH:$L:$C\e[39m\n"
    printf "    $MESSAGE - $DESCRIPTION\n"
done <<< "$RESULT"

printf "\nCOMMIT ABORTED. Please fix them before commiting.\n"

exit 1
fi

最佳答案

通过添加 export PATH=/usr/local/bin:$PATH 修复

源代码树 issue

关于Git 钩子(Hook)不适用于源代码树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51074821/

相关文章:

git - 如何在 git push 后运行 bash 脚本

ruby-on-rails - 找出已安装 gem 的来源

git - 撤销 git remove

git - SourceTree 可以并排显示差异吗

git - 我如何在远程 Hook git pull?

git - 如何处理 `pre-receive` git 脚本中的新分支?

git - git 中的 hg addremove

git - 在 Pydev 中设置 Github 存储库的正确方法?

git - SourceTree - 致命无法创建 .git/index.lock 文件存在

macos - 从存储库中删除奇怪的 'Iconr' 文件