簡體   English   中英

hooks / pre-receive:expr:not found

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM