Ok, so the other week I wrote a little bit about migrating my git server from gitosis (which is no longer maintained), over to gitolite.
Along side this, I also run a gitlist server. Gitlist is a web front end for git, similar to gitweb, which provides a slick and modern looking “github” style interface. It is also remarkably easy to set up and configure.
One gotcha I found was that, while unmodified gitosis repositories displayed correctly, as soon as you pushed a change, gitlist presented an error:
Oops! fatal: Failed to resolve HEAD as a valid ref.
After some investigation, it seems the problem stems from a permission issue. By default, gitolite creates new files and repositories with a slightly more restricted set of permissions.
Fixing the problem
Once the problem was identified, the solution is thankfully fairly trivial:
- First, stop gitolite making the situation any worse. Go to the gitolite home directory and edit
.gitolite.rc
, and set
$REPO_UMASK = 0027;
This will cause new files to be created with access to group, as well as user.
- Next, give your web server process access to the gitolite group. Assuming, as with me, the user is
git
, modify/etc/group
and add your webserver user to the git group, e.g.git:x:128:www-data
- Restart apache for your changes to come into effect.
Fixing broken repositories
New repositories and files should now be created using the more permissive access permissions, which gitlist/gitweb will now be able to see. However, you may need to fix the permissions on some existing repositories.
find repository-name.git -type d | xargs -i{} chmod 750 {};
find repository-name.git -type f | xargs -i{} chmod 640 {}
Hope this helps!