How to get a list of incoming commits on git push for a new branch in a hook

后端 未结 3 1474
北恋
北恋 2021-02-03 13:12

I\'m writing a pre-receive hook to do some validation before accepting commits on the push. It works fine with existing branches since I use following git command to get a list

3条回答
  •  伪装坚强ぢ
    2021-02-03 13:41

    The following helped in my case. I personally think it's very simple.

    OLD_REV=$2
    NEW_REV=$3
    
    if [ $OLD_REV == "0000000000000000000000000000000000000000" ]; then
        OLD_REV=$(git merge-base master $NEW_REV)
    fi;
    
    git diff --name-only $OLD_REV $NEW_REV
    

提交回复
热议问题