summaryrefslogtreecommitdiff
path: root/morphlib/gitdir_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-11 17:11:26 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-22 13:49:25 +0000
commit994f06bc33ff2829e261eeec8b21ae1904967fc9 (patch)
tree6691dfd74614efdd1e55ff0f0d64a86619cf5864 /morphlib/gitdir_tests.py
parent069255328af9a466987b198accfbacb17eb93c9b (diff)
downloadmorph-994f06bc33ff2829e261eeec8b21ae1904967fc9.tar.gz
GitDir: Add resolve_ref_to_{commit,tree} methods
Some APIs should take SHA1 object IDs, there needs to be a way to get one from a ref. To handle this, we add APIs for getting either the commit or the tree pointed to by the ref. Commits are provided because we need to create commits from existing commits and update refs from existing values. Trees are provided because we need trees to create commits, and we can read trees into the index to eventually create another tree.
Diffstat (limited to 'morphlib/gitdir_tests.py')
-rw-r--r--morphlib/gitdir_tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/morphlib/gitdir_tests.py b/morphlib/gitdir_tests.py
index 803f1b3e..a2e530f1 100644
--- a/morphlib/gitdir_tests.py
+++ b/morphlib/gitdir_tests.py
@@ -148,6 +148,18 @@ class GitDirectoryContentsTests(unittest.TestCase):
gd.checkout('foo')
self.assertEqual(gd.HEAD, 'foo')
+ def test_resolve_ref(self):
+ # Just tests that you get an object IDs back and that the
+ # commit and tree IDs are different, since checking the actual
+ # value of the commit requires foreknowledge of the result or
+ # re-implementing the body in the test.
+ gd = morphlib.gitdir.GitDirectory(self.dirname)
+ commit = gd.resolve_ref_to_commit(gd.HEAD)
+ self.assertEqual(len(commit), 40)
+ tree = gd.resolve_ref_to_tree(gd.HEAD)
+ self.assertEqual(len(tree), 40)
+ self.assertNotEqual(commit, tree)
+
def test_uncommitted_changes(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
self.assertEqual(sorted(gd.get_uncommitted_changes()),