从 Git 预接收挂钩获取脚本
Sourcing a script from a Git pre-receive hook
我正在服务器中测试 git 预接收挂钩。这是 hooks/pre-receive
:
的内容
#!/bin/bash
echo "Hi $USER"
source pre-receive-hooks/bye
hooks/pre-receive-hooks/bye
的内容是:
#!/bin/bash
echo "Bye $USER"
hooks/pre-receive
和 hooks/pre-receive-hooks/bye
文件都是可执行的,具有相同的权限,相同的所有者和组。
当我从客户端推送到服务器时,我收到消息:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 287 bytes | 287.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Hi sergioro
remote: hooks/pre-receive: line 10: pre-receive-hooks/bye: No such file or directory
To drop:/git/hooks_practice.git
3fbfa15..c15d08d master -> master
第一个 echo
正在运行,但随后 source
命令失败。为什么 source
失败了?或者更一般地说,如何从 Git 挂钩中获取脚本?
我也尝试了以下命令,但所有 return 当我按下时都出现相同的错误:
source ./pre-receive-hooks/bye # relative path
. pre-receive-hooks/bye # source using the dot command
./pre-receive-hooks/bye # run script directly
将 source pre-receive-hooks/bye
更改为 source hooks/pre-receive-hooks/bye
解决了问题。显然 Git 钩子 $PWD
等于存储库的根目录,而不是钩子目录。
我正在服务器中测试 git 预接收挂钩。这是 hooks/pre-receive
:
#!/bin/bash
echo "Hi $USER"
source pre-receive-hooks/bye
hooks/pre-receive-hooks/bye
的内容是:
#!/bin/bash
echo "Bye $USER"
hooks/pre-receive
和 hooks/pre-receive-hooks/bye
文件都是可执行的,具有相同的权限,相同的所有者和组。
当我从客户端推送到服务器时,我收到消息:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 287 bytes | 287.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Hi sergioro
remote: hooks/pre-receive: line 10: pre-receive-hooks/bye: No such file or directory
To drop:/git/hooks_practice.git
3fbfa15..c15d08d master -> master
第一个 echo
正在运行,但随后 source
命令失败。为什么 source
失败了?或者更一般地说,如何从 Git 挂钩中获取脚本?
我也尝试了以下命令,但所有 return 当我按下时都出现相同的错误:
source ./pre-receive-hooks/bye # relative path
. pre-receive-hooks/bye # source using the dot command
./pre-receive-hooks/bye # run script directly
将 source pre-receive-hooks/bye
更改为 source hooks/pre-receive-hooks/bye
解决了问题。显然 Git 钩子 $PWD
等于存储库的根目录,而不是钩子目录。