aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-31 14:55:54 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-31 17:00:04 +0200
commit7fc4a7e4ab4a3b05d9dd6704ecaefb2a8953551f (patch)
tree042418b67ad8458007070f9819d05d28566a301b
parent25fc07047b9abf915d300d0072734296bbaa5d82 (diff)
gbp.git.repository: add GitRepository.make_tree
Signed-off-by: Guido Günther <agx@sigxcpu.org>
-rw-r--r--gbp/git/repository.py23
-rw-r--r--tests/test_GitRepository.py28
2 files changed, 33 insertions, 18 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 1c6fc34..8a99ff6 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -636,7 +636,6 @@ class GitRepository(object):
@return: C{True} if the repository has that tree, C{False} otherwise
@rtype: C{bool}
"""
-
out, ret = self._git_getoutput('ls-tree', [ treeish ])
return [ True, False ][ret != 0]
@@ -644,7 +643,7 @@ class GitRepository(object):
"""
Create a tree object from the current index
- @param index_file: alternate index file to write the current index to
+ @param index_file: alternate index file to read changes from
@type index_file: C{str}
@return: the new tree object's sha1
@rtype: C{str}
@@ -659,6 +658,26 @@ class GitRepository(object):
raise GitRepositoryError("Can't write out current index")
return tree[0].strip()
+ def make_tree(self, contents):
+ """
+ Create a tree based on contents. I{contents} has the same format than
+ the I{GitRepository.list_tree} output.
+ """
+ out=''
+ args = GitArgs('-z')
+
+ for obj in contents:
+ mode, type, sha1, name = obj
+ out += '%s %s %s\t%s\0' % (mode, type, sha1, name)
+
+ sha1, err, ret = self._git_inout('mktree',
+ args.args,
+ out,
+ capture_stderr=True)
+ if ret:
+ raise GitRepositoryError("Failed to mktree: '%s'" % err)
+ return sha1.strip()
+
def get_obj_type(self, obj):
"""
Get type of a git repository object
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 5393071..121be90 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -617,33 +617,29 @@ def test_update_ref():
"""
-def test_write_file():
+def test_make_tree():
"""
- Test git-write-file
+ Test git-mk-tree
Methods tested:
- L{gbp.git.GitRepository.write_file}
-
- >>> import gbp.git
- >>> repo = gbp.git.GitRepository(repo_dir)
- >>> repo.write_file('testfile')
- '19af7398c894bc5e86e17259317e4db519e9241f'
- """
-
-
-def test_list_tree():
- """
- Test git-ls-tree
-
- Methods tested:
- L{gbp.git.GitRepository.list_tree}
+ - L{gbp.git.GitRepository.make_tree}
>>> import gbp.git
>>> repo = gbp.git.GitRepository(repo_dir)
- >>> repo.list_tree('HEAD')
+ >>> sha1 = repo.write_file('testfile')
+ >>> sha1
+ '19af7398c894bc5e86e17259317e4db519e9241f'
+ >>> head = repo.list_tree('HEAD')
+ >>> head
[['100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', 'testfile']]
+ >>> head.append(['100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', 'testfile2'])
+ >>> repo.make_tree(head)
+ '745951810c9e22fcc6de9b23f05efd6ab5512123'
"""
+
def test_update_submodules():
"""
Updating submodules if we don't have any is a noop