How to detect commit --amend by pre-commit hook ?

后端 未结 5 1282
陌清茗
陌清茗 2021-02-19 07:09

When I do commit --amend, it is unsafe commit if the commit already has been pushed to remote repository.

I want to detect unsafe commit --amend by pre-commit hook and a

5条回答
  •  醉梦人生
    2021-02-19 07:22

    Following @perror's answer, I came up with the following:

    parent=$(/bin/ps -o ppid -p $PPID | tail -1)
    if [ -n "$parent" ]; then
        amended=$(/bin/ps -o command -p $parent | grep -e '--amend')
        if [ -n "$amended" ]; then
            echo "This is an 'amend'"
        fi  
    fi
    

提交回复
热议问题