Why doesn't setting GIT_WORK_TREE work in a post-commit hook?

前端 未结 1 1147
一向
一向 2020-12-31 20:18

I\'m trying to use the following post-commit hook to deploy to a particular directory after each successful commit:

#!/bin/sh
export GIT_WORK_TR         


        
1条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 21:11

    The problem here is that in post-commit hooks (and also pre-commit, prepare-commit-msg and commit-msgt) the GIT_INDEX_FILE environment variable is set to .git/index. (This isn't documented in the githooks documentation, but I've posted elsewhere about the settings of environment variables and the current directory in git hooks.)

    The effect of the GIT_INDEX_FILE environment variable is described in the ENVIRONMENT VARIABLES section of the git man page as:

    GIT_INDEX_FILE

    This environment [variable] allows the specification of an alternate index file. If not specified, the default of $GIT_DIR/index is used.

    ... and for some reason, in this situation, GIT_INDEX_FILE is being used relative to GIT_WORK_TREE.

    To make the hook work as you would expect, you just need to unset GIT_INDEX_FILE, so your hook would look like:

     #!/bin/sh
     unset GIT_INDEX_FILE
     export GIT_WORK_TREE=/var/www/example/
     export GIT_DIR=/home/mark/test/.git/
     git checkout -f
    

    0 讨论(0)
提交回复
热议问题