Nothing happens on git pull hook (post-update)

我们两清 提交于 2020-01-06 11:17:07

问题


when I do a git pull on live server I'm logged in as root and so all modified or new files user and group are set to root:root.

I've tried this set up in my post-update hook file:

OWNER="example:example"
REPO_PATH="/home/example/public_html"

cd $REPO_PATH || exit
unset GIT_DIR
FILES="$(git diff-tree -r --name-only --no-commit-id)"
git merge FETCH_HEAD

for file in $FILES
    do 
    chown $OWNER $file
done

exec git update-server-info

When I run a git pull it just doesn't do anything.


回答1:


Running git pull does not invoke the post-update hook: git pull is git fetch followed by either git rebase or git merge, more or less, and rebase effectively ends with a git checkout while merge is, well, merge. (For so-called fast-forward merges, git merge does something much more like git checkout internally, but also updates the current branch name.) Thus, these two hooks are much more appropriate candidates for this kind of work.

Git includes a contrib/hooks/setgitperms.perl example script that's meant to be used in post-checkout and post-merge hooks.

(It's also worth mentioning that running git pull on a live server is not necessarily a good deployment strategy. Git itself is not a deployment system, and neither push-to-deploy nor pull-to-deploy are adequate by themselves for many real-world setups. They can work for limited subsets, but in general, consider building or using a real deployment system.)



来源:https://stackoverflow.com/questions/53777516/nothing-happens-on-git-pull-hook-post-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!