Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What is the http.conf in order to automatically serve all my git repositories?

For example, if I have a directory structure as follows (a number of project inside a central directory named git):

/../htdocs/git/project1
/../htdocs/git/project2
/../htdocs/git/project3

What do I have to write in order to avoid repeating the same for each project:

<Location /git/project1>
   DAV on
   AuthType Basic
   AuthName "Git"
   AuthUserFile /../htdocs/git/project1/passwd.git
   Require valid-user
</Location>

Bonus question:

Is there a way to have the repos somewhere outside apache's htdocs and redirect the requests there? (like using DocumentRoot)

Notes:

All repos are --bare because they are the central repos (which Trac uses)

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Use mod_macro:

<Macro Project $repos>
<Location /git/$repos>
   DAV on
   AuthType Basic
   AuthName "Git for $repos"
   AuthUserFile /../htdocs/git/$repos/passwd.git
   Require valid-user
</Location>
</Macro>

Then you just add a single line for each repository

Use Project repos1
Use Project repos2

This isn't automatic unfortunately, i.e. it doesn't pick up all repositories in a directory, but you can run a cron job to create the config for you:

echo "# Git repository definitions" > /path/to/httpd_projectdef.conf
for i in /path/to/git/*; do echo "Use Project `basename $i`" >> /path/to/httpd_projectdef.conf; done

The project macro can also do the trac http config too if you wish.

share|improve this answer
    
I have used Mod_Rewrite in the past for my wordpress configuration. Isn't there a way to use it for this situation as well? –  pek Jun 6 '09 at 9:47
    
When you generate the lines using a cron script you don't even need to use macro. –  che Jun 6 '09 at 18:31
    
@pek - I don't think so. The problem is that mod_rewrite doesn't provide any options for setting the password file. –  Mark Jun 6 '09 at 19:44

If all your repositories can use the same AuthUserFile, then will do, but I don't think that's what you're asking. You'll probably have to generate multiple Location sections externally, say with some perl code, and get apache to re-read the config files.

Have you considered using gitosis or git-daemon?

For your bonus question, something like:

alias /git /path/to/repository/root

<Directory "/path/to/repository/root">
   ...
</Directory>
share|improve this answer

If at all possible, I would suggest using SSH for sharing your repositories - it will offer better security, and generally work better as HTTP is a "dumb" protocol in Git terms. This also means you can use the standard file system permissions for controlling access, and you can have hook scripts run etc. HTTP is the lowest common denominator protocol for Git, and I think you would be better off using something else.

If you are stuck using HTTP for some reason, then pgs' answer is the way to go.

share|improve this answer
    
I have no problem using SSH. The reason I don't is because of how accounts are created. As far I know, to access a repository through SSH you must have an account to the server. This account, if I'm not mistaking, is a user in the linux box. I am planing on hosting multiple Git repositories each with their respective users, so I'm using Apache + WebDAV for this. Unless I can use WebDAV + SSH, I think the HTTP setup is OK. Please correct me if I'm wrong. –  pek Jun 6 '09 at 10:01
    
HTTPS adds the same security as SSH, but involves purchasing a (cheap) certificate –  djechelon Jul 11 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.