~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-04 18:51:39 UTC
  • mfrom: (2961.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071104185139-kaio3sneodg2kp71
Authentication ring implementation (read-only)

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
        a_tree.revert(backups=False)
71
71
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
72
72
        a_tree.revert(backups=False)
73
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
74
 
        a_tree.revert(backups=False)
75
73
        self.run_bzr_error(['Show-base is not supported for this merge type'],
76
74
                           'merge ../b -r last:1..last:1 --merge-type weave'
77
75
                           ' --show-base')
138
136
        self.failUnlessExists('sub/a.txt.BASE')
139
137
 
140
138
    def test_merge_remember(self):
141
 
        """Merge changes from one branch to another, test submit location."""
 
139
        """Merge changes from one branch to another and test parent location."""
142
140
        tree_a = self.make_branch_and_tree('branch_a')
143
141
        branch_a = tree_a.branch
144
142
        self.build_tree(['branch_a/a'])
168
166
        tree_b.add('d')
169
167
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
170
168
                           'merge ../branch_a')
171
 
        self.assertEquals(abspath(branch_b.get_submit_branch()),
172
 
                          abspath(parent))
 
169
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
173
170
        # test implicit --remember after resolving conflict
174
171
        tree_b.commit('commit d')
175
172
        out, err = self.run_bzr('merge')
176
173
        
177
174
        base = urlutils.local_path_from_url(branch_a.base)
178
 
        self.assertStartsWith(err,
179
 
                          'Merging from remembered submit location %s\n' % (base,))
180
 
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
181
 
        self.assertEquals(abspath(branch_b.get_submit_branch()),
182
 
                          abspath(parent))
 
175
        self.assertEquals(out, 'Merging from remembered location %s\n' % (base,))
 
176
        self.assertEquals(err, '+N  b\nAll changes applied successfully.\n')
 
177
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
183
178
        # re-open tree as external run_bzr modified it
184
179
        tree_b = branch_b.bzrdir.open_workingtree()
185
180
        tree_b.commit('merge branch_a')
187
182
        out, err = self.run_bzr('merge ../branch_c --remember')
188
183
        self.assertEquals(out, '')
189
184
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
190
 
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
185
        self.assertEquals(abspath(branch_b.get_parent()),
191
186
                          abspath(branch_c.bzrdir.root_transport.base))
192
187
        # re-open tree as external run_bzr modified it
193
188
        tree_b = branch_b.bzrdir.open_workingtree()
243
238
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
244
239
                           'merge /a --uncommitted -r1 -d b')
245
240
 
246
 
    def test_merge_uncommitted_file(self):
247
 
        """It should be possible to merge changes from a single file."""
248
 
        tree_a = self.make_branch_and_tree('tree_a')
249
 
        tree_a.commit('initial commit')
250
 
        tree_a.bzrdir.sprout('tree_b')
251
 
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
252
 
        tree_a.add(['file1', 'file2'])
253
 
        os.chdir('tree_b')
254
 
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
255
 
        self.failUnlessExists('file1')
256
 
        self.failIfExists('file2')
257
 
 
258
241
    def pullable_branch(self):
259
242
        tree_a = self.make_branch_and_tree('a')
260
243
        self.build_tree(['a/file'])
306
289
        target.commit('empty commit')
307
290
        self.write_directive('directive', source.branch, 'target', 'rev2',
308
291
                             'rev1')
309
 
        out, err = self.run_bzr('merge -d target directive')
 
292
        self.run_bzr('merge -d target directive')
310
293
        self.failIfExists('target/a')
311
294
        self.failUnlessExists('target/b')
312
 
        self.assertContainsRe(err, 'Performing cherrypick')
313
295
 
314
296
    def write_directive(self, filename, source, target, revision_id,
315
297
                        base_revision_id=None, mangle_patch=False):
398
380
        # pick 1 revision with option --changes
399
381
        self.run_bzr('merge -d target -c revid:rev_d source')
400
382
        self.assertDirectoryContent('target', ['.bzr', 'a', 'd'])
401
 
 
402
 
    def test_merge_criss_cross(self):
403
 
        tree_a = self.make_branch_and_tree('a')
404
 
        tree_a.commit('', rev_id='rev1')
405
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
406
 
        tree_a.commit('', rev_id='rev2a')
407
 
        tree_b.commit('', rev_id='rev2b')
408
 
        tree_a.merge_from_branch(tree_b.branch)
409
 
        tree_b.merge_from_branch(tree_a.branch)
