serve_git.txt

WRITING A GIT SERVER
These are notes on the implementation of git.badboy.institute.
GIT DAEMON
For read-only repository clones, you'll need to set up the git daemon. You could use HTTP instead for r/o, but that's harder. The git daemon should work out of the box, you'll just need to install it on your system and enable the service. Make sure to port forward :9418.
SSH
Make sure you port forward ssh so that you cana make read/write clones. Badboy git handles authentification by just giving each user a corresp- onding unix user, so that reading badboy.institute:~user/repo.git routes to ~user/repo.git on the actual system. This approach is admitt- edly somewhat naive.
GIT HOOKS
If you want the code in each repo to be visible to the end user, the simplest way to access that code from a bare repo is to clone the bare repo as a full repo on each push. You can do this with git hooks. The hooks you're going to want to add are post-receive and post-update.
badboy git's post-receive:
while read oldrev newrev ref; do if [[ $ref = refs/heads/master ]]; then home=`dirname $(pwd)` u=`basename $home` f=~/"`basename $(pwd)`.full" rm -rf $f git clone -l "$(pwd)" $f fi done
badboy git's post-update:
exec git update-server-info git clone -l $f $f.full
When these files are placed in $REPO/hooks/{post-update,post-receive} respectively, they'll clone the bare repos to ${REPO_NAME}.full. You'll need to copy those files into every bare repo.
CREATING BARE REPOSITORIES
On your server % mkdir $REPO.git % cd $REPO % git init --bare
On your workstation % git remote add origin ssh://${ADDR}:${SSH_PORT}/~$USER/$REPO.git
For more information, see barrow's page: https://alphamethyl.barr0w.net/~barrow/doc/man/20210808_git_hosting.html
HTTP
Badboy git's HTTP handles authentification by syncing a database with user metadata to their corresponding unix users and repository paths on the filesystem. This lets the user create repositories from a web inte- rface, but you could also make a functional server where the repos are created with a command line program on the server.

go home