Sackville-West Clan Wiki/ tech/ Serving up git

I had horrible fits getting git served up the way I wanted. My goals were simple:

So, why not just use github or some other service? Because I like running my own servers. It's just fun!

Anyway, this gave me such fits, that I need to make note of what's going on here, and I might as well share...

Apache config:

<VirtualHost 192.168.2.3:80>
        ServerName git.swclan.homelinux.org
        DocumentRoot /var/cache/git

        CustomLog /var/log/apache2/access.log combined

        Alias /gitweb /usr/lib/cgi-bin/gitweb.cgi
        Alias /gitweb_styles /usr/share/gitweb

        Options +ExecCGI
        AddHandler cgi-script cgi

        RewriteEngine on
        RewriteRule ^/priv/.*$ %{REQUEST_URI} [L,PT]
        RewriteRule ^/(.*\.git/(?!/?(info|objects|refs)).*)?$ /gitweb%{REQUEST_URI}  [L,PT]

        SetEnv      GITWEB_CONFIG   /etc/gitweb.conf

        Alias /priv /var/cache/git
        <Location /priv>
                DAV on
                AuthType Basic
                AuthName "Git"
                AuthUserFile /etc/apache2/passwd.git
                Require valid-user
        </Location>

</VirtualHost>

The really crucial bit is the rewriting stuff and the alias for /priv. I want requests that come in without /priv in the url to get rewritten to gitweb if appropriate. The second RewriteRule comes from the tips on this gitweb README. That all works wonderfully allowing gitweb to serve up alongside git over http:// for cloning. Great.

The first RewriteRule line matches any /priv/ url and leaves it unchanged, but the [L,PT] directive causes rewriting to stop at that point, so the gitweb rewrite rule gets skipped over. Then the Alias directive points it to the right directory and the Location stanza allows webDAV for just those requests only.

Ba-da-bing, all my goals met.

So, why not ssh? I don't have direct ssh access to the machine -- there's a hop in the middle. I could rework all my ssh stuff, but I really like the way it is... So there's the solution.