shell

Git shell for sbi.re
Log | Files | Refs | README

commit 5196de69c6da102cda473fd71eb3d5ea1fdca09b
parent ad80a3e4ed7473f3b46e52d6214f356a35ff6cd0
Author: flupe <flupe@sbi.re>
Date:   Fri, 19 Nov 2021 01:45:21 +0100

added post-receive hook

Diffstat:
Mshell.py | 9++++++++-
Atemplate/hooks/post-receive | 42++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/shell.py b/shell.py @@ -10,6 +10,7 @@ from os.path import basename, splitext, isfile, isdir, join import policy USERS = os.path.expanduser('~/users') +TEMPLATE = os.path.expanduser('~/template') def die(msg, status=1): sys.stderr.write(msg) @@ -32,7 +33,13 @@ def do_git_receive_pack(user, cmd, args): if not os.path.isdir(path): if not policy.CREATE & perm: die('error: sorry %s, %s does not exist and you are not allowed to create it' % (user, repo)) - subprocess.run(['git', 'init', '--bare', path], stdout=sys.stderr.buffer) + subprocess.run( + [ 'git', 'init', '--bare', + '--template=%s' % TEMPLATE, + path, + ], + stdout=sys.stderr.buffer + ) sys.stderr.write('info: created new repo %s' % repo) os.execvp('git-receive-pack', ['git-receive-pack', *args[:-1], path]) diff --git a/template/hooks/post-receive b/template/hooks/post-receive @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +import os +import glob +from os import path + +REPOSITORIES = path.expanduser('~/repositories') +HTMLDIR = '/var/lib/www/git' + +CACHEFILE = '.htmlcache' +COMMITS = 100 +BASEURL = 'https://git.sbi.re' + +def git(*args): + return (subprocess + .run(['git', *args], capture_output=True, encoding='utf-8') + .stdout) + +def main(lines): + CURR = os.getcwd() + full_name = path.relpath(CURR, REPOSITORIES) + short_name = path.basename(full_name) + + # TODO: detect forced push and delete cache + # TODO: detect if repo is public/private + + # create output html dir + outdir = path.join(HTMLDIR, full_name) + os.makedirs(outdir, exist_ok=True) + + # change current dir and generate html + os.chdir(outdir) + subprocess.run(['stagit', '-l', str(COMMITS), '-u', BASEURL , CURR]) + + # render index again + files = sorted(glob.glob(path.join(REPOSITORIES, '*'))) + subprocess.run(['stagit-index', *files]) + +if __name__ == '__main__': + main(sys.stdin)