【问题标题】:Bypass post-receive hook git绕过 post-receive 钩子 git
【发布时间】:2014-05-13 12:06:00
【问题描述】:

有没有办法显式绕过触发接收后挂钩?意思是在推送提交后 post-receive 钩子不会运行。

【问题讨论】:

    标签: git push githooks


    【解决方案1】:

    在接收端(服务器端)单独使用 git 似乎是不可能的:您需要自定义您的钩子以允许这种情况(跳过)发生。
    这与 you can skip (for some of them) 的本地挂钩不同。

    参见“Skip processing of Git revisions in post-receive hook that have already been previously processed”中的例如钩子(这是关于部分跳过一些提交,但想法相似)

    【讨论】:

      【解决方案2】:

      使用push-options 可以跳过post-receive 钩子。

      要实现这一目标,您需要三种成分:

      1)

      根据man githookspost-receive 部分:

      git push --push-option=... 命令行给出的推送选项个数可以从环境变量GIT_PUSH_OPTION_COUNT中读取,选项本身在GIT_PUSH_OPTION_0, GIT_PUSH_OPTION_1,...中找到协商为不使用推送选项阶段,则不会设置环境变量。如果客户端选择使用推送选项,但不传输任何选项,则计数变量将设置为零,GIT_PUSH_OPTION_COUNT=0。

      所以你可以像这样准备你的post-receive钩子脚本:

      if [ "x${GIT_PUSH_OPTION_COUNT}" = "x0" ] ; then
          exec /usr/share/buildbot/contrib/git_buildbot.py --master=172.16.1.1:8989 --auth="***" --category=yaal --project=yaal --repository=yaal "${@}"
      fi
      

      2)

      根据git-config-receiveadvertisePushOptions

      当设置为 true 时,git-receive-pack 将向其客户端通告推送选项功能。默认为假。

      所以你需要像这样在你的遥控器上添加这个配置:

      git config receive.advertisePushOptions true
      

      或者手动编辑你的 project.git/config

      3)

      对于您不想让 post-receive 挂钩触发的推送,只需添加虚拟推送选项,如下所示:

      git push -o blah
      

      使用$GIT_PUSH_OPTION_(n),您可以使您的推送更加复杂。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      • 2011-04-15
      • 2012-02-17
      • 2013-06-26
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多