return "<%s for %r>" % (self.__class__.__name__, self._backends)
@classmethod
- def default(cls, for_path=None):
+ def default_backends(cls):
"""Retrieve the default configuration.
This will look in the repository configuration (if for_path is
configuration.
"""
paths = []
- if for_path is not None:
- paths.append(for_path)
paths.append(os.path.expanduser("~/.gitconfig"))
paths.append("/etc/gitconfig")
backends = []
for path in paths:
try:
cf = ConfigFile.from_path(path)
- except IOError, e:
+ except (IOError, OSError), e:
if e.errno != errno.ENOENT:
raise
else:
continue
backends.append(cf)
- return cls(backends)
+ return backends
def get(self, name):
for backend in self._backends:
return self.commit(sha).parents
def get_config(self):
- from dulwich.config import ConfigFile
+ from dulwich.config import ConfigFile, StackedConfig
+ backends = []
try:
p = ConfigFile.from_path(os.path.join(self._controldir, 'config'))
except (IOError, OSError), e:
- if e.errno == errno.ENOENT:
- return ConfigFile()
- raise
- return dict((section, dict(p.items(section)))
- for section in p.sections())
+ if e.errno != errno.ENOENT:
+ raise
+ backends.extend(StackedConfig.default_backends())
+ return StackedConfig(backends)
def commit(self, sha):
"""Retrieve the commit with a particular SHA.
class StackedConfigTests(TestCase):
- def test_default(self):
- StackedConfig.default()
+ def test_default_backends(self):
+ StackedConfig.default_backends()
tree_lookup_path,
)
from dulwich import objects
-from dulwich.config import ConfigFile
+from dulwich.config import Config
from dulwich.repo import (
check_ref_format,
DictRefsContainer,
def test_get_config(self):
r = self._repo = open_repo('ooo_merge.git')
- self.assertEquals(ConfigFile(), r.get_config())
+ self.assertIsInstance(r.get_config(), Config)
def test_common_revisions(self):
"""