deployment - how to control ownership of files auto-pushed to a git target repo by commit hooks? -


i created bare repo @

/srv/repos/test 

i set ownership wwwrun:www suid+guid bits set

chown -r wwwrun:www /srv/repos/hub chmod ug+s          /srv/repos/hub ls -ald /srv/repos/test     drwsrws---+ 10 wwwrun www 4.0k mar  7 21:28 /srv/repos/hub/ 

i cloned repo webroot, , changed ownership,

git clone /srv/repos/hub /srv/www/sitea chown -r wwwrun:www      /srv/www/sitea 

for convenience, define remote

cd /srv/www/sitea git remote add hub /srv/repos/hub 

then create post-commit , post-update hooks keep things in sync,

vi /srv/www/sitea/.git/hooks/post-commit     #!/bin/sh     git push hub  vi /srv/repos/hub/hooks/post-update     #!/bin/sh     cd /srv/www/sitea || exit     unset git_dir     git pull hub master     exec git-update-server-info 

as normal user, checkout hub

whoami     locuse cd ~ git clone /srv/repos/hub work ls -ald work     drwxr-xr-x 10 locuse users 4.0k mar  7 21:44 work/ 

make change, commit , push,

cd work touch touch_file ls -al touch_file     -rw-r--r-- 1 locuse users 0 mar  7 21:44 touch_file git add -a git commit -m "add test" git push 

then checking see hook fired , update pushed webroot,

ls -al /srv/www/sitea/touch_file     -rw-rw----+ 1 locuse www 0 mar  7 21:45 /srv/www/sitea/touch_file 

the file's there -- expected.

but, it's not user-ownership want, namely it's user='locuse' not user='wwwrun'.

in specific use-case, what's right way make sure i, instead, automatically end-up with,

ls -al /srv/www/sitea/touch_file     -rw-rw----+ 1 wwwrun www 0 mar  7 21:45 /srv/www/sitea/touch_file 

? i.e., gets promoted /srv/www/sitea only wwwrun:www .

something in hook, i'm guessing?

i know add

chown -r wwwrun:www /srv/www/sitea 

to post-commit hook, works fine small tree, bogs @ each commit/update down if it's large (which be).

perhaps if efficiently chown current commit ... ?

this works,

vi /srv/repos/hub/hooks/post-update     #!/bin/sh     cd /srv/www/sitea || exit     unset git_dir -   git pull hub master +   git fetch hub master +   files=`git diff ..fetch_head --name-only --diff-filter=acmrtuxb` +   git merge fetch_head +   file in $files +   +       sudo chown wwwrun:www $file +   done     exec git-update-server-info 

chown execs on files identified being in commit set -- small & fast.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -