From a070b772a565a2803bb1ac4c63a1784cb249ecc3 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Mon, 11 Nov 2013 17:59:36 +0000 Subject: gitindex: Add GitIndex.write_tree() This generates a tree object from the index. This can then be used to create a commit. --- morphlib/gitindex.py | 4 ++++ morphlib/gitindex_tests.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/morphlib/gitindex.py b/morphlib/gitindex.py index a119389e..978ea0e2 100644 --- a/morphlib/gitindex.py +++ b/morphlib/gitindex.py @@ -153,3 +153,7 @@ class GitIndex(object): # 50 is an arbitrary limit for paths in morphlib.util.iter_trickle(paths, 50): self._run_git('add', *paths) + + def write_tree(self): + '''Transform the index into a tree in the object store.''' + return self._run_git('write-tree').strip() diff --git a/morphlib/gitindex_tests.py b/morphlib/gitindex_tests.py index 94444091..7a8953f2 100644 --- a/morphlib/gitindex_tests.py +++ b/morphlib/gitindex_tests.py @@ -85,3 +85,8 @@ class GitIndexTests(unittest.TestCase): idx = gd.get_index() self.assertRaises(morphlib.gitdir.NoWorkingTreeError, idx.add_files_from_working_tree, ['foo']) + + def test_write_tree(self): + gd = morphlib.gitdir.GitDirectory(self.dirname) + idx = gd.get_index() + self.assertEqual(idx.write_tree(), gd.resolve_ref_to_tree(gd.HEAD)) -- cgit v1.2.1