特定存储库的 gitolite 挂钩

发布于 2024-12-18 20:39:07 字数 317 浏览 1 评论 0原文

我不明白如何为 gitolite 中的特定存储库创建接收后挂钩(非 root 安装)

我的裸存储库包含一个网站,该网站应将工作目录复制到 docRoot (GIT_WORK_TREE=/path/htdocs git checkout -f) on update

在 gitolite 之前,我只会更新特定存储库的挂钩。
Gitolite 文档提到所有钩子都应该位于 hooks/common ,所以我不明白它是如何工作的。

钩子的名称应该是什么,它应该位于哪里以及它的结构应该如何改变(如果应该的话)?

I don't understand how do I create a post-receive hook for a specific repository in gitolite (non-root install)

My bare repository contains a website that should copy the working directory to the docRoot
(GIT_WORK_TREE=/path/htdocs git checkout -f) on update

Before gitolite, I would just update the hook for the specific repository.
Gitolite documentation mentions that all hooks should be at hooks/common so I don't understand how it works.

What should be the name of hooks, where it should be located and how it's structure should be changed (if it should)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

垂暮老矣 2024-12-25 20:39:07

2013 年 7 月更新:以下内容适用于 gitolite V2(或“g2”),这是 OP 当时(2011 年 11 月)使用的版本。

2013 年 8 月更新,使用最新的 gitolite 3.x:
您现在拥有官方特定存储库挂钩

它基本上只是在 /hooks 中创建一个符号链接,指向 $rc{LOCAL_CODE}/hooks/repo-specific 中的某个文件(除了gitolite-admin 存储库)


gitolite/hooks/common 中的所有钩子都会复制到 Gitolite 管理的所有存储库中,详细信息请参见 钩子传播文档
这意味着您的钩子脚本必须根据执行所述钩子的存储库采取特定操作。

您可以使用 $GL_REPO 变量(gitolite 设置该变量并将其传递给它接收的任何 git 命令的所有脚本)。

或者您可以使用在 gitolite 服务器上注册的一些 git 配置,例如 镜像挂钩。请参阅 post-receive.mirrorpush 钩子

OP Eyal R 在评论中添加:

但我仍然不明白它是如何完成的(我知道 $GL_REPO 用于确定我正在更新哪个存储库,但我缺少实际部分)。
我用 echo "test" 创建了一个名为 post-receive.test 的文件,将其放入 $HOME/gitolite/hooks/common 中,运行 gl-setup,从工作站运行推送 - 没有任何反应(没有“test”输出)

我对此回复:

该挂钩应作为链接出现在 gitolite 服务器上存储库的 hook 目录中,链接回 .gitolite/common/hook。请注意,它应该位于 $HOME/.gitolite/common/hook 中,而不是 /gitolite 中。

OP 确认缺少的点是问题所在。

添加钩子的过程在 gitolite 中的钩子传播中有详细介绍,其用法在“ 使用 Hooks”。

Update July 2013: what follows is for gitolite V2 (or 'g2'), which was the version used by the OP at the time (November 2011).

Update August 2013, with the latest gitolite 3.x:
You now have official specific repo hook:

it's basically just creating a symlink in <repo.git>/hooks pointing to some file inside $rc{LOCAL_CODE}/hooks/repo-specific (except the gitolite-admin repo)


All hooks in gitolite/hooks/common are replicated in all repositories managed by Gitolite, as detailed in the hook propagation documentation.
That means your hook script must take specific action depending on the repo which execute said hook.

You can either use the $GL_REPO variable (which gitolite set and pass to all its scripts for any git command it receives).

Or you can use some git configuration registered on the gitolite server, like the mirroring hook does. See the post-receive.mirrorpush hook.

The OP Eyal R adds in the comments:

But I still don't understand how it is done (I understand that $GL_REPO is used to determine which repo I am updating but I'm missing the practical part).
I have created a file called post-receive.test with echo "test", put it in $HOME/gitolite/hooks/common, ran gl-setup, ran push from workstation - nothing happens (no "test" output)

To which I replied:

The hook should appear in the hook directory of your repo on the gitolite server as a link, linking back to the .gitolite/common/hook. Note that it should be in $HOME/.gitolite/common/hook, not /gitolite.

The OP confirms the missing dot was the issue.

The process to add an hook is detailed in Hook propagation in gitolite, and their usage in "Using Hooks".

拔了角的鹿 2024-12-25 20:39:07

对于使用 gitolite 的人来说,这是一个相当普遍的需求,并且当不是一个非常高级的用户时,似乎有点难以解决未解决的问题(至少对我来说是这样)。

