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.
This commit is contained in:
parent
6ab2aa0a4b
commit
2078a0c828
5 changed files with 90 additions and 44 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue