summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-20 10:45:40 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-20 10:45:40 +0200
commitdd76b9e72b21d2502a51e3605e5e6ab640e5f0bd (patch)
treeaf85f25dd2f3b1947177f8f2f7cfc4b8a08e1a2d
parentaa5e366889103172a9829730de1ba26d3dcbc01b (diff)
downloadgitpython-dd76b9e72b21d2502a51e3605e5e6ab640e5f0bd.tar.gz
Fixed bare repository handling - bare is now a property to prevent writing it
-rw-r--r--CHANGES9
-rw-r--r--TODO2
-rw-r--r--lib/git/remote.py2
-rw-r--r--lib/git/repo.py42
-rw-r--r--test/git/test_repo.py13
-rw-r--r--test/git/test_utils.py1
6 files changed, 50 insertions, 19 deletions
diff --git a/CHANGES b/CHANGES
index c66930d6..a60ed237 100644
--- a/CHANGES
+++ b/CHANGES
@@ -58,8 +58,8 @@ Config
------
* The git configuration can now be read and manipulated directly from within python
using the GitConfigParser
-* Repo.config_reader returns a read-only parser
-* Repo.config_writer returns a read-write parser
+* Repo.config_reader() returns a read-only parser
+* Repo.config_writer() returns a read-write parser
Diff
----
@@ -115,8 +115,9 @@ Repo
- 'head', creates a head object
- 'tag', creates a tag object
- 'iter_trees' method
- - 'config_reader' property
- - 'config_writer' property
+ - 'config_reader' method
+ - 'config_writer' method
+ - 'bare' property, previously it was a simple attribute that could be written
Remote
------
diff --git a/TODO b/TODO
index 8f5737f0..3b9ef460 100644
--- a/TODO
+++ b/TODO
@@ -31,8 +31,6 @@ Index
Repo
----
* Nice fetch/pull handling, at least supported/wired throuhg to the git command
-* repo.bare is set according to the path it is initialized with, although it
- should be read from the configuration in fact. Check uses of repo.bare.
* Blame: Read the blame format making assumptions about its structure,
currently regex are used a lot although we can deduct what will be next.
- Read data from a stream directly from git command
diff --git a/lib/git/remote.py b/lib/git/remote.py
index e043e6db..6a9c0efb 100644
--- a/lib/git/remote.py
+++ b/lib/git/remote.py
@@ -77,7 +77,7 @@ class Remote(LazyMixin, Iterable):
def _set_cache_(self, attr):
if attr == "_config_reader":
- self._config_reader = _SectionConstraint(self.repo.config_reader, self._config_section_name())
+ self._config_reader = _SectionConstraint(self.repo.config_reader(), self._config_section_name())
else:
super(Remote, self)._set_cache_(attr)
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 966edf9d..3efefd9c 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -79,22 +79,30 @@ class Repo(object):
self.path = None
curpath = epath
+
+ # walk up the path to find the .git dir
while curpath:
if is_git_dir(curpath):
- self.bare = True
self.path = curpath
self.wd = curpath
break
gitpath = os.path.join(curpath, '.git')
if is_git_dir(gitpath):
- self.bare = False
self.path = gitpath
self.wd = curpath
break
curpath, dummy = os.path.split(curpath)
if not dummy:
break
-
+ # END while curpath
+
+ self._bare = False
+ try:
+ self._bare = self.config_reader("repository").getboolean('core','bare')
+ except Exception:
+ # lets not assume the option exists, although it should
+ pass
+
if self.path is None:
raise InvalidGitRepositoryError(epath)
@@ -113,6 +121,15 @@ class Repo(object):
doc="the project's description")
del _get_description
del _set_description
+
+
+ @property
+ def bare(self):
+ """
+ Returns
+ True if the repository is bare
+ """
+ return self._bare
@property
def heads(self):
@@ -194,8 +211,7 @@ class Repo(object):
raise ValueError( "Invalid configuration level: %r" % config_level )
- @property
- def config_reader(self):
+ def config_reader(self, config_level=None):
"""
Returns
GitConfigParser allowing to read the full git configuration, but not to write it
@@ -205,8 +221,18 @@ class Repo(object):
NOTE: On windows, system configuration cannot currently be read as the path is
unknown, instead the global path will be used.
- """
- files = [ self._get_config_path(f) for f in self.config_level ]
+
+ ``config_level``
+ For possible values, see config_writer method
+ If None, all applicable levels will be used. Specify a level in case
+ you know which exact file you whish to read to prevent reading multiple files for
+ instance
+ """
+ files = None
+ if config_level is None:
+ files = [ self._get_config_path(f) for f in self.config_level ]
+ else:
+ files = [ self._get_config_path(config_level) ]
return GitConfigParser(files, read_only=True)
def config_writer(self, config_level="repository"):
@@ -393,7 +419,7 @@ class Repo(object):
like a git-status without untracked files, hence it is dirty if the
index or the working copy have changes.
"""
- if self.bare:
+ if self._bare:
# Bare repositories with no associated working directory are
# always consired to be clean.
return False
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index b91244c9..c89bcde3 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -91,6 +91,9 @@ class TestRepo(TestCase):
assert_true(git.called)
assert_true(repo.called)
+
+ def test_bare_property(self):
+ self.repo.bare
@patch_object(Repo, '__init__')
@patch_object(Git, '_call_process')
@@ -156,11 +159,11 @@ class TestRepo(TestCase):
assert_equal('<git.Repo "%s">' % path, repr(self.repo))
def test_is_dirty_with_bare_repository(self):
- self.repo.bare = True
+ self.repo._bare = True
assert_false(self.repo.is_dirty)
def test_is_dirty(self):
- self.repo.bare = False
+ self.repo._bare = False
for index in (0,1):
for working_tree in (0,1):
for untracked_files in (0,1):
@@ -168,7 +171,7 @@ class TestRepo(TestCase):
# END untracked files
# END working tree
# END index
- self.repo.bare = True
+ self.repo._bare = True
assert self.repo.is_dirty == False
@patch_object(Git, '_call_process')
@@ -236,7 +239,9 @@ class TestRepo(TestCase):
assert len(self.repo.untracked_files) == (num_recently_untracked - len(files))
def test_config_reader(self):
- reader = self.repo.config_reader
+ reader = self.repo.config_reader() # all config files
+ assert reader.read_only
+ reader = self.repo.config_reader("repository") # single config file
assert reader.read_only
def test_config_writer(self):
diff --git a/test/git/test_utils.py b/test/git/test_utils.py
index 2983a14a..6852d0ad 100644
--- a/test/git/test_utils.py
+++ b/test/git/test_utils.py
@@ -7,6 +7,7 @@
import os
from test.testlib import *
from git import *
+from git.cmd import dashify
class TestUtils(object):
def setup(self):