Created
September 22, 2015 08:56
-
-
Save YaroslavShapoval/cbab1fe98adb14ddc2cf to your computer and use it in GitHub Desktop.
Post-update git hook to set right owner and permissions for changed files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
@fishtankmike
The format of the command above is
First of all, let's take a look at
diff-tree
, what does it use for? Actuallydiff-tree
shows the differences from<commit_ID_start>
to<commit_ID_end>
fromreflog
, in this case,HEAD@{1}
is the<commit_ID_start>
andHEAD
is the<commit_ID_end>
.Now we can change the command as below
Now, run
git reflog
, you should know whatHEAD@{1}
means, actually it stands for the last reflog, whileHEAD@{0}
stands for the current reflog(which isHEAD
)So,
git diff-tree HEAD@{1} HEAD
is use to show the difference from the last commitHEAD@{1}
and the currentHEAD@{0}
(HEAD
) from thereflog
.As to
--name-only
and--no-commit-id
, they are the options ofdiff-tree
, see the command and it's output belowwell, if
--name-only
can get the name, what does--no-commit-id
use for? see the screenshot below(screenshot fromgit diff-tree --help
)As to
-r
, I think you already know, it refers torecursively
.