[英]Duplicating git client hooks on the server side
I've defined a post-commit hook in .git/hooks
that I want to also execute on the server side ( Gitlab.com in my case).我已经在
.git/hooks
中定义了一个提交后.git/hooks
,我也想在服务器端(在我的例子中是Gitlab.com )执行它。
Background: I'm using gitinfo2 along with a post-commit hook in a LaTeX project to quote info about the latest git tag within the pdf.背景:我在 LaTeX 项目中使用 gitinfo2 和 post-commit 钩子来引用有关 pdf 中最新 git 标签的信息。 This works well on my computer, but fails when I push the repo to Gitlab.
这在我的计算机上运行良好,但是当我将 repo 推送到 Gitlab 时失败了。
It doesn't cause an error, but gives the following warning, which basically means that the git hook never executed.它不会导致错误,但会给出以下警告,这基本上意味着 git hook 从未执行过。
Package gitinfo2 Warning: I can't find the file '.git/gitHeadInfo.gin'.
(gitinfo2) All git metadata has been set to '(None)'.
From what I've read online so far, client side git hooks don't execute on the server - but why not?从我目前在线阅读的内容来看,客户端 git 钩子不会在服务器上执行 - 但为什么不呢? In a situation like this, I would want the hook to execute on both the client and the server.
在这种情况下,我希望钩子在客户端和服务器上都执行。
So, basically, I want the sequence of events to be like this:所以,基本上,我希望事件的顺序是这样的:
gitHeadInfo.gin
being created in the .git
folder..git
文件夹中创建一个名为gitHeadInfo.gin
的文件。gitinfo
package helping to pull the git version info from gitHeadInfo.gin
. gitinfo
包有助于从gitHeadInfo.gin
提取 git 版本信息。 I've got everything working except step 3. So, my current workaround is to build the pdf on my computer as well and commit it rather than relying on Gitlab CI.除了第 3 步之外,我已经完成了所有工作。因此,我目前的解决方法是也在我的计算机上构建 pdf 并提交它,而不是依赖 Gitlab CI。
Contents of the git hook: git 钩子的内容:
#!/bin/sh
# Copyright 2015 Brent Longborough
# Part of gitinfo2 package Version 2
# Release 2.0.7 2015-11-22
# Please read gitinfo2.pdf for licencing and other details
# -----------------------------------------------------
# Post-{commit,checkout,merge} hook for the gitinfo2 package
#
# Get the first tag found in the history from the current HEAD
FIRSTTAG=$(git describe --tags --always --dirty='-*' 2>/dev/null)
# Get the first tag in history that looks like a Release
RELTAG=$(git describe --tags --long --always --dirty='-*' --match '[0-9]*.*' 2>/dev/null)
# Hoover up the metadata
git --no-pager log -1 --date=short --decorate=short \
--pretty=format:"\usepackage[%
shash={%h},
lhash={%H},
authname={%an},
authemail={%ae},
authsdate={%ad},
authidate={%ai},
authudate={%at},
commname={%cn},
commemail={%ce},
commsdate={%cd},
commidate={%ci},
commudate={%ct},
refnames={%d},
firsttagdescribe={$FIRSTTAG},
reltag={$RELTAG}
]{gitexinfo}" HEAD > .git/gitHeadInfo.gin
client side git hooks don't execute on the server - but why not?
客户端 git 钩子不在服务器上执行 - 但为什么不呢?
Generally, you are pushing to a bare repo (a repo without working tree, where you cannot do any commit directly)通常,您正在推送到一个裸仓库(一个没有工作树的仓库,您不能直接进行任何提交)
So server-side commits are more about enforcing policies than creating new commits.因此, 服务器端提交更多的是关于执行策略而不是创建新的提交。
If you really needed new content to be created on the server side (especially one you have no direct control, like GitLab.com), you would need:如果您确实需要在服务器端创建新内容(尤其是您无法直接控制的内容,例如 GitLab.com),您需要:
Here's a solution that works for me.这是一个对我有用的解决方案。 It does require you to execute two short commands once within any copy of the repo.
它确实需要您在 repo 的任何副本中执行一次两个短命令。
Within any copy of your repo, do the following:在您的存储库的任何副本中,执行以下操作:
$ cp -a .git/hooks .githooks
$ cp -a .git/hooks .githooks
$ git add .githooks
$ git add .githooks
$ git commit -m 'added .githooks directory'
$ git commit -m '添加 .githooks 目录'
Note you only have to do these first two steps once in any of the repos, not in every local copy.请注意,您只需在任何存储库中执行前两个步骤一次,而不是在每个本地副本中。
Within each local copy of a repo you will need to在存储库的每个本地副本中,您需要
$ git config --local core.hooksPath .githooks
$ git config --local core.hooksPath .githooks
$ .githooks/post-commit
$ .githooks/提交后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.