Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong file permission when using git pull in a hook

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

like image 278
Simon Avatar asked Mar 26 '11 14:03

Simon


People also ask

How do I fix permissions in git?

Set the Appropriate Permissions on Objects Directory Make sure all your users who need access to git are part of the git group. Change the “git” in the above chgrp command to whatever group where all your developers belong to. The “s” option in the “g+rws” is to set the setuid bit on the objects folder.

Does git store file ownership?

According to kernel.org git does not store all the permissions possible for files. Git is a content tracker, where content is de facto defined as "whatever is relevant to the state of a typical sourcecode tree". Basically, this is just files' data and "executable" attribute.


1 Answers

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.

like image 172
Lars Noschinski Avatar answered Sep 25 '22 23:09

Lars Noschinski