除非在提交消息中找到“正在进行中”,否则中止提交到代码中

时间:2016-05-12 09:03:14

标签: git githooks pre-commit-hook

我需要获取git来中止包含todo的提交,除非在提交消息中指定了“正在进行中”文本。

是否有办法将提交消息访问到预提交钩子中,因为我总是通过 Sub test() Dim fso As FileSystemObject Dim oSourceFolder As Scripting.Folder Dim oSubFolder As Scripting.Folder Dim oFile As Scripting.File Dim oFolder As Scripting.Folder Dim strFolderName As String Dim i As Long Set fso = CreateObject("Scripting.FileSystemObject") Cells(1, 1).Value = "fld" strFolderName= "C:\Users\fld" i = 2 Range("A2").Select ActiveCell = Range("A2") Set oSourceFolder = fso.GetFolder(strFolderName) For Each oFolder In oSourceFolder.SubFolders For Each oFile In oFolder.Files Cells(i, 1).Value = Left(oFile.ParentFolder) i = i + 1 Next oFile Next oFolder 选项提供它,这意味着它应该可用于所有可用的git钩子?

如果没有,我该怎么办?

1 个答案:

答案 0 :(得分:1)

作为1615903 noted in a comment,您需要使用the commit-msg hook

  

我需要获取git来中止包含todo的提交,除非在提交消息中#34;正在进行的工作"文本已指定。

您尚未定义"包含todo"在这里,但是不管怎样,让我们​​来点吧:

#! /bin/sh
# commit-msg hook: if "work in progress" is included, allow anything,
# otherwise require that no line adds the word "todo" anywhere.
#
# Note that this will forbid a commit that includes a text file
# or comment saying that you should not include the word "todo"
# in your commits!
grep "work in progress" "$1" >/dev/null && exit 0 # allow
git diff --cached | grep '^+.*todo' >/dev/null && {
    echo "commit aborted: found \"todo\" without \"work in progress\"" 1>&2
    exit 1 # forbid
}
exit 0 # test passed, allow

注意:这是完全未经测试的。