Wrong file permission when using git pull in a hoo

2019-04-08 19:25发布

I have created the following git hook to update my web application when new changes are pushed to the repository

#!/bin/sh
#Update the server version to HEAD

echo "Updating webapp..."
unset $(git rev-parse --local-env-vars)
(cd /var/www/webapp && git pull -q)

However, if I add new files they get the wrong permissions. They are only readable by the owner and not by the group or by other users. But I need them to be readable by everyone. Locally they have the right permission bits. And even when I run the hook manually from the shell, it works correctly. It only doesn't work when the script is called as a hook.

Any ideas how to fix that?

PS: I am using git 1.7

1条回答
聊天终结者
2楼-- · 2019-04-08 19:40

Git does not store permissions, apart from the executable bit. So, on checkout, files are created with the default permissions, which depend on your umask.

I guess, when you are calling the hook manually, you have a more liberal umask set. You can override the umask with the umask shell command. For your purposes, 0022 is probably fine.

查看更多
登录 后发表回答