Git钩子不适用于源代码树

时间:2018-06-28 04:38:46

标签: git atlassian-sourcetree githooks

通过终端,一切正常,但在“源树”中不起作用

这是我的pre-commit钩子

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

5 个答案:

答案 0 :(得分:1)

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

修复

源树issue

答案 1 :(得分:0)

这在OSX上有效,用

更新〜/ .bash_profile。
export PATH="/usr/local/bin:$PATH"

答案 2 :(得分:0)

对我来说,我必须通过命令行打开Sourcetree

open /Applications/Sourcetree.app

从这里(SourceTree-Hook-failing-because-paths-don-t-seem-to-be-set

答案 3 :(得分:0)

在我的情况下,导出路径不起作用。我不得不重新安装 husky 并重新启动 sourcetree。然后一切又恢复了。

答案 4 :(得分:0)

通过执行 git config --global core.hooksPath '~/.githooks' 命令修复

我已将 core.hooksPath 设置为错误的目录。 使用 git config --global core.hooksPath '~/.githooks'

重置它