~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-28 07:08:42 UTC
  • mfrom: (2380 +trunk)
  • mto: (2018.5.146 hpss)
  • mto: This revision was merged to the branch mainline in revision 2414.
  • Revision ID: andrew.bennetts@canonical.com-20070328070842-r843houy668oxb9o
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
159
159
        self.build_tree(['a/b/'])
160
160
        tree_a.add('b', 'b-id')
161
161
        tree_a.commit('added b')
162
 
        base_tree = tree_a.basis_tree()
 
162
        # basis_tree() is only guaranteed to be valid as long as it is actually
 
163
        # the basis tree. This mutates the tree after grabbing basis, so go to
 
164
        # the repository.
 
165
        base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision())
163
166
        tree_z = tree_a.bzrdir.sprout('z').open_workingtree()
164
167
        self.build_tree(['a/b/c'])
165
168
        tree_a.add('b/c')
171
174
            conflicts.MissingParent('Created directory', 'b', 'b-id'),
172
175
            conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
173
176
            tree_z.conflicts())
174
 
        merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree, 
 
177
        merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree,
175
178
                    this_tree=tree_a)
176
179
        self.assertEqual([
177
180
            conflicts.DeletingParent('Not deleting', 'b', 'b-id'),
178
181
            conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
179
182
            tree_a.conflicts())
180
183
 
 
184
    def test_nested_merge(self):
 
185
        tree = self.make_branch_and_tree('tree',
 
186
            format='dirstate-with-subtree')
 
187
        sub_tree = self.make_branch_and_tree('tree/sub-tree',
 
188
            format='dirstate-with-subtree')
 
189
        sub_tree.set_root_id('sub-tree-root')
 
190
        self.build_tree_contents([('tree/sub-tree/file', 'text1')])
 
191
        sub_tree.add('file')
 
192
        sub_tree.commit('foo')
 
193
        tree.add_reference(sub_tree)
 
194
        tree.commit('set text to 1')
 
195
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
196
        # modify the file in the subtree
 
197
        self.build_tree_contents([('tree2/sub-tree/file', 'text2')])
 
198
        # and merge the changes from the diverged subtree into the containing
 
199
        # tree
 
200
        tree2.commit('changed file text')
 
201
        tree.merge_from_branch(tree2.branch)
 
202
        self.assertFileEqual('text2', 'tree/sub-tree/file')
 
203
 
181
204
    def test_merge_with_missing(self):
182
205
        tree_a = self.make_branch_and_tree('tree_a')
183
206
        self.build_tree_contents([('tree_a/file', 'content_1')])
184
207
        tree_a.add('file')
185
208
        tree_a.commit('commit base')
186
 
        base_tree = tree_a.basis_tree()
 
209
        # basis_tree() is only guaranteed to be valid as long as it is actually
 
210
        # the basis tree. This mutates the tree after grabbing basis, so go to
 
211
        # the repository.
 
212
        base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision())
187
213
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
188
214
        self.build_tree_contents([('tree_a/file', 'content_2')])
189
215
        tree_a.commit('commit other')