From dedb3dc63f413ed6eeba8082b7e93ad136b16d0d Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Wed, 16 Sep 2009 22:32:54 -0700 Subject: [PATCH] Let even readonly operations init a repo if needed. Git >=1.6.2 support cloning empty repositories; this is a good way to bootstrap development on a new repository. --- gitosis/serve.py | 3 +-- gitosis/test/test_serve.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gitosis/serve.py b/gitosis/serve.py index 867249e..d83b1d8 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -130,8 +130,7 @@ def serve( 'git extension should have been stripped: %r' % relpath repopath = '%s.git' % relpath fullpath = os.path.join(topdir, repopath) - if (not os.path.exists(fullpath) - and verb in COMMANDS_WRITE): + if not os.path.exists(fullpath): # it doesn't exist on the filesystem, but the configuration # refers to it, we're serving a write request, and the user is # authorized to do that: create the repository on the fly diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index f1c1930..9884694 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -215,6 +215,30 @@ def test_simple_read_space(): ) eq(got, "git upload-pack '%s/foo.git'" % tmp) +def test_read_inits_if_needed(): + # a clone of a non-existent repository (but where config + # authorizes you to do that) will create the repository on the fly + tmp = util.maketemp() + cfg = RawConfigParser() + cfg.add_section('gitosis') + repositories = os.path.join(tmp, 'repositories') + os.mkdir(repositories) + cfg.set('gitosis', 'repositories', repositories) + 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', 'readonly', 'foo') + got = serve.serve( + cfg=cfg, + user='jdoe', + command="git-upload-pack 'foo'", + ) + eq(got, "git-upload-pack '%s/foo.git'" % repositories) + eq(os.listdir(repositories), ['foo.git']) + assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD')) + def test_simple_write_dash(): tmp = util.maketemp() repository.init(os.path.join(tmp, 'foo.git'))