On one server I work on, we must log in as root (for reasons I won't get into here). We have a git repository set up which is used for the web server, but since files are created as root, files modified by git have the wrong permissions.
I created an incredibly simple post-merge hook which I thought would solve the problem.
#!/bin/bash
. git-sh-setup
chown -R www-data:www-data $GIT_DIR
I dropped this into .git/hooks/post-merge
with execute permissions, but the file never seems to run. This is the first time I've tried to set up a hook, so maybe I'm missing something obvious.
One thing I did notice is that most hooks had a .sample
file, while post-merge did not. (git version 1.7.4)
Thanks in advance!
You might have already known but you might want to check for the EOL characters (CRs) in your post-merge hook. This might explain why your hook doesn't execute (as mentioned in this other question git-hook-post-merge-error-cannot-run.
If this isn't the solution you could also possibly look at another approach for your problem. You could make a task to perform the owner changes to your directory when a file in your repository change on the server. Cron tasks on their own do not react based on filesystem changes, but you could take a stab at using something like inotify to react to changes in the server's git repository on any changes.
I hope that these two pieces of information either solve your problem or at least puts you closer. Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With