~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2009-11-25 07:27:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4825.
  • Revision ID: andrew.bennetts@canonical.com-20091125072743-v6sv4m2mkt9iyslp
Terminate SSHSubprocesses when no refs to them are left, in case .close is never called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 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
19
19
"""Black-box tests for bzr merge.
20
20
"""
21
21
 
22
 
import doctest
23
22
import os
24
23
 
25
 
from testtools import matchers
26
 
 
27
24
from bzrlib import (
28
25
    branch,
29
26
    bzrdir,
30
27
    conflicts,
 
28
    errors,
31
29
    merge_directive,
32
30
    osutils,
33
31
    tests,
34
32
    urlutils,
35
33
    workingtree,
36
34
    )
37
 
from bzrlib.tests import (
38
 
    scenarios,
39
 
    script,
40
 
    )
41
 
 
42
 
 
43
 
load_tests = scenarios.load_tests_apply_scenarios
44
35
 
45
36
 
46
37
class TestMerge(tests.TestCaseWithTransport):
111
102
        # Merging a branch pulls its revision into the tree
112
103
        b = branch.Branch.open('../b')
113
104
        b_tip = b.last_revision()
114
 
        self.assertTrue(a.branch.repository.has_revision(b_tip))
 
105
        self.failUnless(a.branch.repository.has_revision(b_tip))
115
106
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
116
107
        a_tree.revert(backups=False)
117
108
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
213
204
        b_tree.commit(message='Modified a.txt')
214
205
        os.chdir('b')
215
206
        self.run_bzr('merge ../a/', retcode=1)
216
 
        self.assertPathExists('sub/a.txt.THIS')
217
 
        self.assertPathExists('sub/a.txt.BASE')
 
207
        self.failUnlessExists('sub/a.txt.THIS')
 
208
        self.failUnlessExists('sub/a.txt.BASE')
218
209
        os.chdir('../a')
219
210
        self.run_bzr('merge ../b/', retcode=1)
220
 
        self.assertPathExists('sub/a.txt.OTHER')
221
 
        self.assertPathExists('sub/a.txt.BASE')
222
 
 
223
 
    def test_conflict_leaves_base_this_other_files(self):
224
 
        tree, other = self.create_conflicting_branches()
225
 
        self.run_bzr('merge ../other', working_dir='tree',
226
 
                     retcode=1)
227
 
        self.assertFileEqual('a\nb\nc\n', 'tree/fname.BASE')
228
 
        self.assertFileEqual('a\nB\nD\n', 'tree/fname.OTHER')
229
 
        self.assertFileEqual('a\nB\nC\n', 'tree/fname.THIS')
230
 
 
231
 
    def test_weave_conflict_leaves_base_this_other_files(self):
232
 
        tree, other = self.create_conflicting_branches()
233
 
        self.run_bzr('merge ../other --weave', working_dir='tree',
234
 
                     retcode=1)
235
 
        self.assertFileEqual('a\nb\nc\n', 'tree/fname.BASE')
236
 
        self.assertFileEqual('a\nB\nD\n', 'tree/fname.OTHER')
237
 
        self.assertFileEqual('a\nB\nC\n', 'tree/fname.THIS')
 
211
        self.failUnlessExists('sub/a.txt.OTHER')
 
212
        self.failUnlessExists('sub/a.txt.BASE')
238
213
 
239
214
    def test_merge_remember(self):
240
215
        """Merge changes from one branch to another, test submit location."""
335
310
        tree_a.add(['file_1', 'file_2'])
336
311
        tree_a.commit('commit 1')
337
312
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
338
 
        self.assertPathExists('b/file_1')
 
313
        self.failUnlessExists('b/file_1')
339
314
        tree_a.rename_one('file_1', 'file_i')
340
315
        tree_a.commit('commit 2')
341
316
        tree_a.rename_one('file_2', 'file_ii')
342
317
        ## os.chdir('b')
343
318
        self.run_bzr('merge a --uncommitted -d b')
344
 
        self.assertPathExists('b/file_1')
345
 
        self.assertPathExists('b/file_ii')
 
319
        self.failUnlessExists('b/file_1')
 
320
        self.failUnlessExists('b/file_ii')
346
321
        tree_b.revert()
347
322
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
348
323
                           'merge /a --uncommitted -r1 -d b')
356
331
        tree_a.add(['file1', 'file2'])
357
332
        os.chdir('tree_b')
358
333
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
359
 
        self.assertPathExists('file1')
360
 
        self.assertPathDoesNotExist('file2')
361
 
 
362
 
    def test_merge_nonexistent_file(self):
363
 
        """It should not be possible to merge changes from a file which
364
 
        does not exist."""
