问题描述
我有一个后期结账
挂钩,我在本地使用了所有回购协议(它将我的tmux会话重命名为 repo-name / branch -
)
对于我正在开发的项目,我们只是添加了一个后结账
钩,我们要求整个团队使用。
我不想将个人钩子的逻辑添加到团队范围的钩子,因为它是对于每个人都没用,但我也不想放弃它。
有没有办法在单个git-hook触发器上执行多个脚本?我希望每一个 git checkout
执行团队范围的后结帐
钩子和执行我的个人结账后
挂钩。我无法将两个文件命名为相同的东西 - 有没有办法解决这个问题?
更新:一个好方法是,make post-checkout
调用其他两个脚本。我喜欢这个主意,这可能是解决方案。
post-checkout 复制到hooks目录中。如果可能,我想以不会干扰与现有团队设置,并且如果稍后再次运行安装步骤,则不需要手动调整。
如果这是不可能的,那很酷,但我对更有创意的解决方案感到好奇。
当然,创建一个包装器 code> post-checkout 调用其他脚本的钩子脚本: #!/ bin / sh
$ GIT_DIR / hooks / my-tmux-post-checkout$ @
$ GIT_DIR / hooks / corporate-post-checkout$ @
您可能会更喜欢并且遍历 post-checkout.d
目录中的任意数量的脚本,但是基本的想法是一样的。
更新史蒂夫
输入于 stdin
:
#!/ bin / sh
tmpfile = $(mktemp hookXXXXXX)
traprm -f $ tmpfileEXIT
cat> $ tmpfile
$ GIT_DIR / hooks / my-tmux-post-checkout$ @< $ tmpfile
$ GIT_DIR / hooks / corporate-post-checkout$ @< $ tmpfile
实际上这对第一种情况应该是无害的,但如果测试它通过手动运行它,您需要确保始终从某处重定向stdin(可能 / dev / null
)。
I have a post-checkout
hook that I use locally in all of my repos (it renames my tmux session to repo-name/branch-name
)
For a project I am working on, we just added a post-checkout
hook that we're asking the whole team to use.
I don't want to add my personal hook's logic to the team-wide hook, because it's not useful to everyone, but I also don't want to give it up.
Is there a way to have more than one script execute on a single git-hook trigger? I want every git checkout
to execute the teamwide post-checkout
hook and execute my personal post-checkout
hook. I can't have two files named the same thing -- is there a way to get around that?
Update: A good approach is, "make post-checkout
call the two other scripts. I like this idea, and it may be the solution.
However, right now we have an automated setup step that copies post-checkout
into the hooks directory. If possible, I'd like to do this in a way that doesn't interfere with the existing team setup, and doesn't require manual tweaking on my part if I run that install step again later.
If that's not possible, that's cool, but I'm curious about even more creative solutions.
Sure. Create a wrapper post-checkout
hook script that calls the other scripts:
#!/bin/sh
$GIT_DIR/hooks/my-tmux-post-checkout "$@"
$GIT_DIR/hooks/corporate-post-checkout "$@"
You could get fancier and iterate over an arbitrary number of scripts in a post-checkout.d
directory or something, but the basic idea is the same.
Update for Steve
For scripts that expect input on stdin
:
#!/bin/sh
tmpfile=$(mktemp hookXXXXXX)
trap "rm -f $tmpfile" EXIT
cat > $tmpfile
$GIT_DIR/hooks/my-tmux-post-checkout "$@" < $tmpfile
$GIT_DIR/hooks/corporate-post-checkout "$@" < $tmpfile
This should actually be harmless to use for the first case as well, although if you test it by running it manually you would need to make sure you always redirect stdin from somewhere (possibly /dev/null
).
这篇关于多个git挂钩用于同一个触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!