gpt4 book ai didi

git - 多个 git post-receive 钩子(Hook)

转载 作者:太空狗 更新时间:2023-10-29 14:44:55 28 4
gpt4 key购买 nike

我正在使用 Gitlab。 Gitlab 正在创建以下链接以通过所有存储库分发相同的 Hook

hooks -> /opt/gitlab/embedded/service/gitlab-shell/hooks

在此目录中,已经有一个 post-receive Hook ,用于在 Gitlab 中正确处理提交,它是用 ruby​​ 编写的。我想添加一个用 bash 编写的附加钩子(Hook)。这可能吗?

最好的问候

最佳答案

Gitlab 在 $GIT_DIR/custom_hooks directory 中支持项目 Hook .

这支持 pre-receive , post-receiveupdate钩子(Hook)。

来自上面的网页:

Normally, git hooks are placed in the repository or project's hooks directory. GitLab creates a symlink from each project's hooks directory to the gitlab-shell hooks directory for ease of maintenance between gitlab-shell upgrades. As such, custom hooks are implemented a little differently. Behavior is exactly the same once the hook is created, though. Follow these steps to set up a custom hook.

  1. Pick a project that needs a custom git hook.
  2. On the GitLab server, navigate to the project's repository directory. For an installation from source the path is usually /home/git/repositories/<group>/<project>.git. For Omnibus installs the path is usually /var/opt/gitlab/git-data/repositories/<group>/<project>.git.
  3. Create a new directory in this location called custom_hooks.
  4. Inside the new custom_hooks directory, create a file with a name matching the hook type. For a pre-receive hook the file name should be pre-receive with no extension.
  5. Make the hook file executable and make sure it's owned by git.
  6. Write the code to make the git hook function as expected. Hooks can be in any language. Ensure the 'shebang' at the top properly reflects the language type. For example, if the script is in Ruby the shebang will probably be #!/usr/bin/env ruby.

That's it! Assuming the hook code is properly implemented the hook will fire as appropriate.

运行多个相同类型的钩子(Hook)

现在可以像任何其他 git 存储库一样完成此操作:编写委托(delegate)脚本以将操作转发给您想要触发的所有 Hook 实现。例如:

#!/bin/bash

# Allow to run multiple hooks
# For each hook type (post-receive, post-update, ...) create a type.d subdirectory, e.g. post-receive.d/
# Then put all hook scripts into that directory and make them executable.

# Requires the "pee" utility from moreutils package: http://joeyh.name/code/moreutils/ or use "apt install moreutils"
# pee duplicates stdinput to all scripts

script_dir=$(dirname $0)
hook_name=$(basename $0)

hook_dir="$script_dir/$hook_name.d"
if [[ -d $hook_dir ]]; then
pee $hook_dir/* $*
fi

exit 0

关于git - 多个 git post-receive 钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33690788/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com