How I set up git.raylu.net

March 29, 2013

Motivation

GitHub doesn't let you host private repositories for free. (Also, their commit list view is silly.) GitLab's setup is ridiculous. Getting hosted on GitLab.com might be an option, but I haven't explored it thoroughly.

It was a dark and stormy night

Actually, I was "studying" for finals when I stumbled across gitolite. Gitolite lets you host multiple git repos for multiple users and gives you finer-grained control than GitHub (per-branch and read-only permissions, in particular). It's even packaged in Debian!

Unfortunately, if you install from the Debian wheezy packages (at the time of writing, wheezy is testing), you're a bit out of luck. The official documentation is wrong, the README is wrong, and this guide specifically for Debian is less wrong, but still wrong.

Setup

Actually, the Debian-specific guide is pretty close. The critical missing step is after installing gitolite but before trying to switch users, you have to create the user first.

sudo adduser --system --home /var/lib/gitolite --shell /bin/bash git

A lot of guides mention creating a gitolite user, but that means your git urls look like gitolite@example.com:repo. Instead, I create a git user. Also, when running gl-setup, it will give you the option to edit the .gitolite.rc file. You should take this opportunity to set

$REPO_UMASK = 0027;

because why not and, later, when you set up a web interface, you'll need it.

gitweb sucks (or how to setup cgit)

cgit is great. It's just a frontend for repositories. No issue tracking, pull requests... no redis dependencies, nothing. Just diffs and downloads.

git clone git://hjemli.net/pub/git/cgit
cd cgit
git submodule init
git submodule update
make

Set up a /etc/cgitrc

project-list=/var/lib/gitolite/projects.list
remove-suffix=1
snapshots=tar.xz

enable-gitweb-owner=1
enable-commit-graph=1
enable-log-filecount=1
enable-log-linecount=1
enable-index-links=1
enable-tree-linenumbers=1
max-stats=quarter
root-title=git.raylu.net
root-desc=repository browser
root-readme=/var/www/git.raylu.net/about.html

scan-path=/var/lib/gitolite/repositories
virtual-root=/
clone-prefix=ssh://git@git.raylu.net http://git.raylu.net

Set up your webserver. In my case, I symlinked

$ ll /var/www/git.raylu.net
total 4.0K
-rw-r--r-- 1 root root 36 Mar 27 22:58 about.html
lrwxrwxrwx 1 root root 25 Mar 27 23:08 cgit.cgi -> /home/raylu/src/cgit/cgit
lrwxrwxrwx 1 root root 29 Mar 27 23:08 cgit.css -> /home/raylu/src/cgit/cgit.css
lrwxrwxrwx 1 root root 29 Mar 27 23:08 cgit.png -> /home/raylu/src/cgit/cgit.png

After enabling the lighttpd cgi module, I added this to my lighttpd.conf

$HTTP["host"] == "git.raylu.net" {
    alias.url = (
        "/cgit.css" => "/var/www/git.raylu.net/cgit.css",
        "/cgit.png" => "/var/www/git.raylu.net/cgit.png",
        "/cgit.cgi" => "/var/www/git.raylu.net/cgit.cgi",
        "/"         => "/var/www/git.raylu.net/cgit.cgi",
    )
    cgi.assign = ( "cgit.cgi" => "" )
    url.rewrite-once = (
        "^/cgit\.(css|png)" => "$0",
        "^/.+" => "/cgit.cgi$0"
    )
}

And you're done. Unless you don't see any commits, in which case you probably want to

sudo chgrp -R www-data /var/lib/gitolite/{repositories,projects.list}
sudo chmod g+r /var/lib/gitolite/repositories
sudo chmod g-r /var/lib/gitolite/repositories/gitolite-admin.git