Home » Questions » Computers [ Ask a new question ]

Apache serve files from git repo branches

Apache serve files from git repo branches

Is there any way to serve files from branches in a git repo without checking them out into different directories?

Asked by: Guest | Views: 193
Total answers/comments: 2
Guest [Entry]

"The simplest approach would be checking out each branch and creating clones for each branch in subdirectories. It's very easy to do that with a script runned by cron (or in a post-commit hook) like:

#!/bin/sh
ROOT=/srv/repos/control
cd ${ROOT} # it's an internal repo
git fetch
for ref in .git/refs/remotes/origin/*; do
BRANCH=`basename ${ref}`
if ! [ -d ../${BRANCH} ]; then
git clone --local ${ROOT} ../${BRANCH}
cd ../${BRANCH}
git branch --track ${BRANCH} remotes/origin/${BRANCH}
git checkout ${BRANCH}
else
cd ../${BRANCH}
git pull
fi
done

After it's work you will get a bunch of directories with branches in /srv/repos.

git clone --local is very fast and optimal even on huge repositories like Linux kernel because it does not create all the objects in repository but instead creates hardlinks to them, so you won't waste any space on repository copies. You will, through, waste space on checked-out copies, but a) they're probably not very big and b) this will make web-based access much easier and faster."
Guest [Entry]

Also have a look at Divergence, a rack application that maps git branches to subdomains. I haven't used it my self yet, but it seems to fit your needs quite well.