[英]Duplicating git client hooks on the server side
我已經在.git/hooks
中定義了一個提交后.git/hooks
,我也想在服務器端(在我的例子中是Gitlab.com )執行它。
背景:我在 LaTeX 項目中使用 gitinfo2 和 post-commit 鈎子來引用有關 pdf 中最新 git 標簽的信息。 這在我的計算機上運行良好,但是當我將 repo 推送到 Gitlab 時失敗了。
它不會導致錯誤,但會給出以下警告,這基本上意味着 git hook 從未執行過。
Package gitinfo2 Warning: I can't find the file '.git/gitHeadInfo.gin'.
(gitinfo2) All git metadata has been set to '(None)'.
從我目前在線閱讀的內容來看,客戶端 git 鈎子不會在服務器上執行 - 但為什么不呢? 在這種情況下,我希望鈎子在客戶端和服務器上都執行。
所以,基本上,我希望事件的順序是這樣的:
.git
文件夾中創建一個名為gitHeadInfo.gin
的文件。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
客戶端 git 鈎子不在服務器上執行 - 但為什么不呢?
通常,您正在推送到一個裸倉庫(一個沒有工作樹的倉庫,您不能直接進行任何提交)
因此, 服務器端提交更多的是關於執行策略而不是創建新的提交。
如果您確實需要在服務器端創建新內容(尤其是您無法直接控制的內容,例如 GitLab.com),您需要:
這是一個對我有用的解決方案。 它確實需要您在 repo 的任何副本中執行一次兩個短命令。
在您的存儲庫的任何副本中,執行以下操作:
$ cp -a .git/hooks .githooks
$ git add .githooks
$ git commit -m '添加 .githooks 目錄'
請注意,您只需在任何存儲庫中執行前兩個步驟一次,而不是在每個本地副本中。
在存儲庫的每個本地副本中,您需要
$ git config --local core.hooksPath .githooks
$ .githooks/提交后
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.