365
 
        tree_a = self.make_branch_and_tree('tree_a')
366
 
        self.build_tree_contents([('tree_a/file', 'bar\n')])
367
 
        tree_a.add(['file'])
368
 
        tree_a.commit('commit 1')
369
 
        os.chdir('tree_a')
370
 
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
371
 
                           ['merge', 'non/existing'])
 
334
        self.failUnlessExists('file1')
 
335
        self.failIfExists('file2')
372
336
 
373
337
    def pullable_branch(self):
374
338
        tree_a = self.make_branch_and_tree('a')
375
 
        self.build_tree_contents([('a/file', 'bar\n')])
 
339
        self.build_tree(['a/file'])
376
340
        tree_a.add(['file'])
377
341
        self.id1 = tree_a.commit('commit 1')
378
342
 
379
343
        tree_b = self.make_branch_and_tree('b')
380
344
        tree_b.pull(tree_a.branch)
381
 
        self.build_tree_contents([('b/file', 'foo\n')])
 
345
        file('b/file', 'wb').write('foo')
382
346
        self.id2 = tree_b.commit('commit 2')
383
347
 
384
348
    def test_merge_pull(self):
389
353
        tree_a = workingtree.WorkingTree.open('.')
390
354
        self.assertEqual([self.id2], tree_a.get_parent_ids())
391
355
 
392
 
    def test_merge_pull_preview(self):
393
 
        self.pullable_branch()
394
 
        (out, err) = self.run_bzr('merge --pull --preview -d a b')
395
 
        self.assertThat(out, matchers.DocTestMatches(
396
 
"""=== modified file 'file'
397
 
--- file\t...
398
 
+++ file\t...
399
 
@@ -1,1 +1,1 @@
400
 
-bar
401
 
+foo
402
 
 
403
 
""", doctest.ELLIPSIS | doctest.REPORT_UDIFF))
404
 
        tree_a = workingtree.WorkingTree.open('a')
405
 
        self.assertEqual([self.id1], tree_a.get_parent_ids())
406
 
 
407
356
    def test_merge_kind_change(self):
408
357
        tree_a = self.make_branch_and_tree('tree_a')
409
358
        self.build_tree_contents([('tree_a/file', 'content_1')])
428
377
    def test_directive_cherrypick(self):
429
378
        source = self.make_branch_and_tree('source')
430
379
        source.commit("nothing")
431
 
        # see https://bugs.launchpad.net/bzr/+bug/409688 - trying to
 
380
        # see https://bugs.edge.launchpad.net/bzr/+bug/409688 - trying to
432
381
        # cherrypick from one branch into another unrelated branch with a
433
382
        # different root id will give shape conflicts.  as a workaround we
434
383
        # make sure they share the same root id.
443
392
        self.write_directive('directive', source.branch, 'target', 'rev2',
444
393
                             'rev1')
445
394
        out, err = self.run_bzr('merge -d target directive')
446
 
        self.assertPathDoesNotExist('target/a')
447
 
        self.assertPathExists('target/b')
 
395
        self.failIfExists('target/a')
 
396
        self.failUnlessExists('target/b')
448
397
        self.assertContainsRe(err, 'Performing cherrypick')
449
398
 
