Local executing hook after a git push?

前端 未结 5 610
南笙
南笙 2020-11-27 11:07

I\'ve looked at the githooks manpage but unless I\'m missing something I don\'t see an option for local, post-push git hooks. I\'d like to have one that updates the api doc

5条回答
  •  生来不讨喜
    2020-11-27 11:38

    Another solution to this problem is to have a wrapper for git push that executes .git/hooks/pre-push and .git/hooks/post-push scripts before and after the git push call. A possible wrapper could look like this:

    #!/bin/sh
    
    GIT_DIR_="$(git rev-parse --git-dir)"
    BRANCH="$(git rev-parse --symbolic --abbrev-ref $(git symbolic-ref HEAD))"
    
    PRE_PUSH="$GIT_DIR_/hooks/pre-push"
    POST_PUSH="$GIT_DIR_/hooks/post-push"
    
    test -x "$PRE_PUSH" &&
        exec "$PRE_PUSH" "$BRANCH" "$@"
    
    git push "$@"
    
    test $? -eq 0 && test -x "$POST_PUSH" &&
        exec "$POST_PUSH" "$BRANCH" "$@"
    

    Saved as git-push-wh somewhere in your PATH, it can then be called as git push-wh if you want to push with hooks.

提交回复
热议问题