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.
This commit is contained in:
parent
4b19d45a3b
commit
dedb3dc63f
2 changed files with 25 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in a new issue