450
399
    def write_directive(self, filename, source, target, revision_id,
485
434
        branch_b.add('file2')
486
435
        branch_b.commit('added file2', rev_id='rev2b')
487
436
        branch_b.merge_from_branch(branch_a.branch)
488
 
        self.assertPathExists('branch_b/file1')
 
437
        self.failUnlessExists('branch_b/file1')
489
438
        branch_b.commit('merged branch_a', rev_id='rev3b')
490
439
 
491
440
        # It works if the revid has an interger revno
492
441
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
493
 
        self.assertPathExists('target/file1')
494
 
        self.assertPathDoesNotExist('target/file2')
 
442
        self.failUnlessExists('target/file1')
 
443
        self.failIfExists('target/file2')
495
444
        target.revert()
496
445
 
497
446
        # It should work if the revid has no integer revno
498
447
        self.run_bzr('merge -d target -r revid:rev2a branch_b')
499
 
        self.assertPathExists('target/file1')
500
 
        self.assertPathDoesNotExist('target/file2')
 
448
        self.failUnlessExists('target/file1')
 
449
        self.failIfExists('target/file2')
501
450
 
502
451
    def assertDirectoryContent(self, directory, entries, message=''):
503
452
        """Assert whether entries (file or directories) exist in a directory.
551
500
 
552
501
    def test_merge_from_submit(self):
553
502
        tree_a = self.make_branch_and_tree('a')
554
 
        tree_a.commit('test')
555
503
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
556
504
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
557
505
        out, err = self.run_bzr(['merge', '-d', 'c'])
562
510
 
563
511
    def test_remember_sets_submit(self):
564
512
        tree_a = self.make_branch_and_tree('a')
565
 
        tree_a.commit('rev1')
566
513
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
567
514
        self.assertIs(tree_b.branch.get_submit_branch(), None)
568
515
 
575
522
        self.assertEqual(tree_b.branch.get_submit_branch(),
576
523
                         tree_a.bzrdir.root_transport.base)
577
524
 
578
 
    def test_no_remember_dont_set_submit(self):
579
 
        tree_a = self.make_branch_and_tree('a')
580
 
        self.build_tree_contents([('a/file', "a\n")])
581
 
        tree_a.add('file')
582
 
        tree_a.commit('rev1')
583
 
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
584
 
        self.assertIs(tree_b.branch.get_submit_branch(), None)
585
 
 
586
 
        # Remember should not happen if using default from parent
587
 
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
588
 
        self.assertEquals(None, tree_b.branch.get_submit_branch())
589
 
 
590
 
        # Remember should not happen if user supplies location but ask for not
591
 
        # remembering it
592
 
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember', 'a'])
593
 
        self.assertEqual(None, tree_b.branch.get_submit_branch())
594
 
 
595
525
    def test_weave_cherrypick(self):
596
526
        this_tree = self.make_branch_and_tree('this')
597
527
        self.build_tree_contents([('this/file', "a\n")])
657
587
        other.add('other_file')
658
588
        other.commit('rev1b')
659
589
        self.run_bzr('merge -d this other -r0..')
660
 
        self.assertPathExists('this/other_file')
661
 
 
662
 
    def test_merge_interactive_unlocks_branch(self):
663
 
        this = self.make_branch_and_tree('this')
664
 
        this.commit('empty commit')
665
 
        other = this.bzrdir.sprout('other').open_workingtree()
666
 
        other.commit('empty commit 2')
667
 
        self.run_bzr('merge -i -d this other')
668
 
        this.lock_write()
669
 
        this.unlock()
670
 
 
671
 
    def test_merge_fetches_tags(self):
672
 
        """Tags are updated by merge, and revisions named in those tags are
673
 
        fetched.
674
 
        """
675
 
        # Make a source, sprout a target off it
676
 
        builder = self.make_branch_builder('source')
677
 
        builder.build_commit(message="Rev 1", rev_id='rev-1')
678
 
        source = builder.get_branch()
679
 
        target_bzrdir = source.bzrdir.sprout('target')
680
 
        # Add a non-ancestry tag to source
681
 
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
682
 
        source.tags.set_tag('tag-a', 'rev-2a')
683
 
        source.set_last_revision_info(1, 'rev-1')
684
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
685
 
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
686
 
        # Merge from source
687
 
        self.run_bzr('merge -d target source')
688
 
        target = target_bzrdir.open_branch()
689
 
        # The tag is present, and so is its revision.
690
 
        self.assertEqual('rev-2a', target.tags.lookup_tag('tag-a'))
691
 
        target.repository.get_revision('rev-2a')
692
 
 
693
 
 
694
 
class TestMergeRevisionRange(tests.TestCaseWithTransport):
695
 
 
696
 
    scenarios = (('whole-tree', dict(context='.')),
697
 
                 ('file-only', dict(context='a')))
698
 
 
699
 
    def setUp(self):
700
 
        super(TestMergeRevisionRange, self).setUp()
701
 
        self.tree = self.make_branch_and_tree(".")
702
 
        self.tree.commit('initial commit')
703
 
        for f in ("a", "b"):
704
 
            self.build_tree([f])
705
 
            self.tree.add(f)
706
 
            self.tree.commit("added " + f)
707
 
 
708
 
    def test_merge_reversed_revision_range(self):
709
 
        self.run_bzr("merge -r 2..1 " + self.context)
710
 
        self.assertPathDoesNotExist("a")
711
 
        self.assertPathExists("b")
712
 
 
713
 
 
714
 
class TestMergeScript(script.TestCaseWithTransportAndScript):
715
 
    def test_merge_empty_branch(self):
716
 
        source = self.make_branch_and_tree('source')
717
 
        self.build_tree(['source/a'])
718
 
        source.add('a')
719
 
        source.commit('Added a', rev_id='rev1')
720
 
        target = self.make_branch_and_tree('target')
721
 
        self.run_script("""\
722
 
$ bzr merge -d target source
723
 
2>bzr: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
724
 
""")
 
590
        self.failUnlessExists('this/other_file')
 
591
 
725
592
 
726
593
class TestMergeForce(tests.TestCaseWithTransport):
727
594