Git 后接钩
我需要关于编写git post接收挂钩的帮助 我需要钩子来调用外部.exe文件并传入参数 到目前为止,这是我的钩子:Git 后接钩,git,sh,githooks,Git,Sh,Githooks,我需要关于编写git post接收挂钩的帮助 我需要钩子来调用外部.exe文件并传入参数 到目前为止,这是我的钩子: #!/bin/sh call_external() { # --- Arguments oldrev=$(git rev-parse $1) newrev=$(git rev-parse $2) refname="$3" DIR="$(cd "$(dirname "$0&quo
#!/bin/sh
call_external()
{
# --- Arguments
oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)
refname="$3"
DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/post-receive.d/External.exe
}
# --- Main loop
while read oldrev newrev refname
do
call_external $oldrev $newrev $refname
done
它工作得很好,只是我需要将一些参数传递给那个exe,我不知道如何从Git获取它们
感谢“博士”,更新如下:
每次提交推送时,我都需要这些参数
Commit hash
- 作者/电子邮件
- 提交散列
- 提交描述
- 分支机构名称
#!/bin/sh
call_external()
{
# --- Arguments
oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)
refname="$3"
if [ $(git rev-parse --is-bare-repository) = true ]
then
REPOSITORY_BASENAME=$(basename "$PWD")
else
REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
fi
DIR="$(cd "$(dirname "$0")" && pwd)"
BRANCH=$refname
git rev-list "$oldrev..$newrev"|
while read hash
do
COMMIT_HASH=$hash
AUTHOR_NAME=$(git show --format="%an" -s)
AUTHOR_EMAIL=$(git show --format="%ae" -s)
COMMIT_MESSAGE=$(git show --format="%B" -s)
$($DIR/post-receive.d/External.exe "$BRANCH" "$AUTHOR_NAME" "$AUTHOR_EMAIL" "$COMMIT_MESSAGE" "$COMMIT_HASH" "$REPOSITORY_BASENAME")
done
}
# --- Main loop
while read oldrev newrev refname
do
call_external $oldrev $newrev $refname
done
每次提交推送时,我都需要这些参数
Commit hash
运行以下循环:
git rev-list oldrev..newrev | while read hash; do echo $hash; done
在循环中,$hash
是一次提交的哈希
这是git show--format=“%an”-s
和git show--format=“%ae”-s
<代码>%an表示“作者姓名”,%ae
-“作者电子邮件”。请参见位于的占位符列表
git show--format=“%B”-s
。这就是“提交消息的全部内容”。可以分为%s
和%b
你不需要它在一个循环中,你总是拥有它。更新引用时调用post接收钩子,引用是分支<脚本中的代码>引用名称
让我们将所有这些合并到一个循环中:
git rev-list oldrev..newrev |
while read hash; do
echo Commit hash: $hash
echo Author name: git show --format="%an" -s
echo Author email: git show --format="%ae" -s
echo Commit message: git show --format="%B" -s
done
“推送提交人的电子邮件”什么是提交?更新引用时调用钩子;在
oldrev
和newrev
之间可能有一百次提交。“提交号码”号码是多少?提交散列?“说明/评论”再说一遍,这是什么?提交消息?“Repository name”您无法从git获取此名称-它不存储存储库名称。您可以从操作系统获取顶级目录的名称,仅此而已。谢谢,我用完成的脚本更新了我的问题。
Branch name
git rev-list oldrev..newrev |
while read hash; do
echo Commit hash: $hash
echo Author name: git show --format="%an" -s
echo Author email: git show --format="%ae" -s
echo Commit message: git show --format="%B" -s
done