summaryrefslogtreecommitdiff
path: root/morphlib/gitindex_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-11-11 17:57:14 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-11-22 13:49:26 +0000
commit02f112af84b32b6731b6d286d3002730bfb2eabc (patch)
tree00972b0821d1bd5f74c4fdf42c8100a15627f731 /morphlib/gitindex_tests.py
parent05cf106943ce737392d507ab1e34a3487849bd9f (diff)
downloadmorph-02f112af84b32b6731b6d286d3002730bfb2eabc.tar.gz
gitindex: Add GitIndex.add_files_from_working_tree()
This is like GitIndex.add_files_from_index_info, but uses the working tree and a list of paths. This is more convenient when the changes exist in the working tree. The comment describes its relationship with GitIndex.add_files_from_index_info, but it is faster, since it calls out to `git add` rather than calling out to `git hash-object` for every file.
Diffstat (limited to 'morphlib/gitindex_tests.py')
-rw-r--r--morphlib/gitindex_tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/morphlib/gitindex_tests.py b/morphlib/gitindex_tests.py
index af0e0444..94444091 100644
--- a/morphlib/gitindex_tests.py
+++ b/morphlib/gitindex_tests.py
@@ -73,3 +73,15 @@ class GitIndexTests(unittest.TestCase):
idx.add_files_from_index_info(
[(os.stat(filepath).st_mode, sha1, 'foo')])
self.assertEqual(list(idx.get_uncommitted_changes()),[])
+
+ def test_add_files_from_working_tree(self):
+ gd = morphlib.gitdir.GitDirectory(self.dirname)
+ idx = gd.get_index()
+ idx.add_files_from_working_tree(['foo'])
+ self.assertEqual(list(idx.get_uncommitted_changes()),[])
+
+ def test_add_files_from_working_tree_fails_in_bare(self):
+ gd = morphlib.gitdir.GitDirectory(self.mirror)
+ idx = gd.get_index()
+ self.assertRaises(morphlib.gitdir.NoWorkingTreeError,
+ idx.add_files_from_working_tree, ['foo'])