~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Abbreviate pack_stat struct format to '>6L'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
34
34
    urlutils,
35
35
    workingtree,
36
36
    )
 
37
from bzrlib.tests import (
 
38
    scenarios,
 
39
    script,
 
40
    )
 
41
 
 
42
 
 
43
load_tests = scenarios.load_tests_apply_scenarios
37
44
 
38
45
 
39
46
class TestMerge(tests.TestCaseWithTransport):
352
359
        self.assertPathExists('file1')
353
360
        self.assertPathDoesNotExist('file2')
354
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'])
 
372
 
355
373
    def pullable_branch(self):
356
374
        tree_a = self.make_branch_and_tree('a')
357
375
        self.build_tree_contents([('a/file', 'bar\n')])
533
551
 
534
552
    def test_merge_from_submit(self):
535
553
        tree_a = self.make_branch_and_tree('a')
 
554
        tree_a.commit('test')
536
555
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
537
556
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
538
557
        out, err = self.run_bzr(['merge', '-d', 'c'])
543
562
 
544
563
    def test_remember_sets_submit(self):
545
564
        tree_a = self.make_branch_and_tree('a')
 
565
        tree_a.commit('rev1')
546
566
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
547
567
        self.assertIs(tree_b.branch.get_submit_branch(), None)
548
568
 
555
575
        self.assertEqual(tree_b.branch.get_submit_branch(),
556
576
                         tree_a.bzrdir.root_transport.base)
557
577
 
 
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
 
558
595
    def test_weave_cherrypick(self):
559
596
        this_tree = self.make_branch_and_tree('this')
560
597
        self.build_tree_contents([('this/file', "a\n")])
624
661
 
625
662
    def test_merge_interactive_unlocks_branch(self):
626
663
        this = self.make_branch_and_tree('this')
627
 
        other = self.make_branch_and_tree('other')
628
 
        other.commit('empty commit')
 
664
        this.commit('empty commit')
 
665
        other = this.bzrdir.sprout('other').open_workingtree()
 
666
        other.commit('empty commit 2')
629
667
        self.run_bzr('merge -i -d this other')
630
668
        this.lock_write()
631
669
        this.unlock()
632
670
 
633
 
    def test_merge_reversed_revision_range(self):
634
 
        tree = self.make_branch_and_tree(".")
635
 
        for f in ("a", "b"):
636
 
            self.build_tree([f])
637
 
            tree.add(f)
638
 
            tree.commit("added "+f)
639
 
        for context in (".", "", "a"):
640
 
            self.run_bzr("merge -r 1..0 " + context)
641
 
            self.assertPathDoesNotExist("a")
642
 
            tree.revert()
643
 
            self.assertPathExists("a")
644
 
 
645
671
    def test_merge_fetches_tags(self):
646
672
        """Tags are updated by merge, and revisions named in those tags are
647
673
        fetched.
655
681
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
656
682
        source.tags.set_tag('tag-a', 'rev-2a')
657
683
        source.set_last_revision_info(1, 'rev-1')
 
684
        source.get_config().set_user_option('branch.fetch_tags', 'True')
658
685
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
659
686
        # Merge from source
660
687
        self.run_bzr('merge -d target source')
664
691
        target.repository.get_revision('rev-2a')
665
692
 
666
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
""")
 
725
 
667
726
class TestMergeForce(tests.TestCaseWithTransport):
668
727
 
669
728
    def setUp(self):