410
 
        tree_a.commit('', rev_id='rev3a')
411
 
        tree_b.commit('', rev_id='rev3b')
412
 
        graph = tree_a.branch.repository.get_graph(tree_b.branch.repository)
413
 
        out, err = self.run_bzr(['merge', '-d', 'a', 'b'])
414
 
        self.assertContainsRe(err, 'Warning: criss-cross merge encountered.')
415
 
 
416
 
    def test_merge_from_submit(self):
417
 
        tree_a = self.make_branch_and_tree('a')
418
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
419
 
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
420
 
        out, err = self.run_bzr(['merge', '-d', 'c'])
421
 
        self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
422
 
        tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
423
 
        out, err = self.run_bzr(['merge', '-d', 'c'])
424
 
        self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
425
 
 
426
 
    def test_remember_sets_submit(self):
427
 
        tree_a = self.make_branch_and_tree('a')
428
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
429
 
        self.assertIs(tree_b.branch.get_submit_branch(), None)
430
 
 
431
 
        # Remember should not happen if using default from parent
432
 
        out, err = self.run_bzr(['merge', '-d', 'b'])
433
 
        self.assertIs(tree_b.branch.get_submit_branch(), None)
434
 
 
435
 
        # Remember should happen if user supplies location
436
 
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
437
 
        self.assertEqual(tree_b.branch.get_submit_branch(),
438
 
                         tree_a.bzrdir.root_transport.base)
439
 
 
440
 
    def test_weave_cherrypick(self):
441
 
        this_tree = self.make_branch_and_tree('this')
442
 
        self.build_tree_contents([('this/file', "a\n")])
443
 
        this_tree.add('file')
444
 
        this_tree.commit('rev1')
445
 
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
446
 
        self.build_tree_contents([('other/file', "a\nb\n")])
447
 
        other_tree.commit('rev2b')
448
 
        self.build_tree_contents([('other/file', "c\na\nb\n")])
449
 
        other_tree.commit('rev3b')
450
 
        self.run_bzr('merge --weave -d this other -r -2..-1')
451
 
        self.assertFileEqual('c\na\n', 'this/file')
452
 
 
453
 
    def test_lca_merge_criss_cross(self):
454
 
        tree_a = self.make_branch_and_tree('a')
455
 
        self.build_tree_contents([('a/file', 'base-contents\n')])
456
 
        tree_a.add('file')
457
 
        tree_a.commit('', rev_id='rev1')
458
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
459
 
        self.build_tree_contents([('a/file',
460
 
                                   'base-contents\nthis-contents\n')])
461
 
        tree_a.commit('', rev_id='rev2a')
462
 
        self.build_tree_contents([('b/file',
463
 
                                   'base-contents\nother-contents\n')])
464
 
        tree_b.commit('', rev_id='rev2b')
465
 
        tree_a.merge_from_branch(tree_b.branch)
466
 
        self.build_tree_contents([('a/file',
467
 
                                   'base-contents\nthis-contents\n')])
468
 
        tree_a.set_conflicts(ConflictList())
469
 
        tree_b.merge_from_branch(tree_a.branch)
470
 
        self.build_tree_contents([('b/file',
471
 
                                   'base-contents\nother-contents\n')])
472
 
        tree_b.set_conflicts(ConflictList())
473
 
        tree_a.commit('', rev_id='rev3a')
474
 
        tree_b.commit('', rev_id='rev3b')
475
 
        out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
476
 
        self.assertFileEqual('base-contents\n<<<<<<< TREE\nthis-contents\n'
477
 
                             '=======\nother-contents\n>>>>>>> MERGE-SOURCE\n',
478
 
                             'a/file')
479
 
 
480
 
    def test_merge_preview(self):
481
 
        this_tree = self.make_branch_and_tree('this')
482
 
        this_tree.commit('rev1')
483
 
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
484
 
        self.build_tree_contents([('other/file', 'new line')])
485
 
        other_tree.add('file')
486
 
        other_tree.commit('rev2a')
487
 
        this_tree.commit('rev2b')
488
 
        out, err = self.run_bzr(['merge', '-d', 'this', 'other', '--preview'])
489
 
        self.assertContainsRe(out, '\+new line')
490
 
        self.assertNotContainsRe(err, '\+N  file\n')
491
 
        this_tree.lock_read()
492
 
        self.addCleanup(this_tree.unlock)
493
 
        self.assertEqual([],
494
 
                         list(this_tree.iter_changes(this_tree.basis_tree())))