From 2e068602d08643b249de1ab2bc57d1ec85645bea Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Mon, 3 Sep 2007 19:24:04 -0700 Subject: [PATCH] Don't git init when it's not needed. Confusion between pathnames with extensions and without made gitosis-serve confused when it needs to create a repository and when not. --- gitosis/serve.py | 8 ++++---- gitosis/test/test_serve.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gitosis/serve.py b/gitosis/serve.py index 551ac46..92f150a 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -93,14 +93,14 @@ def serve( # didn't have write access and tried to write raise WriteAccessDenied() - if (not os.path.exists(newpath) + assert not newpath.endswith('.git'), \ + 'git extension should have been stripped: %r' % newpath + repopath = '%s.git' % newpath + if (not os.path.exists(repopath) and verb in COMMANDS_WRITE): # 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 - assert not newpath.endswith('.git'), \ - 'git extension should have been stripped: %r' % newpath - repopath = '%s.git' % newpath repository.init(path=repopath) # put the verb back together with the new path diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index 416587a..ec757a4 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -143,7 +143,7 @@ def test_push_inits_if_needed(): cfg.add_section('group foo') cfg.set('group foo', 'members', 'jdoe') cfg.set('group foo', 'writable', 'foo') - got = serve.serve( + serve.serve( cfg=cfg, user='jdoe', command="git-receive-pack 'foo'", @@ -161,10 +161,31 @@ def test_push_inits_if_needed_haveExtension(): cfg.add_section('group foo') cfg.set('group foo', 'members', 'jdoe') cfg.set('group foo', 'writable', 'foo') - got = serve.serve( + serve.serve( cfg=cfg, user='jdoe', command="git-receive-pack 'foo.git'", ) eq(os.listdir(tmp), ['foo.git']) assert os.path.isfile(os.path.join(tmp, 'foo.git', 'HEAD')) + +def test_push_inits_if_needed_existsWithExtension(): + tmp = util.maketemp() + os.mkdir(os.path.join(tmp, 'foo.git')) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('group foo') + cfg.set('group foo', 'members', 'jdoe') + cfg.set('group foo', 'writable', 'foo') + serve.serve( + cfg=cfg, + user='jdoe', + command="git-receive-pack 'foo'", + ) + eq(os.listdir(tmp), ['foo.git']) + # it should *not* have HEAD here as we just mkdirred it and didn't + # create it properly, and the mock repo didn't have anything in + # it.. having HEAD implies serve ran git init, which is supposed + # to be unnecessary here + eq(os.listdir(os.path.join(tmp, 'foo.git')), [])