aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-31 14:30:22 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-31 16:34:12 +0200
commit829eea6abab9e28894f50f3766b7bd67110a5d53 (patch)
tree91294c631acc7f9b0053aaa46be36abfbb721b0a
parenta116edd739e9ff529058a2d9df6fe67bdb17670d (diff)
gbp.git.repository: Add GitRepository.list_tree
-rw-r--r--gbp/git/repository.py27
-rw-r--r--tests/test_GitRepository.py14
2 files changed, 41 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 16bad60..43a8c46 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -672,6 +672,33 @@ class GitRepository(object):
if ret:
raise GitRepositoryError("Not a Git repository object: '%s'" % obj)
return out[0].strip()
+
+ def list_tree(self, treeish, recurse=False):
+ """
+ Get a trees content. It returns a list of objects that match the
+ 'ls-tree' output: [ mode, type, sha1, path ].
+
+ @param treeish: the treeish object to list
+ @type treeish: C{str}
+ @param recurse: whether to list the tree recursively
+ @type recurse: C{bool}
+ @return: the tree
+ @rtype: C{list} of objects. See above.
+ """
+ args = GitArgs('-z')
+ args.add_true(recurse, '-r')
+ args.add(treeish)
+
+ out, err, ret = self._git_inout('ls-tree', args.args, capture_stderr=True)
+ if ret:
+ raise GitRepositoryError("Failed to ls-tree '%s': '%s'" % (treeish, err))
+
+ tree = []
+ for line in out.split('\0'):
+ if line:
+ tree.append(line.split(None, 3))
+ return tree
+
#}
def get_config(self, name):
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index b467339..328a65f 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -616,6 +616,20 @@ def test_update_ref():
True
"""
+
+def test_list_tree():
+ """
+ Test git-ls-tree
+
+ Methods tested:
+ - L{gbp.git.GitRepository.list_tree}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> repo.list_tree('HEAD')
+ [['100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', 'testfile']]
+ """
+
def test_update_submodules():
"""
Updating submodules if we don't have any is a noop