来回跟踪 stackoverflow 和 gitolite 的链接可能会有点令人困惑。这些是我的结论以及我为实现这一目标所遵循的道路。

正如 @VonC 提到的,自 版本 3.5.3.1 (<一个href="https://github.com/sitaramc/gitolite/commit/62fb31755abb7ad93e17a6fe8880b74eb17086fa" rel="nofollow noreferrer">github 链接)

更新/升级 Gitolite

你应该做的第一件事正在更新您的 gitolite 存储库。因此,ssh 进入托管 gitolite 的服务器,并以 git 用户(通常 )身份移动到安装 gitolite 的位置(通常 /home/git/gitolite) git)

示例:

$ ssh [email protected]
$ sudo su - git
$ pwd
/home/git
$ cd gitolite

然后我们必须升级 gitolite。为此,首先我们需要更新 gitolite 存储库

$ git pull

然后我们必须重复 install 命令(确保使用与之前相同的参数)

$ ./install

最后再次运行安装程序。

$ gitolite setup

如果这不起作用,您可能还没有在 PATH 中设置 gitolite 可执行文件,因此您可以执行以下操作:

$ src/gitolite setup

Gitolite Settings (The "RC"文件)

这是最让我困惑的部分之一,但最终它非常简单。

著名的“rc”文件位于 git 的主目录 /home/git/.gitolite.rc 中。确保您有一个名为 LOCAL_CODE 的变量,您应该在该文件上看到类似的内容,如果没有,请添加它。

LOCAL_CODE => "$ENV{HOME}/.gitolite/local"

在“命令启用功能”部分中,您应该确保 repo-specific-hooks 可用,如果不可用,请添加它。

ENABLE => [

    # COMMANDS

        # These are the commands enabled by default
        'help',
        'desc',
        'info',
        ...,
        ...,
        ...,
        'repo-specific-hooks'
        ...,
        ...,
        ...
]

这是文档的链接

编写存储库特定的挂钩

最后,在您的 local gitolite-admin 存储库中,在您刚刚在中设置的目录下创建以下目录 hooks/repo-specific LOCAL_CODE 变量,例如:

gitolite_admin/local/hooks/repo-specific

之后,您实际上可以将钩子脚本添加到该位置,并通过 gitolite conf 文件管理它们,如 文档中所述。确保脚本可执行。

repo foo
RW+                       =   @all
option hook.post-receive  =   deploy

再次,我希望这对你们中的一些人有所帮助。

干杯!

This is a fairly common need for someone using gitolite, and appears to be a little difficult to tie up loose ends when being not a very advanced user (at leas it was for me).

Following stackoverflow's and gitolite's links back and forth can be a little confusing. These are my conclusions and the path I followed to be able to achieve this.

As @VonC mentioned creating repository specific hooks is already possible since version 3.5.3.1 (github link)

Update/Upgrade Gitolite

The first thing you should do is update your gitolite repo. So ssh into your server that is hosting gitolite and move to the location where gitolite is installed (usually /home/git/gitolite) as the git user (usually git)

Example:

$ ssh [email protected]
$ sudo su - git
$ pwd
/home/git
$ cd gitolite

Then we have to upgrade gitolite. To do so, first we need to update the gitolite repository

$ git pull

Then we have to repeat the install command (make sure you use the same arguments as before)

$ ./install

And finally run the setup again.

$ gitolite setup

If that doesn't work, you probably haven't set up gitolite executable in your PATH, so you could do something like this:

$ src/gitolite setup

Gitolite Settings (The "RC" file)

This was one of the parts that confused me the most, but it ended up it was pretty straight forward.

The famous "rc" file is located at git's home directory /home/git/.gitolite.rc. There make sure you have a variable called LOCAL_CODE, you should see something like this on that file, if not, add it.

LOCAL_CODE => "$ENV{HOME}/.gitolite/local"

And in the "commands an feature to enable" section you should make sure that repo-specific-hooks is available, if not, add it.

ENABLE => [

    # COMMANDS

        # These are the commands enabled by default
        'help',
        'desc',
        'info',
        ...,
        ...,
        ...,
        'repo-specific-hooks'
        ...,
        ...,
        ...
]

Here is the link to the documentation

Writing Repository Specific Hooks

Finally, in your local gitolite-admin repository create the following directories hooks/repo-specific under the directory you just set in the LOCAL_CODE variable, for example:

gitolite_admin/local/hooks/repo-specific

After that you can actually add your hooks scripts to that location and manage them through the gitolite conf file as stated in the documentation. Make sure the scripts are executable.

repo foo
RW+                       =   @all
option hook.post-receive  =   deploy

Again, I hope this helps some of you guys.

Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文