Git post checkout 钩子在裸存储库上为上一个和当前头接收相同的值

发布于 2025-01-15 19:34:26 字数 702 浏览 2 评论 0原文

我在生产服务器上有一个裸存储库,每当合并请求获得批准时,就会更新该存储库(利用 Gitlab 中的 Webhook)。

存储库更新如下:

git fetch origin master:master

git --work-tree=/home/prod/git/ --git-dir/=/path/to/bare-repo.git checkout -f

我想使用 post-checkout 挂钩来验证 conda 环境文件是否已更改;挂钩内容:

#!/bin/sh

prevHEAD=$1
newHEAD=$2
checkoutType=$3

changed_files="$(git diff-tree -r --name-only --no-commit-id  $prevHEAD $newHEAD)"

不幸的是,每次触发结账时,我不清楚为什么会发生这种情况, prevHEAD 和 newHEAD 变量总是相同的。每次结账时,这些值本身都会有所不同,但它们总是相互匹配。

假设无法使用此方法,那么识别特定文件是否已更改的最佳方法是什么?

在其他地方,我读过使用推送部署模型。这将需要替换 fetch &使用 git Push 代替 checkout 命令,并利用 post-receive 挂钩。我会研究这个,但考虑到 fetch &结帐已经工作正常,如果可能的话,我宁愿不更改该设置。

I've got a bare repo on a production server, which is updated (utilising a webhook in Gitlab) whenever a merge request is approved.

The repo is updated like so:

git fetch origin master:master

git --work-tree=/home/prod/git/ --git-dir/=/path/to/bare-repo.git checkout -f

I would like to use the post-checkout hook to verify whether a conda environment file was changed; Content of the hook:

#!/bin/sh

prevHEAD=$1
newHEAD=$2
checkoutType=$3

changed_files="$(git diff-tree -r --name-only --no-commit-id  $prevHEAD $newHEAD)"

Unfortunately everytime the checkout is triggered, and I'm not clear on why this happens, prevHEAD and newHEAD variables are always the same. The values themselves differ on every checkout, however, they always match each other.

Assuming this method can't be used, what would be the best way to identify whether a particular file was changed?

Elsewhere I've read to use push-to deploy model. This would require replacing the fetch & checkout commands with a git push instead, and utilising post-receive hook. I'll look into this, but given that the fetch & checkout already work fine, I'd prefer not changing that setup if possible at all.

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

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

发布评论

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

评论(1

执笏见 2025-01-22 19:34:26

作为解决方法,我使用 git log 来检索当前和以前的头 ID:

prevHead=$(git log --pretty="%h" --merges -1 --skip=1)
newHead=$(git log --pretty="%h" --merges -1)

As a work around I used the git log to retrieve current and previous head id's:

prevHead=$(git log --pretty="%h" --merges -1 --skip=1)
newHead=$(git log --pretty="%h" --merges -1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文