~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_pull.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for branch.pull behaviour."""
18
18
 
19
 
import os
20
 
 
21
19
from bzrlib import (
22
20
    branch,
23
 
    bzrdir,
 
21
    controldir,
24
22
    errors,
25
23
    memorytree,
26
24
    revision,
27
25
    )
28
 
from bzrlib.tests import per_branch
 
26
from bzrlib.tests import (
 
27
    fixtures,
 
28
    per_branch,
 
29
    TestNotApplicable,
 
30
    )
29
31
 
30
32
 
31
33
class TestPull(per_branch.TestCaseWithBranch):
40
42
        parent.merge_from_branch(mine.branch)
41
43
        parent.commit('merge my change', rev_id='P2')
42
44
        mine.pull(parent.branch)
43
 
        self.assertEqual(['P1', 'P2'], mine.branch.revision_history())
 
45
        self.assertEqual('P2', mine.branch.last_revision())
44
46
 
45
47
    def test_pull_merged_indirect(self):
46
48
        # it should be possible to do a pull from one branch into another
57
59
        parent.merge_from_branch(other.branch)
58
60
        parent.commit('merge other', rev_id='P2')
59
61
        mine.pull(parent.branch)
60
 
        self.assertEqual(['P1', 'P2'], mine.branch.revision_history())
 
62
        self.assertEqual('P2', mine.branch.last_revision())
61
63
 
62
64
    def test_pull_updates_checkout_and_master(self):
63
65
        """Pulling into a checkout updates the checkout and the master branch"""
69
71
        rev2 = other.commit('other commit')
70
72
        # now pull, which should update both checkout and master.
71
73
        checkout.branch.pull(other.branch)
72
 
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
73
 
        self.assertEqual([rev1, rev2], master_tree.branch.revision_history())
 
74
        self.assertEqual(rev2, checkout.branch.last_revision())
 
75
        self.assertEqual(rev2, master_tree.branch.last_revision())
74
76
 
75
77
    def test_pull_local_updates_checkout_only(self):
76
78
        """Pulling --local into a checkout updates the checkout and not the
83
85
        rev2 = other.commit('other commit')
84
86
        # now pull local, which should update checkout but not master.
85
87
        checkout.branch.pull(other.branch, local = True)
86
 
        self.assertEqual([rev1, rev2], checkout.branch.revision_history())
87
 
        self.assertEqual([rev1], master_tree.branch.revision_history())
 
88
        self.assertEqual(rev2, checkout.branch.last_revision())
 
89
        self.assertEqual(rev1, master_tree.branch.last_revision())
88
90
 
89
91
    def test_pull_local_raises_LocalRequiresBoundBranch_on_unbound(self):
90
92
        """Pulling --local into a branch that is not bound should fail."""
96
98
        # now pull --local, which should raise LocalRequiresBoundBranch error.
97
99
        self.assertRaises(errors.LocalRequiresBoundBranch,
98
100
                          master_tree.branch.pull, other.branch, local = True)
99
 
        self.assertEqual([rev1], master_tree.branch.revision_history())
 
101
        self.assertEqual(rev1, master_tree.branch.last_revision())
100
102
 
101
103
    def test_pull_returns_result(self):
102
104
        parent = self.make_branch_and_tree('parent')
113
115
        self.assertEqual('P1', result.old_revid)
114
116
        self.assertEqual(2, result.new_revno)
115
117
        self.assertEqual('M1', result.new_revid)
116
 
        self.assertEqual(None, result.tag_conflicts)
 
118
        self.assertEqual([], result.tag_conflicts)
117
119
 
118
120
    def test_pull_overwrite(self):
119
121
        tree_a = self.make_branch_and_tree('tree_a')
126
128
                          tree_a.branch.pull, tree_b.branch,
127
129
                          overwrite=False, stop_revision='rev2b')
128
130
        # It should not have updated the branch tip, but it should have fetched
129
 
        # the revision
 
131
        # the revision if the repository supports "invisible" revisions
130
132
        self.assertEqual('rev2a', tree_a.branch.last_revision())
131
 
        self.assertTrue(tree_a.branch.repository.has_revision('rev2b'))
 
133
        if tree_a.branch.repository._format.supports_unreferenced_revisions:
 
134
            self.assertTrue(tree_a.branch.repository.has_revision('rev2b'))
132
135
        tree_a.branch.pull(tree_b.branch, overwrite=True,
133
136
                           stop_revision='rev2b')
134
137
        self.assertEqual('rev2b', tree_a.branch.last_revision())
135
 
        self.assertEqual(tree_b.branch.revision_history(),
136
 
                         tree_a.branch.revision_history())
 
138
        self.assertEqual(tree_b.branch.last_revision(),
 
139
                         tree_a.branch.last_revision())
 
140
 
 
141
    def test_pull_merges_and_fetches_tags(self):
 
142
        """Tags are updated by br.pull(source), and revisions named in those
 
143
        tags are fetched.
 
144
        """
 
145
        # Make a source, sprout a target off it
 
146
        try:
 
147
            builder = self.make_branch_builder('source')
 
148
        except errors.UninitializableFormat:
 
149
            raise TestNotApplicable('uninitializeable format')
 
150
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
151
        target = source.bzrdir.sprout('target').open_branch()
 
152
        # Add a tag to the source, then pull from source
 
153
        try:
 
154
            source.tags.set_tag('tag-a', 'rev-2')
 
155
        except errors.TagsNotSupported:
 
156
            raise TestNotApplicable('format does not support tags.')
 
157
        source.tags.set_tag('tag-a', 'rev-2')
 
158
        source.get_config_stack().set('branch.fetch_tags', True)
 
159
        target.pull(source)
 
160
        # The tag is present, and so is its revision.
 
161
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
 
162
        target.repository.get_revision('rev-2')
 
163
 
 
164
    def test_pull_stop_revision_merges_and_fetches_tags(self):
 
165
        """br.pull(source, stop_revision=REV) updates and fetches tags."""
 
166
        # Make a source, sprout a target off it
 
167
        try:
 
168
            builder = self.make_branch_builder('source')
 
169
        except errors.UninitializableFormat:
 
170
            raise TestNotApplicable('uninitializeable format')
 
171
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
172
        target = source.bzrdir.sprout('target').open_branch()
 
173
        # Add a new commit to the ancestry
 
174
        builder.build_commit(message="Rev 2 again", rev_id='rev-2-again')
 
175
        # Add a tag to the source, then pull rev-2-again from source
 
176
        try:
 
177
            source.tags.set_tag('tag-a', 'rev-2')
 
178
        except errors.TagsNotSupported:
 
179
            raise TestNotApplicable('format does not support tags.')
 
180
        source.get_config_stack().set('branch.fetch_tags', True)
 
181
        target.pull(source, 'rev-2-again')
 
182
        # The tag is present, and so is its revision.
 
183
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
 
184
        target.repository.get_revision('rev-2')
137
185
 
138
186
 
139
187
class TestPullHook(per_branch.TestCaseWithBranch):
190
238
            # remotebranches can't be bound.  Let's instead make a new local
191
239
            # branch of the default type, which does allow binding.
192
240
            # See https://bugs.launchpad.net/bzr/+bug/112020
193
 
            local = bzrdir.BzrDir.create_branch_convenience('local2')
 
241
            local = controldir.ControlDir.create_branch_convenience('local2')
194
242
            local.bind(target)
195
243
        source = self.make_branch('source')
196
244
        branch.Branch.hooks.install_named_hook(