简体   繁体   English

如何修复我的 git 环境中的 pre-commit-msg?

[英]How to fix the pre-commit-msg in my git environment?

Has someone have experienced a weird behaviour of .git/hooks/pre-commit-msg?有人经历过 .git/hooks/pre-commit-msg 的奇怪行为吗? The file has proper permission in being executed.该文件具有适当的执行权限。 And actually it is executed.实际上它被执行了。 The issue is that the commits, any commits with correct or uncorrect messages, make the execution goes into the error.问题是提交,任何带有正确或不正确消息的提交,都会使执行进入错误状态。 Always.总是。

The correct message should be something like these examples:正确的消息应该类似于以下示例:

  • "ABC-123/ticket-task blah blha" “ABC-123/票任务等等”
  • "ABC-234/ticket-task fixed some things" “ABC-234/ticket-task 修复了一些东西”
  • "ABC-123/ticket-task added some" “ABC-123/ticket-task 添加了一些”

where the first word after [test], or [fix], or [feat] is chosen between a set (like Added, Fixed, Upgraded..)其中 [test]、[fix] 或 [feat] 之后的第一个词是在一组之间选择的(如添加、固定、升级......)

Working on OSX, with git, with zsh shell.使用 git 和 zsh shell 在 OSX 上工作。

#!/bin/bash
#

commit_message=$(cat .git/COMMIT_EDITMSG)
commit_error="Error in the commit message. Prefix with 
JIRA ticket. For example UXD-1234/git-hook"


if [[ ! $commit_message =~ /([A-Z]+[-][\d]+\/\S+)/  ]]; then
  echo >&2 $commit_error
  exit 1
fi

Is there an error in this code?这段代码有错误吗?

Thanks in advance提前致谢

So here is the correct answer所以这是正确答案

^[A-Z]+-[0-9]+/[a-zA-Z]

Thanks to @jonrsharpe感谢@jonrsharpe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM