Skip to content

Commit

Permalink
Let even readonly operations init a repo if needed.
Browse files Browse the repository at this point in the history
Git >=1.6.2 support cloning empty repositories; this is a good way to
bootstrap development on a new repository.
  • Loading branch information
tv42 committed Sep 17, 2009
1 parent 4b19d45 commit dedb3dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions gitosis/serve.py
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions gitosis/test/test_serve.py
Expand Up @@ -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'))
Expand Down

0 comments on commit dedb3dc

Please sign in to comment.