66
77from test .testlib import *
88from git import *
9+ from git .index .util import TemporaryFileSwap
910import inspect
1011import os
1112import sys
@@ -94,23 +95,24 @@ def _cmp_tree_index(self, tree, index):
9495 raise AssertionError ( "CMP Failed: Missing entries in index: %s, missing in tree: %s" % (bset - iset , iset - bset ) )
9596 # END assertion message
9697
97- def test_index_file_from_tree (self ):
98+ @with_rw_repo ('0.1.6' )
99+ def test_index_file_from_tree (self , rw_repo ):
98100 common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541"
99101 cur_sha = "4b43ca7ff72d5f535134241e7c797ddc9c7a3573"
100102 other_sha = "39f85c4358b7346fee22169da9cad93901ea9eb9"
101103
102104 # simple index from tree
103- base_index = IndexFile .from_tree (self . rorepo , common_ancestor_sha )
105+ base_index = IndexFile .from_tree (rw_repo , common_ancestor_sha )
104106 assert base_index .entries
105107 self ._cmp_tree_index (common_ancestor_sha , base_index )
106108
107109 # merge two trees - its like a fast-forward
108- two_way_index = IndexFile .from_tree (self . rorepo , common_ancestor_sha , cur_sha )
110+ two_way_index = IndexFile .from_tree (rw_repo , common_ancestor_sha , cur_sha )
109111 assert two_way_index .entries
110112 self ._cmp_tree_index (cur_sha , two_way_index )
111113
112114 # merge three trees - here we have a merge conflict
113- three_way_index = IndexFile .from_tree (self . rorepo , common_ancestor_sha , cur_sha , other_sha )
115+ three_way_index = IndexFile .from_tree (rw_repo , common_ancestor_sha , cur_sha , other_sha )
114116 assert len (list (e for e in three_way_index .entries .values () if e .stage != 0 ))
115117
116118
@@ -476,7 +478,7 @@ def mixed_iterator():
476478 fake_symlink_relapath = "my_fake_symlink"
477479 link_target = "/etc/that"
478480 fake_symlink_path = self ._make_file (fake_symlink_relapath , link_target , rw_repo )
479- fake_entry = BaseIndexEntry ((0120000 , null_hex_sha , 0 , fake_symlink_relapath ))
481+ fake_entry = BaseIndexEntry ((0120000 , null_bin_sha , 0 , fake_symlink_relapath ))
480482 entries = index .reset (new_commit ).add ([fake_entry ], fprogress = self ._fprogress_add )
481483 self ._assert_fprogress (entries )
482484 assert entries [0 ].hexsha != null_hex_sha
@@ -497,6 +499,7 @@ def mixed_iterator():
497499 # a tree created from this should contain the symlink
498500 tree = index .write_tree ()
499501 assert fake_symlink_relapath in tree
502+ index .write () # flush our changes for the checkout
500503
501504 # checkout the fakelink, should be a link then
502505 assert not S_ISLNK (os .stat (fake_symlink_path )[ST_MODE ])
@@ -569,5 +572,19 @@ def make_paths():
569572 for filenum in range (len (paths )):
570573 assert index .entry_key (str (filenum ), 0 ) in index .entries
571574
572- def test_compare_write_tree (self ):
573- self .fail ("compare git-write-tree with python implementation, must have same output" )
575+ @with_rw_repo ('HEAD' )
576+ def test_compare_write_tree (self , rw_repo ):
577+ def write_tree (index ):
578+ tree_sha = index .repo .git .write_tree (missing_ok = True )
579+ return Tree (index .repo , tree_sha , 0 , '' )
580+ # END git cmd write tree
581+
582+ # write all trees and compare them
583+ for commit in rw_repo .head .commit .traverse ():
584+ index = rw_repo .index .reset (commit )
585+ orig_tree = commit .tree
586+ new_git_tree = write_tree (index )
587+ assert new_git_tree == orig_tree
588+ assert index .write_tree () == orig_tree
589+ # END for each commit
590+
0 commit comments