aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-09-02 13:28:41 -0700
committerTommi Virtanen <tv@eagain.net>2007-09-02 13:28:41 -0700
commit3dd96139a1e4c20fe278561e7c537e02b8ffade2 (patch)
treeb82a394c634a5e67e382550e519a215d6b51836b
parentAdd unit tests for gitosis-serve. (diff)
downloadgitosis-dakkar-3dd96139a1e4c20fe278561e7c537e02b8ffade2.tar.gz
gitosis-dakkar-3dd96139a1e4c20fe278561e7c537e02b8ffade2.tar.bz2
gitosis-dakkar-3dd96139a1e4c20fe278561e7c537e02b8ffade2.zip
Make gitosis-serve create repositories on demand when pushing.
-rw-r--r--gitosis/serve.py8
-rw-r--r--gitosis/test/test_serve.py32
2 files changed, 38 insertions, 2 deletions
diff --git a/gitosis/serve.py b/gitosis/serve.py
index 2b7e7da..82976c8 100644
--- a/gitosis/serve.py
+++ b/gitosis/serve.py
@@ -10,6 +10,7 @@ import sys, os, optparse, re
from ConfigParser import RawConfigParser
from gitosis import access
+from gitosis import repository
def die(msg):
print >>sys.stderr, '%s: %s' % (sys.argv[0], msg)
@@ -106,6 +107,13 @@ def serve(
# didn't have write access and tried to write
raise WriteAccessDenied()
+ if (not os.path.exists(newpath)
+ 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
+ repository.init(path=newpath)
+
# put the verb back together with the new path
newcmd = "%(verb)s '%(newpath)s'" % dict(
verb=verb,
diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py
index a2e2e90..bbffe16 100644
--- a/gitosis/test/test_serve.py
+++ b/gitosis/test/test_serve.py
@@ -1,9 +1,11 @@
from nose.tools import eq_ as eq
from gitosis.test.util import assert_raises
+import os
from ConfigParser import RawConfigParser
from gitosis import serve
+from gitosis import repository
from gitosis.test import util
@@ -88,7 +90,11 @@ def test_bad_forbiddenCommand_write_readAccess():
assert isinstance(e, serve.ServingError)
def test_simple_read():
+ tmp = util.maketemp()
+ repository.init(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', 'readonly', 'foo')
@@ -97,10 +103,14 @@ def test_simple_read():
user='jdoe',
command="git-upload-pack 'foo'",
)
- eq(got, "git-upload-pack 'repositories/foo'")
+ eq(got, "git-upload-pack '%s/foo'" % tmp)
def test_simple_write():
+ tmp = util.maketemp()
+ repository.init(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')
@@ -109,4 +119,22 @@ def test_simple_write():
user='jdoe',
command="git-receive-pack 'foo'",
)
- eq(got, "git-receive-pack 'repositories/foo'")
+ eq(got, "git-receive-pack '%s/foo'" % tmp)
+
+def test_push_inits_if_needed():
+ # a push to 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')
+ cfg.set('gitosis', 'repositories', tmp)
+ cfg.add_section('group foo')
+ cfg.set('group foo', 'members', 'jdoe')
+ cfg.set('group foo', 'writable', 'foo')
+ got = serve.serve(
+ cfg=cfg,
+ user='jdoe',
+ command="git-receive-pack 'foo'",
+ )
+ eq(os.listdir(tmp), ['foo'])
+ assert os.path.isfile(os.path.join(tmp, 'foo', 'HEAD'))