@@ -136,6 +136,57 @@ def test_index_file_from_tree(self):
136136 # END for each blob
137137 assert num_blobs == len (three_way_index .entries )
138138
139+ @with_rw_repo ('0.1.6' )
140+ def test_index_merge_tree (self , rw_repo ):
141+ # SINGLE TREE MERGE
142+ # current index is at the (virtual) cur_commit
143+ next_commit = "4c39f9da792792d4e73fc3a5effde66576ae128c"
144+ parent_commit = rw_repo .head .commit .parents [0 ]
145+ manifest_key = IndexFile .get_entries_key ('MANIFEST.in' , 0 )
146+ manifest_entry = rw_repo .index .entries [manifest_key ]
147+ rw_repo .index .merge_tree (next_commit )
148+ # only one change should be recorded
149+ assert manifest_entry .sha != rw_repo .index .entries [manifest_key ].sha
150+
151+ rw_repo .index .reset (rw_repo .head )
152+ assert rw_repo .index .entries [manifest_key ].sha == manifest_entry .sha
153+
154+ # FAKE MERGE
155+ #############
156+ # Add a change with a NULL sha that should conflict with next_commit. We
157+ # pretend there was a change, but we do not even bother adding a proper
158+ # sha for it ( which makes things faster of course )
159+ manifest_fake_entry = BaseIndexEntry ((manifest_entry [0 ], Diff .null_hex_sha , 0 , manifest_entry [3 ]))
160+ rw_repo .index .add ([manifest_fake_entry ])
161+ # add actually resolves the null-hex-sha for us as a feature, but we can
162+ # edit the index manually
163+ assert rw_repo .index .entries [manifest_key ].sha != Diff .null_hex_sha
164+ # must operate on the same index for this ! Its a bit problematic as
165+ # it might confuse people
166+ index = rw_repo .index
167+ index .entries [manifest_key ] = IndexEntry .from_base (manifest_fake_entry )
168+ index .write ()
169+ assert rw_repo .index .entries [manifest_key ].sha == Diff .null_hex_sha
170+
171+ # a three way merge would result in a conflict and fails as the command will
172+ # not overwrite any entries in our index and hence leave them unmerged. This is
173+ # mainly a protection feature as the current index is not yet in a tree
174+ self .failUnlessRaises (GitCommandError , index .merge_tree , next_commit , base = parent_commit )
175+
176+ # the only way to get the merged entries is to safe the current index away into a tree,
177+ # which is like a temporary commit for us. This fails as well as the NULL sha deos not
178+ # have a corresponding object
179+ self .failUnlessRaises (GitCommandError , index .write_tree )
180+
181+ # if missing objects are okay, this would work though
182+ tree = index .write_tree (missing_ok = True )
183+
184+ # now make a proper three way merge with unmerged entries
185+ unmerged_tree = IndexFile .from_tree (rw_repo , parent_commit , tree , next_commit )
186+ unmerged_blobs = unmerged_tree .unmerged_blobs ()
187+ assert len (unmerged_blobs ) == 1 and unmerged_blobs .keys ()[0 ] == manifest_key [0 ]
188+
189+
139190 @with_rw_repo ('0.1.6' )
140191 def test_index_file_diffing (self , rw_repo ):
141192 # default Index instance points to our index
@@ -397,7 +448,6 @@ def mixed_iterator():
397448 entries = index .reset (new_commit ).add ([link_file ], fprogress = self ._fprogress_add )
398449 self ._assert_fprogress (entries )
399450 assert len (entries ) == 1 and S_ISLNK (entries [0 ].mode )
400- print "%o" % entries [0 ].mode
401451 # END real symlink test
402452
403453 # add fake symlink and assure it checks-our as symlink
0 commit comments