How can I run a virtualenv python script as a git pre-commit hook

后端 未结 2 814
说谎
说谎 2021-01-11 14:47

This is my pre-commit script:

#!/bin/bash
for f in .git/hooks/pre-commit.d/*; do
    if [ -x \"$f\" ]; then
        if ! \"$f\"; then
            echo \"DID          


        
2条回答
  •  庸人自扰
    2021-01-11 15:16

    You can check in your pre-commit script for the $VIRTUAL_ENV variable and prepend it to $PATH accordingly:

    #!/bin/bash
    
    if [ -n $VIRTUAL_ENV ]; then
        PATH=$VIRTUAL_ENV/bin:$PATH
    fi
    
    for f in .git/hooks/pre-commit.d/*; do
        if [ -x "$f" ]; then
            if ! "$f"; then
                echo "DID NOT COMMIT YOUR CHANGES!";
                exit 1
            fi
        fi
    done
    

提交回复
热议问题