Fix permissions with git post-merge

On one server I'm working on, we need to log in as root (for reasons that I will not log in here). We have a git repository that is used for the web server, but since files are created as root, files modified with git have incorrect permissions.

I created an incredibly simple hook after the merge, which I thought would solve the problem.

#!/bin/bash . git-sh-setup chown -R www-data:www-data $GIT_DIR 

I dumped this in .git/hooks/post-merge with execute permissions, but the file never ran. This is the first time I have tried to adjust the hook, so maybe I am missing something obvious.

One thing I noticed is that most hooks had a .sample file, and post merge .sample n't. (git version 1.7.4)

Thanks in advance!

+6
source share
4 answers

You may already know, but you can check the EOL (CR) characters in your hook after the merge. This may explain why your hook is not executing (as mentioned in this other question git-hook-post-merge-error-cannot-run .

If this is not a solution, you can also look at a different approach to your problem. You can complete the task of making owner changes to your directory when the file in your repository changes on the server. Cron's tasks themselves do not respond to file system changes, but you can take a hit by using something like inotify to respond to changes in the git server repository with any changes.

I hope that these two pieces of information either solve your problem, or at least bring you closer. Good luck.

+2
source

Make sure you add the script to the root group property.

0
source

Perhaps you are looking for post-receive hook if you want the script to execute the remote repository, was clicked.

0
source

See how git achievements works. It would be easier to wrap git in a script and do what you need with any command. Hooks are more for remote repo, not local. Merging is what you do locally, so you won't find much help from hook mechanisms.

Link

http://benjamin-meyer.blogspot.com/2010/03/git-achievements.html

Hope this helps

0
source

Source: https://habr.com/ru/post/890181/


All Articles