Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix permissions with git post-merge

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!

like image 880
Michael Mior Avatar asked Jun 09 '11 19:06

Michael Mior


1 Answers

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.

like image 63
Kevin Jalbert Avatar answered Oct 23 '22 04:10

Kevin Jalbert