diff options
Diffstat (limited to 'test/git/test_index.py')
-rw-r--r-- | test/git/test_index.py | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/test/git/test_index.py b/test/git/test_index.py index 21d610db..efb1b477 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -55,7 +55,7 @@ class TestIndex(TestBase): last_val = None entry = index.entries.itervalues().next() for attr in ("path","ctime","mtime","dev","inode","mode","uid", - "gid","size","sha","stage"): + "gid","size","binsha", "hexsha", "stage"): val = getattr(entry, attr) # END for each method @@ -128,7 +128,7 @@ class TestIndex(TestBase): # writing a tree should fail with an unmerged index - self.failUnlessRaises(GitCommandError, three_way_index.write_tree) + self.failUnlessRaises(UnmergedEntriesError, three_way_index.write_tree) # removed unmerged entries unmerged_blob_map = three_way_index.unmerged_blobs() @@ -159,27 +159,27 @@ class TestIndex(TestBase): manifest_entry = rw_repo.index.entries[manifest_key] rw_repo.index.merge_tree(next_commit) # only one change should be recorded - assert manifest_entry.sha != rw_repo.index.entries[manifest_key].sha + assert manifest_entry.binsha != rw_repo.index.entries[manifest_key].binsha rw_repo.index.reset(rw_repo.head) - assert rw_repo.index.entries[manifest_key].sha == manifest_entry.sha + assert rw_repo.index.entries[manifest_key].binsha == manifest_entry.binsha # FAKE MERGE ############# # Add a change with a NULL sha that should conflict with next_commit. We # pretend there was a change, but we do not even bother adding a proper # sha for it ( which makes things faster of course ) - manifest_fake_entry = BaseIndexEntry((manifest_entry[0], Diff.null_hex_sha, 0, manifest_entry[3])) + manifest_fake_entry = BaseIndexEntry((manifest_entry[0], "\0"*20, 0, manifest_entry[3])) rw_repo.index.add([manifest_fake_entry]) # add actually resolves the null-hex-sha for us as a feature, but we can # edit the index manually - assert rw_repo.index.entries[manifest_key].sha != Diff.null_hex_sha + assert rw_repo.index.entries[manifest_key].binsha != Object.NULL_BIN_SHA # must operate on the same index for this ! Its a bit problematic as # it might confuse people index = rw_repo.index index.entries[manifest_key] = IndexEntry.from_base(manifest_fake_entry) index.write() - assert rw_repo.index.entries[manifest_key].sha == Diff.null_hex_sha + assert rw_repo.index.entries[manifest_key].hexsha == Diff.NULL_HEX_SHA # a three way merge would result in a conflict and fails as the command will # not overwrite any entries in our index and hence leave them unmerged. This is @@ -189,10 +189,11 @@ class TestIndex(TestBase): # the only way to get the merged entries is to safe the current index away into a tree, # which is like a temporary commit for us. This fails as well as the NULL sha deos not # have a corresponding object - self.failUnlessRaises(GitCommandError, index.write_tree) + # NOTE: missing_ok is not a kwarg anymore, missing_ok is always true + # self.failUnlessRaises(GitCommandError, index.write_tree) - # if missing objects are okay, this would work though - tree = index.write_tree(missing_ok = True) + # if missing objects are okay, this would work though ( they are always okay now ) + tree = index.write_tree() # now make a proper three way merge with unmerged entries unmerged_tree = IndexFile.from_tree(rw_repo, parent_commit, tree, next_commit) @@ -348,7 +349,7 @@ class TestIndex(TestBase): if type_id == 0: # path yield entry.path elif type_id == 1: # blob - yield Blob(rw_repo, entry.sha, entry.mode, entry.path) + yield Blob(rw_repo, entry.hexsha, entry.mode, entry.path) elif type_id == 2: # BaseIndexEntry yield BaseIndexEntry(entry[:4]) elif type_id == 3: # IndexEntry @@ -442,18 +443,19 @@ class TestIndex(TestBase): old_blob = new_commit.parents[0].tree.blobs[0] entries = index.reset(new_commit).add([old_blob], fprogress=self._fprogress_add) self._assert_fprogress(entries) - assert index.entries[(old_blob.path,0)].sha == old_blob.sha and len(entries) == 1 + assert index.entries[(old_blob.path,0)].hexsha == old_blob.sha and len(entries) == 1 # mode 0 not allowed - null_sha = "0"*40 - self.failUnlessRaises(ValueError, index.reset(new_commit).add, [BaseIndexEntry((0, null_sha,0,"doesntmatter"))]) + null_hex_sha = Diff.NULL_HEX_SHA + null_bin_sha = "\0" * 20 + self.failUnlessRaises(ValueError, index.reset(new_commit).add, [BaseIndexEntry((0, null_bin_sha,0,"doesntmatter"))]) # add new file new_file_relapath = "my_new_file" new_file_path = self._make_file(new_file_relapath, "hello world", rw_repo) - entries = index.reset(new_commit).add([BaseIndexEntry((010644, null_sha, 0, new_file_relapath))], fprogress=self._fprogress_add) + entries = index.reset(new_commit).add([BaseIndexEntry((010644, null_bin_sha, 0, new_file_relapath))], fprogress=self._fprogress_add) self._assert_fprogress(entries) - assert len(entries) == 1 and entries[0].sha != null_sha + assert len(entries) == 1 and entries[0].hexsha != null_hex_sha # add symlink if sys.platform != "win32": @@ -467,21 +469,21 @@ class TestIndex(TestBase): assert S_ISLNK(index.entries[index.entry_key("my_real_symlink", 0)].mode) # we expect only the target to be written - assert index.repo.odb.stream(entries[0].sha).read() == target + assert index.repo.odb.stream(entries[0].binsha).read() == target # END real symlink test # add fake symlink and assure it checks-our as symlink fake_symlink_relapath = "my_fake_symlink" link_target = "/etc/that" fake_symlink_path = self._make_file(fake_symlink_relapath, link_target, rw_repo) - fake_entry = BaseIndexEntry((0120000, null_sha, 0, fake_symlink_relapath)) + fake_entry = BaseIndexEntry((0120000, null_hex_sha, 0, fake_symlink_relapath)) entries = index.reset(new_commit).add([fake_entry], fprogress=self._fprogress_add) self._assert_fprogress(entries) - assert entries[0].sha != null_sha + assert entries[0].hexsha != null_hex_sha assert len(entries) == 1 and S_ISLNK(entries[0].mode) # assure this also works with an alternate method - full_index_entry = IndexEntry.from_base(BaseIndexEntry((0120000, entries[0].sha, 0, entries[0].path))) + full_index_entry = IndexEntry.from_base(BaseIndexEntry((0120000, entries[0].binsha, 0, entries[0].path))) entry_key = index.entry_key(full_index_entry) index.reset(new_commit) @@ -493,7 +495,7 @@ class TestIndex(TestBase): assert S_ISLNK(new_entry.mode) # a tree created from this should contain the symlink - tree = index.write_tree(True) + tree = index.write_tree() assert fake_symlink_relapath in tree # checkout the fakelink, should be a link then @@ -567,3 +569,5 @@ class TestIndex(TestBase): for filenum in range(len(paths)): assert index.entry_key(str(filenum), 0) in index.entries + def test_compare_write_tree(self): + self.fail("compare git-write-tree with python implementation, must have same output") |