diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/git/test_diff.py | 13 | ||||
-rw-r--r-- | test/git/test_index.py | 35 |
2 files changed, 43 insertions, 5 deletions
diff --git a/test/git/test_diff.py b/test/git/test_diff.py index d7505987..ead231e5 100644 --- a/test/git/test_diff.py +++ b/test/git/test_diff.py @@ -59,6 +59,14 @@ class TestDiff(TestBase): assertion_map.setdefault(key, 0) assertion_map[key] = assertion_map[key]+len(list(diff_index.iter_change_type(ct))) # END for each changetype + + # check entries + diff_set = set() + diff_set.add(diff_index[0]) + diff_set.add(diff_index[0]) + assert len(diff_set) == 1 + assert diff_index[0] == diff_index[0] + assert not (diff_index[0] != diff_index[0]) # END diff index checking # END for each patch option # END for each path option @@ -71,7 +79,4 @@ class TestDiff(TestBase): for key,value in assertion_map.items(): assert value, "Did not find diff for %s" % key # END for each iteration type - - def test_diff_index_working_tree(self): - self.fail("""Find a good way to diff an index against the working tree -which is not possible with the current interface""") + diff --git a/test/git/test_index.py b/test/git/test_index.py index 5c643a67..257acf10 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -102,12 +102,45 @@ class TestTree(TestBase): assert num_blobs == len(three_way_index.entries) @with_rw_repo('0.1.6') - def test_from_index(self, rw_repo): + def test_from_index_and_diff(self, rw_repo): # default Index instance points to our index index = Index(rw_repo) + assert index.path is not None assert len(index.entries) # write the file back index.write() # could sha it, or check stats + + # test diff + # resetting the head will leave the index in a different state, and the + # diff will yield a few changes + cur_head_commit = rw_repo.head.commit + ref = rw_repo.head.reset(rw_repo, 'HEAD~6', index=True, working_tree=False) + + # diff against same index is 0 + diff = index.diff() + assert len(diff) == 0 + + # against HEAD as string, must be the same as it matches index + diff = index.diff('HEAD') + assert len(diff) == 0 + + # against previous head, there must be a difference + diff = index.diff(cur_head_commit) + assert len(diff) + + # we reverse the result + adiff = index.diff(str(cur_head_commit), R=True) + odiff = index.diff(cur_head_commit, R=False) # now its not reversed anymore + assert adiff != odiff + assert odiff == diff # both unreversed diffs against HEAD + + # against working copy - its still at cur_commit + wdiff = index.diff(None) + assert wdiff != adiff + assert wdiff != odiff + + # against something unusual + self.failUnlessRaises(ValueError, index.diff, int) |