summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/objects/base.py5
-rw-r--r--lib/git/repo/base.py13
-rw-r--r--test/git/test_base.py2
-rw-r--r--test/git/test_commit.py2
-rw-r--r--test/git/test_remote.py2
-rw-r--r--test/git/test_repo.py2
-rw-r--r--test/git/test_submodule.py2
-rw-r--r--test/git/test_tree.py2
-rw-r--r--test/testlib/helper.py53
9 files changed, 32 insertions, 51 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index 82c2589c..b8cec47f 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -114,7 +114,10 @@ class Object(LazyMixin):
class IndexObject(Object):
"""Base for all objects that can be part of the index file , namely Tree, Blob and
SubModule objects"""
- __slots__ = ("path", "mode")
+ __slots__ = ("path", "mode")
+
+ # for compatability with iterable lists
+ _id_attribute_ = 'path'
def __init__(self, repo, binsha, mode=None, path=None):
"""Initialize a newly instanced IndexObject
diff --git a/lib/git/repo/base.py b/lib/git/repo/base.py
index 3a395af0..0355b062 100644
--- a/lib/git/repo/base.py
+++ b/lib/git/repo/base.py
@@ -225,7 +225,7 @@ class Repo(object):
@property
def submodules(self):
""":return: git.IterableList(Submodule, ...) of direct submodules"""
- return self.list_submodules(recursive=False)
+ return Submodule.list_items(self)
def submodule(self, name):
""":return: Submodule with the given name
@@ -236,12 +236,11 @@ class Repo(object):
raise ValueError("Didn't find submodule named %r" % name)
# END exception handling
- def list_submodules(self, recursive=False):
- """A list if Submodule objects available in this repository
- :param recursive: If True, submodules of submodules (and so forth) will be
- returned as well as part of a depth-first traversal
- :return: ``git.IterableList(Submodule, ...)"""
- return RootModule(self).list_traverse(ignore_self=1, depth = recursive and -1 or 1)
+ def iter_submodules(self, *args, **kwargs):
+ """An iterator yielding Submodule instances, see Traversable interface
+ for a description of args and kwargs
+ :return: Iterator"""
+ return RootModule(self).traverse(*args, **kwargs)
@property
def tags(self):
diff --git a/test/git/test_base.py b/test/git/test_base.py
index db13feae..25d1e4e9 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -83,7 +83,7 @@ class TestBase(TestBase):
# objects must be resolved to shas so they compare equal
assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_with_bare_rw_repo(self, bare_rw_repo):
assert bare_rw_repo.config_reader("repository").getboolean("core", "bare")
assert os.path.isfile(os.path.join(bare_rw_repo.git_dir,'HEAD'))
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 2692938f..c3ce5c92 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -237,7 +237,7 @@ class TestCommit(TestBase):
name_rev = self.rorepo.head.commit.name_rev
assert isinstance(name_rev, basestring)
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_serialization(self, rwrepo):
# create all commits of our repo
assert_commit_serialization(rwrepo, '0.1.6')
diff --git a/test/git/test_remote.py b/test/git/test_remote.py
index 1db4bc32..c52f907e 100644
--- a/test/git/test_remote.py
+++ b/test/git/test_remote.py
@@ -422,7 +422,7 @@ class TestRemote(TestBase):
origin = rw_repo.remote('origin')
assert origin == rw_repo.remotes.origin
- @with_bare_rw_repo
+ @with_rw_repo('HEAD', bare=True)
def test_creation_and_removal(self, bare_rw_repo):
new_name = "test_new_one"
arg_list = (new_name, "git@server:hello.git")
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 063b5dff..3a59f05e 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -558,7 +558,7 @@ class TestRepo(TestBase):
def test_submodules(self):
assert len(self.rorepo.submodules) == 1 # non-recursive
- assert len(self.rorepo.list_submodules(recursive=True)) == 2
+ assert len(list(self.rorepo.iter_submodules())) == 2
assert isinstance(self.rorepo.submodule("lib/git/ext/gitdb"), Submodule)
self.failUnlessRaises(ValueError, self.rorepo.submodule, "doesn't exist")
diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py
index 2ca0b269..ac179c22 100644
--- a/test/git/test_submodule.py
+++ b/test/git/test_submodule.py
@@ -105,7 +105,7 @@ class TestSubmodule(TestBase):
def test_base_rw(self, rwrepo):
self._do_base_tests(rwrepo)
- @with_bare_rw_repo
+ @with_rw_repo(k_subm_current, bare=True)
def test_base_bare(self, rwrepo):
self._do_base_tests(rwrepo)
diff --git a/test/git/test_tree.py b/test/git/test_tree.py
index d08999bd..18688424 100644
--- a/test/git/test_tree.py
+++ b/test/git/test_tree.py
@@ -102,6 +102,8 @@ class TestTree(TestBase):
assert isinstance(obj, (Blob, Tree))
all_items.append(obj)
# END for each object
+ assert all_items == root.list_traverse()
+
# limit recursion level to 0 - should be same as default iteration
assert all_items
assert 'CHANGES' in root
diff --git a/test/testlib/helper.py b/test/testlib/helper.py
index b5b6fad7..c79ecaa1 100644
--- a/test/testlib/helper.py
+++ b/test/testlib/helper.py
@@ -14,6 +14,11 @@ import cStringIO
GIT_REPO = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+__all__ = (
+ 'fixture_path', 'fixture', 'absolute_project_path', 'StringProcessAdapter',
+ 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO'
+ )
+
#{ Routines
def fixture_path(name):
@@ -58,41 +63,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
os.chmod(fullpath, 0777)
os.remove(fullpath)
-def with_bare_rw_repo(func):
- """
- Decorator providing a specially made read-write repository to the test case
- decorated with it. The test case requires the following signature::
- def case(self, rw_repo)
-
- The rwrepo will be a bare clone or the types rorepo. Once the method finishes,
- it will be removed completely.
-
- Use this if you want to make purely index based adjustments, change refs, create
- heads, generally operations that do not need a working tree."""
- def bare_repo_creator(self):
- repo_dir = tempfile.mktemp("bare_repo_%s" % func.__name__)
- rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=True)
- prev_cwd = os.getcwd()
- try:
- try:
- return func(self, rw_repo)
- except:
- # assure we keep the repo for debugging
- print >> sys.stderr, "Keeping bare repo after failure: %s" % repo_dir
- repo_dir = None
- raise
- # END handle exceptions
- finally:
- rw_repo.git.clear_cache()
- if repo_dir is not None:
- shutil.rmtree(repo_dir, onerror=_rmtree_onerror)
- # END remove repo dir
- # END cleanup
- # END bare repo creator
- bare_repo_creator.__name__ = func.__name__
- return bare_repo_creator
-
-def with_rw_repo(working_tree_ref):
+def with_rw_repo(working_tree_ref, bare=False):
"""
Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
out the working tree at the given working_tree_ref.
@@ -105,11 +76,17 @@ def with_rw_repo(working_tree_ref):
assert isinstance(working_tree_ref, basestring), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
def repo_creator(self):
- repo_dir = tempfile.mktemp("non_bare_%s" % func.__name__)
- rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=False, n=True)
+ prefix = 'non_'
+ if bare:
+ prefix = ''
+ #END handle prefix
+ repo_dir = tempfile.mktemp("%sbare_%s" % (prefix, func.__name__))
+ rw_repo = self.rorepo.clone(repo_dir, shared=True, bare=bare, n=True)
rw_repo.head.commit = rw_repo.commit(working_tree_ref)
- rw_repo.head.reference.checkout()
+ if not bare:
+ rw_repo.head.reference.checkout()
+ # END handle checkout
prev_cwd = os.getcwd()
os.chdir(rw_repo.working_dir)