/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_switch.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from breezy import (
23
23
    branch,
24
24
    errors,
25
 
    lock,
26
25
    merge as _mod_merge,
27
26
    switch,
28
27
    tests,
60
59
            tree.remove('file-1')
61
60
            tree.commit('rev2')
62
61
        checkout = tree.branch.create_checkout('checkout',
63
 
            lightweight=self.lightweight)
 
62
                                               lightweight=self.lightweight)
64
63
        self.build_tree(['checkout/file-3'])
65
64
        checkout.add('file-3')
66
65
        return checkout, to_branch
112
111
        """Test switch after the branch is moved."""
113
112
        tree = self._setup_tree()
114
113
        checkout = tree.branch.create_checkout('checkout',
115
 
            lightweight=self.lightweight)
 
114
                                               lightweight=self.lightweight)
116
115
        self.build_tree(['branch-1/file-2'])
117
116
        tree.add('file-2')
118
117
        tree.remove('file-1')
119
118
        tree.commit('rev2')
120
119
        self.build_tree(['checkout/file-3'])
121
120
        checkout.add('file-3')
122
 
        checkout_dir = checkout.controldir
123
121
        # rename the branch on disk, the checkout object is now invalid.
124
122
        os.rename('branch-1', 'branch-2')
125
123
        to_branch = branch.Branch.open('branch-2')
129
127
            switch.switch, checkout.controldir, to_branch)
130
128
        if isinstance(err, errors.BzrCommandError):
131
129
            self.assertContainsRe(str(err),
132
 
                'Unable to connect to current master branch .*'
133
 
                'To switch anyway, use --force.')
 
130
                                  'Unable to connect to current master branch .*'
 
131
                                  'To switch anyway, use --force.')
134
132
        switch.switch(checkout.controldir, to_branch, force=True)
135
133
        self.assertPathDoesNotExist('checkout/file-1')
136
134
        self.assertPathExists('checkout/file-2')
142
140
        tree = self._setup_tree()
143
141
        tree2 = tree.controldir.sprout('branch-2').open_workingtree()
144
142
        checkout = tree.branch.create_checkout('checkout',
145
 
            lightweight=self.lightweight)
 
143
                                               lightweight=self.lightweight)
146
144
        # Change tree2 and merge it into the checkout without committing
147
145
        self.build_tree(['branch-2/file-2'])
148
146
        tree2.add('file-2')
150
148
        checkout.merge_from_branch(tree2.branch)
151
149
        # Check the error reporting is as expected
152
150
        err = self.assertRaises(errors.BzrCommandError,
153
 
            switch.switch, checkout.controldir, tree2.branch)
 
151
                                switch.switch, checkout.controldir, tree2.branch)
154
152
        self.assertContainsRe(str(err),
155
 
            "Pending merges must be committed or reverted before using switch")
 
153
                              "Pending merges must be committed or reverted before using switch")
156
154
 
157
155
    def test_switch_with_revision(self):
158
156
        """Test switch when a revision is given."""
160
158
        tree = self.make_branch_and_tree('branch-1')
161
159
        self.build_tree(['branch-1/file-1'])
162
160
        tree.add('file-1')
163
 
        tree.commit(rev_id='rev1', message='rev1')
 
161
        tree.commit(rev_id=b'rev1', message='rev1')
164
162
        self.build_tree(['branch-1/file-2'])
165
163
        tree.add('file-2')
166
 
        tree.commit(rev_id='rev2', message='rev2')
 
164
        tree.commit(rev_id=b'rev2', message='rev2')
167
165
        # Check it out and switch to revision 1
168
166
        checkout = tree.branch.create_checkout('checkout',
169
 
            lightweight=self.lightweight)
170
 
        switch.switch(checkout.controldir, tree.branch, revision_id="rev1")
 
167
                                               lightweight=self.lightweight)
 
168
        switch.switch(checkout.controldir, tree.branch, revision_id=b"rev1")
171
169
        self.assertPathExists('checkout/file-1')
172
170
        self.assertPathDoesNotExist('checkout/file-2')
173
171
 
174
172
    def test_switch_changing_root_id(self):
175
173
        tree = self._setup_tree()
176
174
        tree2 = self.make_branch_and_tree('tree-2')
177
 
        tree2.set_root_id('custom-root-id')
 
175
        tree2.set_root_id(b'custom-root-id')
178
176
        self.build_tree(['tree-2/file-2'])
179
177
        tree2.add(['file-2'])
180
178
        tree2.commit('rev1b')
181
179
        checkout = tree.branch.create_checkout('checkout',
182
 
            lightweight=self.lightweight)
 
180
                                               lightweight=self.lightweight)
183
181
        switch.switch(checkout.controldir, tree2.branch)
184
 
        self.assertEqual('custom-root-id', tree2.get_root_id())
 
182
        self.assertEqual(b'custom-root-id', tree2.path2id(''))
185
183
 
186
184
    def test_switch_configurable_file_merger(self):
187
185
        class DummyMerger(_mod_merge.ConfigurableFileMerger):
192
190
            'test factory')
193
191
        foo = self.make_branch('foo')
194
192
        checkout = foo.create_checkout('checkout', lightweight=True)
195
 
        self.build_tree_contents([('checkout/file', 'a')])
 
193
        self.build_tree_contents([('checkout/file', b'a')])
196
194
        checkout.add('file')
197
195
        checkout.commit('a')
198
196
        bar = foo.controldir.sprout('bar').open_workingtree()
199
 
        self.build_tree_contents([('bar/file', 'b')])
 
197
        self.build_tree_contents([('bar/file', b'b')])
200
198
        bar.commit('b')
201
 
        self.build_tree_contents([('checkout/file', 'c')])
 
199
        self.build_tree_contents([('checkout/file', b'c')])
202
200
        switch.switch(checkout.controldir, bar.branch)
203
201
 
204
202
 
223
221
        self.build_tree(['checkout/file-4'])
224
222
        # Check the error reporting is as expected
225
223
        err = self.assertRaises(errors.BzrCommandError,
226
 
            switch.switch, checkout.controldir, to_branch)
 
224
                                switch.switch, checkout.controldir, to_branch)
227
225
        self.assertContainsRe(str(err),
228
 
            'Cannot switch as local commits found in the checkout.')
 
226
                              'Cannot switch as local commits found in the checkout.')
229
227
        # Check all is ok when force is given
230
228
        self.assertPathDoesNotExist('checkout/file-1')
231
229
        self.assertPathExists('checkout/file-2')