From 4f6a8b8770e7aee232a3c88bf00c3ccce6378b62 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 5 Jun 2007 14:06:33 +0300 Subject: [PATCH] Add .git to gitweb projects list if only that version of path exists. --- gitosis/gitweb.py | 26 +++++++++++++++++++++++++- gitosis/test/test_gitweb.py | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/gitosis/gitweb.py b/gitosis/gitweb.py index 2ae682e..08f62f5 100644 --- a/gitosis/gitweb.py +++ b/gitosis/gitweb.py @@ -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') diff --git a/gitosis/test/test_gitweb.py b/gitosis/test/test_gitweb.py index 0840879..e634d42 100644 --- a/gitosis/test/test_gitweb.py +++ b/gitosis/test/test_gitweb.py @@ -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 +''')