我在.git/hooks
中定义了一个提交后钩子,我也想在服务器端执行(在我的情况下,Gitlab.com)。
背景:我正在使用gitinfo2以及LaTeX项目中的提交后钩子来引用pdf中最新git标签的信息。这在我的计算机上可以正常工作,但是在将存储库推送到Gitlab时失败。
它不会引起错误,但是会给出以下警告,这基本上意味着git钩子从未执行。
Package gitinfo2 Warning: I can't find the file '.git/gitHeadInfo.gin'.
(gitinfo2) All git metadata has been set to '(None)'.
从到目前为止我在网上阅读的内容来看,客户端git钩子不在服务器上执行-但是为什么不呢?在这种情况下,我希望挂钩在客户端和服务器上都执行。
因此,基本上,我希望事件的顺序如下:
gitHeadInfo.gin
文件夹中创建一个名为.git
的文件。gitinfo
软件包帮助从gitHeadInfo.gin
中提取git版本信息。除了第3步,我已经正常运行。因此,当前的解决方法是在计算机上也生成pdf并提交,而不是依靠Gitlab CI。
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
答案 0 :(得分:7)
客户端git钩子不在服务器上执行-但是为什么不呢?
通常,您将推送至裸仓库(没有工作树的仓库,您不能直接进行任何提交)
因此,server-side commits与其说是执行新提交,不如说是执行政策。
如果您确实需要在服务器端创建新内容(特别是您没有直接控制权的内容,例如GitLab.com),则需要:
答案 1 :(得分:4)
这是对我有用的解决方案。它确实需要您在存储库的任何副本中一次执行两个短命令。
在您的任何回购副本中,执行以下操作:
$ cp -a .git / hooks .githooks
$ git add .githooks
$ git commit -m'添加了.githooks目录'
请注意,您只需在任何存储库中执行一次前两个步骤,而不必在每个本地副本中执行一次。
在存储库的每个本地副本中,您将需要
$ git config --local core.hooksPath .githooks
$ .githooks / post-commit