get commit message in git hook

前端 未结 4 1057
滥情空心
滥情空心 2020-12-03 06:49

I would like to check commit message before git commit. I use pre-commit hook to do that, but couldn\'t find the way to get commit message in .git/pre-commit script. How cou

4条回答
  •  醉梦人生
    2020-12-03 07:30

    You can do the following in a pre-receive hook (for server side) using Python, and that will display the revision information.

    import sys
    import subprocess
    old, new, branch = sys.stdin.read().split()
    proc = subprocess.Popen(["git", "rev-list", "--oneline","--first-parent" , "%s..%s" %(old, new)], stdout=subprocess.PIPE)
    commitMessage=str(proc.stdout.readlines()[0])  
    

提交回复
热议问题