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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…