Skip to content

Instantly share code, notes, and snippets.

@ottosmops
Forked from YaroslavShapoval/post-merge
Created August 21, 2023 05:33
Show Gist options
  • Select an option

  • Save ottosmops/763922eb500355665f8080e59304f882 to your computer and use it in GitHub Desktop.

Select an option

Save ottosmops/763922eb500355665f8080e59304f882 to your computer and use it in GitHub Desktop.
Post-update git hook to set right owner and permissions for changed files
#!/bin/sh
# default owner user
OWNER="www-data:www-data"
# changed file permission
PERMISSION="664"
# web repository directory
REPO_DIR="/var/www/sitename"
# remote repository
REMOTE_REPO="origin"
# public branch of the remote repository
REMOTE_REPO_BRANCH="master"
cd $REPO_DIR || exit
unset GIT_DIR
files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"
git merge FETCH_HEAD
for file in $files
do
sudo chown $OWNER $file
sudo chmod $PERMISSION $file
done
exec git-update-server-info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment