0

我正在使用下面提到的代码来使用正则表达式验证分支名称,但在无效情况下它工作正常,但在有效情况下它也给出相同的消息并且它没有按预期创建分支名称。

LC_COLLATE='C'

local_branch="$(git rev-parse --abbrev-ref HEAD)"

valid_branch_regex="^(feature|merge|project|release|revert|scratch|story|track)\/[-a-z0-9_/]+$"

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex."


if  [[ ! $local_branch =~ $valid_branch_regex ]]; then
    
echo "$message"
    
exit 1

fi

exit 0

结果:-

无法创建分支。预接收挂钩失败。

scripts/git-branch-name-test.sh: failed with exit status 1 您的分支名称有问题。此项目中的分支名称必须遵守此合同:^(feature|merge|project|release|revert|scratch|story|track)/[-a-z0-9_/]+$。

谁能帮我解决这个问题?我错过了什么吗?

4

0 回答 0