【问题标题】:Having trouble accessing the arguments to the git pre-receive hook无法访问 git pre-receive 挂钩的参数
【发布时间】:2022-01-02 22:13:37
【问题描述】:

我正在运行 vanilla git(git 版本 2.23.3)作为 AWS 实例上的裸存储库的原始主机。

我已经创建了一个文件 repo_dir/hooks/pre-receive,内容如下:

#!/bin/bash -p

echo $1 > pre-receive-old-hash.txt
echo $2 > pre-receive-new-hash.txt
echo $3 > pre-receive-ref.txt

exit 1

我从遥控器进行测试推送。当推送被拒绝时,我可以确认该钩子已运行。

但是,虽然 pre-receive-x.txt 文件存在,但它们是空的。我做错了什么?

【问题讨论】:

  • From githooks manual: "pre-receive: ...这个钩子为接收操作执行一次。它不带参数,... 所以不要除了要定义的${1..3}。改为读取标准输入,挂钩从中接收额外信息。

标签: git githooks


【解决方案1】:

https://git-scm.com/docs/githooks#pre-receive

它不需要参数,但是对于每个要更新的引用,它在标准输入上接收一行格式:

<old-value> SP <new-value> SP <ref-name> LF

(强调我的——phd

让你的脚本变成这样:

#!/bin/bash -p

while read old new refname; do
    echo $old >> pre-receive-old-hash.txt
    echo $new >> pre-receive-new-hash.txt
    echo $refname >> pre-receive-ref.txt
done

exit 1

【讨论】:

    猜你喜欢
    • 2012-05-18
    • 2015-04-09
    • 1970-01-01
    • 2017-12-30
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    相关资源
    最近更新 更多