6
6
7
7
from test .testlib import *
8
8
from git import *
9
+ from git .index .util import TemporaryFileSwap
9
10
import inspect
10
11
import os
11
12
import sys
@@ -94,23 +95,24 @@ def _cmp_tree_index(self, tree, index):
94
95
raise AssertionError ( "CMP Failed: Missing entries in index: %s, missing in tree: %s" % (bset - iset , iset - bset ) )
95
96
# END assertion message
96
97
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 ):
98
100
common_ancestor_sha = "5117c9c8a4d3af19a9958677e45cda9269de1541"
99
101
cur_sha = "4b43ca7ff72d5f535134241e7c797ddc9c7a3573"
100
102
other_sha = "39f85c4358b7346fee22169da9cad93901ea9eb9"
101
103
102
104
# 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 )
104
106
assert base_index .entries
105
107
self ._cmp_tree_index (common_ancestor_sha , base_index )
106
108
107
109
# 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 )
109
111
assert two_way_index .entries
110
112
self ._cmp_tree_index (cur_sha , two_way_index )
111
113
112
114
# 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 )
114
116
assert len (list (e for e in three_way_index .entries .values () if e .stage != 0 ))
115
117
116
118
@@ -476,7 +478,7 @@ def mixed_iterator():
476
478
fake_symlink_relapath = "my_fake_symlink"
477
479
link_target = "/etc/that"
478
480
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 ))
480
482
entries = index .reset (new_commit ).add ([fake_entry ], fprogress = self ._fprogress_add )
481
483
self ._assert_fprogress (entries )
482
484
assert entries [0 ].hexsha != null_hex_sha
@@ -497,6 +499,7 @@ def mixed_iterator():
497
499
# a tree created from this should contain the symlink
498
500
tree = index .write_tree ()
499
501
assert fake_symlink_relapath in tree
502
+ index .write () # flush our changes for the checkout
500
503
501
504
# checkout the fakelink, should be a link then
502
505
assert not S_ISLNK (os .stat (fake_symlink_path )[ST_MODE ])
@@ -569,5 +572,19 @@ def make_paths():
569
572
for filenum in range (len (paths )):
570
573
assert index .entry_key (str (filenum ), 0 ) in index .entries
571
574
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