summaryrefslogtreecommitdiff
path: root/test/git/test_index.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-23 21:49:13 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-23 21:49:13 +0200
commit0cd09bd306486028f5442c56ef2e947355a06282 (patch)
tree1cec6080050543833c8377d81f4de96e70ef17c2 /test/git/test_index.py
parent13a26d4f9c22695033040dfcd8c76fd94187035b (diff)
downloadgitpython-0cd09bd306486028f5442c56ef2e947355a06282.tar.gz
index.remove implemented including throrough test
Diffstat (limited to 'test/git/test_index.py')
-rw-r--r--test/git/test_index.py64
1 files changed, 62 insertions, 2 deletions
diff --git a/test/git/test_index.py b/test/git/test_index.py
index 7236aad9..2f8fed32 100644
--- a/test/git/test_index.py
+++ b/test/git/test_index.py
@@ -9,6 +9,7 @@ from git import *
import inspect
import os
import tempfile
+import glob
class TestTree(TestBase):
@@ -174,8 +175,67 @@ class TestTree(TestBase):
finally:
fp.close()
+
+ def _count_existing(self, repo, files):
+ existing = 0
+ basedir = repo.git.git_dir
+ for f in files:
+ existing += os.path.isfile(os.path.join(basedir, f))
+ # END for each deleted file
+ return existing
+ # END num existing helper
+
+
+
@with_rw_repo('0.1.6')
def test_index_mutation(self, rw_repo):
- # add / remove / commit / Working Tree Handling
- self.fail( "add, remove, commit, working tree handling" )
+ index = rw_repo.index
+ num_entries = len(index.entries)
+ # remove all of the files, provide a wild mix of paths, BaseIndexEntries,
+ # IndexEntries
+ def mixed_iterator():
+ count = 0
+ for entry in index.entries.itervalues():
+ type_id = count % 4
+ if type_id == 0: # path
+ yield entry.path
+ elif type_id == 1: # blob
+ yield Blob(rw_repo, entry.sha, entry.mode, entry.path)
+ elif type_id == 2: # BaseIndexEntry
+ yield BaseIndexEntry(entry[:4])
+ elif type_id == 3: # IndexEntry
+ yield entry
+ else:
+ raise AssertionError("Invalid Type")
+ count += 1
+ # END for each entry
+ # END mixed iterator
+ deleted_files = index.remove(mixed_iterator(), working_tree=False)
+ assert deleted_files
+ assert self._count_existing(rw_repo, deleted_files) == len(deleted_files)
+ assert len(index.entries) == 0
+
+ # reset the index to undo our changes
+ index.reset()
+ assert len(index.entries) == num_entries
+
+ # remove with working copy
+ deleted_files = index.remove(mixed_iterator(), working_tree=True)
+ assert deleted_files
+ assert self._count_existing(rw_repo, deleted_files) == 0
+
+ # reset everything
+ index.reset(working_tree=True)
+ assert self._count_existing(rw_repo, deleted_files) == len(deleted_files)
+
+ # invalid type
+ self.failUnlessRaises(TypeError, index.remove, [1])
+
+ # absolute path
+ deleted_files = index.remove([os.path.join(rw_repo.git.git_dir,"lib")], r=True)
+ assert len(deleted_files) > 1
+ self.failUnlessRaises(ValueError, index.remove, ["/doesnt/exists"])
+
+ # re-add all files in lib
+ self.fail( "add, commit, working tree handling" )