【问题标题】:Git hooks doesn't work on Source TreeGit 钩子在源代码树上不起作用
【发布时间】:2018-06-28 04:38:46
【问题描述】:

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

这是我的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

【问题讨论】:

  • 什么不起作用?是不是被执行了?还是执行时出现错误消息?
  • issue修复
  • 通过添加export PATH=/usr/local/bin:$PATH
  • 太棒了!将此添加为答案:您可以接受自己的答案。这会帮助其他人。

标签: git atlassian-sourcetree githooks


【解决方案1】:

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

源码树issue

【讨论】:

  • 我把这个字符串直接添加到文件顶部的预提交文件中
【解决方案2】:

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

open /Applications/Sourcetree.app

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

【讨论】:

  • 所以每次我必须用终端打开SourceTree而不是直接通过系统?
  • @ShoebMirza 这对我有用。也许有更好的方法。我很快就习惯了。
  • 只有当我使用终端而不是直接通过系统打开 SourceTree 时它才对我有用
  • 您还可以安装 SourceTree 命令行工具(在 SourceTree 应用程序中作为菜单选项提供),然后从命令行运行 stree。 (见this comment。)
  • 很有趣,有效,但这如何解决问题?
【解决方案3】:

这适用于 OSX,使用

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

【讨论】:

    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-06
        • 2016-03-30
        • 1970-01-01
        • 2015-12-22
        • 2011-06-02
        • 1970-01-01
        相关资源
        最近更新 更多