From 3796d6219f60d2ed85ecdc2b715c24fb6ae8395f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 12 Oct 2008 17:20:40 +0400 Subject: [PATCH] Allow specifying a template for auto-init. [gitosis] init-template = /srv/git/templates It is useful for enforcing a set of common hooks, e.g. a post-update that calls update-server-info. Signed-off-by: Alexander Gavrilov --- gitosis/serve.py | 9 +++++++++ gitosis/test/test_serve.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/gitosis/serve.py b/gitosis/serve.py index 39904fa..5efb6b5 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -8,6 +8,8 @@ import logging import sys, os, re +from ConfigParser import NoSectionError, NoOptionError + from gitosis import access from gitosis import repository from gitosis import gitweb @@ -143,6 +145,13 @@ def serve( p = os.path.join(p, segment) util.mkdir(p, 0750) + # init using a custom template, if required + try: + template = cfg.get('gitosis', 'init-template') + repository.init(path=fullpath,template=template) + except (NoSectionError, NoOptionError): + pass + repository.init(path=fullpath) gitweb.set_descriptions( config=cfg, diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index f20da14..2336f45 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -1,5 +1,5 @@ from nose.tools import eq_ as eq -from gitosis.test.util import assert_raises +from gitosis.test.util import assert_raises, readFile, check_mode import logging import os @@ -503,6 +503,47 @@ def test_push_inits_sets_htaccess(): path = os.path.join(repositories, 'foo.git', '.htaccess') assert os.path.exists(path) +def test_push_inits_templates(): + tmp = util.maketemp() + templatedir = os.path.join( + os.path.dirname(__file__), + 'mocktemplates', + ) + cfg = RawConfigParser() + cfg.add_section('gitosis') + repositories = os.path.join(tmp, 'repositories') + os.mkdir(repositories) + cfg.set('gitosis', 'repositories', repositories) + cfg.set('gitosis', 'init-template', templatedir) + generated = os.path.join(tmp, 'generated') + os.mkdir(generated) + cfg.set('gitosis', 'generate-files-in', generated) + cfg.add_section('group foo') + cfg.set('group foo', 'members', 'jdoe') + cfg.set('group foo', 'writable', 'foo') + os.umask(0022) + serve.serve( + cfg=cfg, + user='jdoe', + command="git-receive-pack 'foo'", + ) + eq(os.listdir(repositories), ['foo.git']) + path = os.path.join(repositories, 'foo.git') + assert os.path.isfile(os.path.join(path, 'HEAD')) + got = readFile(os.path.join(path, 'no-confusion')) + eq(got, 'i should show up\n') + check_mode( + os.path.join(path, 'hooks', 'post-update'), + 0755, + is_file=True, + ) + got = readFile(os.path.join(path, 'hooks', 'post-update')) + eq(got, '#!/bin/sh\n# i can override standard templates\n') + # standard templates are there, too + assert (os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase')) + or os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase.sample'))) + + def test_absolute(): # as the only convenient way to use non-standard SSH ports with # git is via the ssh://user@host:port/path syntax, and that syntax -- 2.11.4.GIT