Black
Black

Reputation: 20252

Change user and group of all files in project after git pull

The user and group are always changed to root:root if I execute git pull or git checkout

So I created the file .git/hooks/post-merge with the following content:

#!/bin/sh

chown -R mycompany:www /srv/www/vhosts/mycompany

exec git-update-server-info

The file has execute permission

But it does not work, nothing changes after git pull was called.

Upvotes: 1

Views: 677

Answers (1)

VonC
VonC

Reputation: 1324347

First thing to check: is your hook executable?
As in this example:

Run chmod +x post-merge to make it executable then put it into .git/hooks/.

Then add at least an echo in it, to check if it is executed or not.

Note that the hook will only run after a successful merge, meaning if the pull result in a fast-forward merge (HEAD moves, no actual merge needed) the hook would not run.

An alternative would be to try and use setuid/setgid to force to process (Git, as root) to run as the right user (pre-requisite: chown to set the right user/group for those files)

Upvotes: 1

Related Questions