diff options
author | 2007-11-29 00:40:34 +0200 | |
---|---|---|
committer | 2007-11-29 00:40:34 +0200 | |
commit | 2078a0c828a064d0e12eed9110c3f71237a3d022 (patch) | |
tree | 73f85e3d7b887241e78508f253cfbac9e317ec01 | |
parent | Add instructions for using gitweb. (diff) | |
download | gitosis-gentoo-2078a0c828a064d0e12eed9110c3f71237a3d022.tar.gz gitosis-gentoo-2078a0c828a064d0e12eed9110c3f71237a3d022.tar.bz2 gitosis-gentoo-2078a0c828a064d0e12eed9110c3f71237a3d022.zip |
Write gitweb projects.list to ~/gitosis, not inside the gitosis-admin repo.
This allows running gitweb as a separate user without needing to allow it
read access to gitosis-admin.git. Running as separate user will still most
likely require a ``chgrp www-data`` of the relevant repositories, but
nothing not already decided public needs to be exposed.
Existing gitweb users will need to adjust their gitweb.conf to point to
the new location of the projects.list file.
Removing the old projects.list from
~git/repositories/gitosis-admin.git/projects.list is safe once gitweb
has switched to using the new location.
-rw-r--r-- | gitosis/run_hook.py | 4 | ||||
-rw-r--r-- | gitosis/serve.py | 14 | ||||
-rw-r--r-- | gitosis/test/test_serve.py | 108 | ||||
-rw-r--r-- | gitosis/util.py | 6 | ||||
-rw-r--r-- | gitweb.conf | 2 |
5 files changed, 90 insertions, 44 deletions
diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py index a7943fc..f9a009d 100644 --- a/gitosis/run_hook.py +++ b/gitosis/run_hook.py @@ -13,6 +13,7 @@ from gitosis import ssh from gitosis import gitweb from gitosis import gitdaemon from gitosis import app +from gitosis import util def post_update(cfg, git_dir): export = os.path.join(git_dir, 'gitosis-export') @@ -31,9 +32,10 @@ def post_update(cfg, git_dir): gitweb.set_descriptions( config=cfg, ) + generated = util.getGeneratedFilesDir(config=cfg) gitweb.generate_project_list( config=cfg, - path=os.path.join(git_dir, 'projects.list'), + path=os.path.join(generated, 'projects.list'), ) gitdaemon.set_export_ok( config=cfg, diff --git a/gitosis/serve.py b/gitosis/serve.py index 0b8f775..0f9cb5c 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -117,15 +117,11 @@ def serve( gitweb.set_descriptions( config=cfg, ) - gitosis_repo = os.path.join(topdir, 'gitosis-admin.git') - if os.path.isdir(gitosis_repo): - gitweb.generate_project_list( - config=cfg, - path=os.path.join( - gitosis_repo, - 'projects.list', - ), - ) + generated = util.getGeneratedFilesDir(config=cfg) + gitweb.generate_project_list( + config=cfg, + path=os.path.join(generated, 'projects.list'), + ) gitdaemon.set_export_ok( config=cfg, ) diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index b842bdf..d6030d2 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -139,7 +139,12 @@ def test_push_inits_if_needed(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') @@ -148,8 +153,8 @@ def test_push_inits_if_needed(): user='jdoe', command="git-receive-pack 'foo'", ) - eq(os.listdir(tmp), ['foo.git']) - assert os.path.isfile(os.path.join(tmp, 'foo.git', 'HEAD')) + eq(os.listdir(repositories), ['foo.git']) + assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD')) def test_push_inits_if_needed_haveExtension(): # a push to a non-existent repository (but where config authorizes @@ -157,7 +162,12 @@ def test_push_inits_if_needed_haveExtension(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') @@ -166,14 +176,19 @@ def test_push_inits_if_needed_haveExtension(): 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')) + eq(os.listdir(repositories), ['foo.git']) + assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD')) def test_push_inits_subdir_parent_missing(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo/bar') @@ -182,20 +197,25 @@ def test_push_inits_subdir_parent_missing(): user='jdoe', command="git-receive-pack 'foo/bar.git'", ) - eq(os.listdir(tmp), ['foo']) - foo = os.path.join(tmp, 'foo') + eq(os.listdir(repositories), ['foo']) + foo = os.path.join(repositories, 'foo') util.check_mode(foo, 0750, is_dir=True) eq(os.listdir(foo), ['bar.git']) - assert os.path.isfile(os.path.join(tmp, 'foo', 'bar.git', 'HEAD')) + assert os.path.isfile(os.path.join(repositories, 'foo', 'bar.git', 'HEAD')) def test_push_inits_subdir_parent_exists(): tmp = util.maketemp() - foo = os.path.join(tmp, 'foo') - # silly mode on purpose; not to be touched - os.mkdir(foo, 0751) cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + repositories = os.path.join(tmp, 'repositories') + os.mkdir(repositories) + foo = os.path.join(repositories, 'foo') + # silly mode on purpose; not to be touched + os.mkdir(foo, 0751) + 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', 'writable', 'foo/bar') @@ -204,31 +224,33 @@ def test_push_inits_subdir_parent_exists(): user='jdoe', command="git-receive-pack 'foo/bar.git'", ) - eq(os.listdir(tmp), ['foo']) + eq(os.listdir(repositories), ['foo']) util.check_mode(foo, 0751, is_dir=True) eq(os.listdir(foo), ['bar.git']) - assert os.path.isfile(os.path.join(tmp, 'foo', 'bar.git', 'HEAD')) + assert os.path.isfile(os.path.join(repositories, 'foo', 'bar.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) + repositories = os.path.join(tmp, 'repositories') + os.mkdir(repositories) + cfg.set('gitosis', 'repositories', repositories) cfg.add_section('group foo') cfg.set('group foo', 'members', 'jdoe') cfg.set('group foo', 'writable', 'foo') + os.mkdir(os.path.join(repositories, 'foo.git')) serve.serve( cfg=cfg, user='jdoe', command="git-receive-pack 'foo'", ) - eq(os.listdir(tmp), ['foo.git']) + eq(os.listdir(repositories), ['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')), []) + eq(os.listdir(os.path.join(repositories, 'foo.git')), []) def test_push_inits_no_stdout_spam(): # git init has a tendency to spew to stdout, and that confuses @@ -236,7 +258,12 @@ def test_push_inits_no_stdout_spam(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') @@ -256,14 +283,19 @@ def test_push_inits_no_stdout_spam(): got = new_stdout.read() new_stdout.close() eq(got, '') - eq(os.listdir(tmp), ['foo.git']) - assert os.path.isfile(os.path.join(tmp, 'foo.git', 'HEAD')) + eq(os.listdir(repositories), ['foo.git']) + assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD')) def test_push_inits_sets_description(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') @@ -274,33 +306,38 @@ def test_push_inits_sets_description(): user='jdoe', command="git-receive-pack 'foo'", ) - eq(os.listdir(tmp), ['foo.git']) - path = os.path.join(tmp, 'foo.git', 'description') + eq(os.listdir(repositories), ['foo.git']) + path = os.path.join(repositories, 'foo.git', 'description') assert os.path.exists(path) got = util.readFile(path) eq(got, 'foodesc\n') def test_push_inits_updates_projects_list(): tmp = util.maketemp() - os.mkdir(os.path.join(tmp, 'gitosis-admin.git')) cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') cfg.add_section('repo foo') cfg.set('repo foo', 'gitweb', 'yes') + os.mkdir(os.path.join(repositories, 'gitosis-admin.git')) serve.serve( cfg=cfg, user='jdoe', command="git-receive-pack 'foo'", ) eq( - sorted(os.listdir(tmp)), + sorted(os.listdir(repositories)), sorted(['foo.git', 'gitosis-admin.git']), ) - path = os.path.join(tmp, 'gitosis-admin.git', 'projects.list') + path = os.path.join(generated, 'projects.list') assert os.path.exists(path) got = util.readFile(path) eq(got, 'foo.git\n') @@ -309,7 +346,12 @@ def test_push_inits_sets_export_ok(): tmp = util.maketemp() cfg = RawConfigParser() cfg.add_section('gitosis') - cfg.set('gitosis', 'repositories', tmp) + 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', 'writable', 'foo') @@ -320,7 +362,7 @@ def test_push_inits_sets_export_ok(): user='jdoe', command="git-receive-pack 'foo'", ) - eq(os.listdir(tmp), ['foo.git']) - path = os.path.join(tmp, 'foo.git', 'git-daemon-export-ok') + eq(os.listdir(repositories), ['foo.git']) + path = os.path.join(repositories, 'foo.git', 'git-daemon-export-ok') assert os.path.exists(path) diff --git a/gitosis/util.py b/gitosis/util.py index 061660a..1c88ed1 100644 --- a/gitosis/util.py +++ b/gitosis/util.py @@ -21,3 +21,9 @@ def getRepositoryDir(config): repositories = os.path.join(repositories, path) return repositories +def getGeneratedFilesDir(config): + try: + generated = config.get('gitosis', 'generate-files-in') + except (NoSectionError, NoOptionError): + generated = os.path.expanduser('~/gitosis') + return generated diff --git a/gitweb.conf b/gitweb.conf index 83cde79..8fb62d1 100644 --- a/gitweb.conf +++ b/gitweb.conf @@ -4,7 +4,7 @@ do "/etc/gitweb.conf" if -e "/etc/gitweb.conf"; # Point to projects.list file generated by gitosis. # Here gitosis manages the user "git", who has a # home directory of /srv/example.com/git -$projects_list = "/srv/example.com/git/repositories/gitosis-admin.git/projects.list"; +$projects_list = "/srv/example.com/git/gitosis/projects.list"; # Where the actual repositories are located. $projectroot = "/srv/example.com/git/repositories"; |