git预推钩,如果是--tags,则不运行 [英] git pre-push hook, don't run if is --tags

查看:97
本文介绍了git预推钩,如果是--tags,则不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试我的代码的prepush钩子,但是,当我执行 git push --tags 时,它也会运行。有没有什么办法可以避免这种情况?

可能有一些方法可以检查它的常规推送,或者它的一个 - tags c $ c> push?



更新 - 这是我能够找到的唯一参数:




  • $ 1是远程的名称
  • $ 2是推送完成的url


解决方案

我有一个解决方案,但它确实是 kludgey。前一阵子,我设置了一个预先提交的钩子来阻止我在文件启动时意外地使用 -a 。我的解决方案是读取调用原始git命令的命令(也许只能在linux上运行)。

$ c> while read read -d $'\ 0'arg;如果[[$ arg=='--tags']]做
;那么
出口0
fi
完成< / proc / $ PPID / cmdline
#并在此执行您的支票

原创



这就是说,尝试调用 env 在钩子中; git设置了一些额外的变量(以 GIT _ 前缀开头,如 GIT_INDEX_FILE )。


I have a prepush hook that tests my code, however, it also runs when I do a git push --tags. Is there any way to avoid this?

Maybe there's some way to check if its a regular push or if its a --tags push?

Update - These are the only arguments I was able to find:

  • $1 is the name of the remote
  • $2 is url to which the push is being done

解决方案

I have a solution to this, but it's really kludgey. A while back, I set up a pre-commit hook to stop me from accidentally using -a when I have files staged. My solution is to read the command that invoked the original git command (probably only works on linux too).

while read -d $'\0' arg ; do
    if [[ "$arg" == '--tags' ]] ; then
        exit 0
    fi
done < /proc/$PPID/cmdline
# and perform your check here

Original

That being said, try calling env in the hook; git sets a few extra vars (starting with GIT_ prefixes, like GIT_INDEX_FILE).

这篇关于git预推钩,如果是--tags,则不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