Add .git to gitweb projects list if only that version of path exists.

This commit is contained in:
Tommi Virtanen 2007-06-05 14:06:33 +03:00
parent 8a6cb39b9f
commit 4f6a8b8770
2 changed files with 44 additions and 1 deletions

View file

@ -25,7 +25,7 @@ To plug this into ``gitweb``, you have two choices.
isolates the changes a bit more nicely. Recommended.
"""
import os, urllib
import os, urllib, logging
from ConfigParser import RawConfigParser, NoSectionError, NoOptionError
@ -35,6 +35,16 @@ def _escape_filename(s):
s = s.replace('"', '\\"')
return s
def _getReposityDir(config):
repositories = os.path.expanduser('~')
try:
path = config.get('gitosis', 'repositories')
except (NoSectionError, NoOptionError):
pass
else:
repositories = os.path.join(repositories, path)
return repositories
def generate(config, fp):
"""
Generate a config file and projects list for ``gitweb``.
@ -45,6 +55,10 @@ def generate(config, fp):
:param fp: writable for ``projects.list``
:type fp: (file-like, anything with ``.write(data)``)
"""
log = logging.getLogger('gitosis.access.haveAccess')
repositories = _getReposityDir(config)
try:
global_enable = config.getboolean('gitosis', 'gitweb')
except (NoSectionError, NoOptionError):
@ -67,6 +81,16 @@ def generate(config, fp):
continue
name, = l
if not os.path.exists(os.path.join(repositories, name)):
namedotgit = '%s.git' % name
if os.path.exists(os.path.join(repositories, namedotgit)):
name = namedotgit
else:
log.warning(
'Cannot find %(name)r in %(repositories)r'
% dict(name=name, repositories=repositories))
response = [name]
try:
owner = config.get(section, 'owner')

View file

@ -1,9 +1,11 @@
from nose.tools import eq_ as eq
import os
from ConfigParser import RawConfigParser
from cStringIO import StringIO
from gitosis import gitweb
from gitosis.test.util import mkdir, maketemp
def test_projectsList_empty():
cfg = RawConfigParser()
@ -86,3 +88,20 @@ def test_projectsList_multiple_globalGitwebYes():
quux
foo%2Fbar John+Doe
''')
def test_projectsList_reallyEndsWithGit():
tmp = maketemp()
path = os.path.join(tmp, 'foo.git')
mkdir(path)
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', tmp)
cfg.add_section('repo foo')
cfg.set('repo foo', 'gitweb', 'yes')
got = StringIO()
gitweb.generate(
config=cfg,
fp=got)
eq(got.getvalue(), '''\
foo.git
''')