[英]hooks/pre-receive: expr: not found
我在我的服务器上托管git并拥有运行命令的webhook
branch=$(expr "$refname" : "refs/heads/\(.*\)")
这与SSH git推送完美配合,但在尝试使用HTTPS协议时,我收到错误
hooks/pre-receive: expr: not found
我想这是因为使用https时脚本作为www-data运行。
任何想法如何解决这个问题?
如果这是同一台服务器,则应检查从HTTP服务器调用此挂钩时是否正确设置了PATH
环境变量; 它可能会丢失/bin
或/usr/bin
(无论哪个存储你的expr
命令)。
也就是说,这里根本不需要expr
。 假设$refname
中的值以refs/heads
开头:
# Delete the leading refs/heads/ from refname to get branch
branch=${refname#refs/heads/}
除此以外:
# Delete everything up to and including the first instance of refs/heads/
branch=${refname#*refs/heads/}
如果你想检查refname
是否包含refs/heads/
,这在bash中最容易完成(你的脚本以#!/bin/bash
开头):
if [[ $refname = *refs/heads/ ]]; then
branch=${refname#*/refs/heads/}
else
# refname does not match the pattern
branch=
fi
如果你实际上使用bash,你实际上可以使用更相似的代码:
refname_re='refs/heads/(.*)'
if [[ $refname =~ $refname_re ]]; then
branch=${BASH_REMATCH[1]}
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.