【问题标题】:git update hook not receiving any argumentsgit update 钩子没有收到任何参数
【发布时间】:2018-11-08 13:04:21
【问题描述】:

我在网上读到 git hook 接受 3 个参数:

  1. 正在更新的 ref 的名称,

  2. 存储在 ref 中的旧对象名称,

  3. 以及要存储在 ref 中的新对象名称。

我正在尝试访问这些参数,但它是空的。这里有什么问题?

#!/bin/bash


echo $@
refname="$1"
oldrev="$2"
newrev="$3"

基于 cmets,我尝试添加一个 echo 语句 echo "In update hook: Args:$@",这是我看到的输出:

$git push
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 563 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 1 (delta 0)
remote: In update hook: Args:
remote:
remote:

【问题讨论】:

  • Hooks 必须是可执行的,你确定chmod +x $yourscriptfile 了吗?另外,请确保从您尝试执行的挂钩文件中删除 .sample 命名。
  • 另外,请记住一些钩子不会通过命令行接收参数。参见例如。 stackoverflow.com/questions/3762084/…
  • @BjoernRennhak OP 谈到了更新挂钩,所以$yourscriptfile 实际上是.git/hooks/update。 :-) Docs say 它确实在命令行接收 3 个参数。
  • 您是否将脚本放入服务器存储库的git/hooks/update 中?是否可执行?添加回显以验证它是否真的在运行,例如 echo "In update hook. Args: $@"
  • 我确实添加了一个 echo 语句,并看到钩子被触发但参数为空

标签: git hook githooks


【解决方案1】:

感谢Bjoern 提供参考链接。 根据您提供的链接,我可以检索参数:

来源:git: empty arguments in post-receive hook 发布者estani

read oldrev newrev refname
echo "Old revision: $oldrev"
echo "New revision: $newrev"
echo "Reference name: $refname"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 2017-11-03
    • 1970-01-01
    • 2012-01-02
    • 2011-04-15
    • 2016-10-18
    • 2019-10-09
    相关资源
    最近更新 更多