/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: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

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."""
166
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)
 
167
                                               lightweight=self.lightweight)
170
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')
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
182
        self.assertEqual(b'custom-root-id', tree2.get_root_id())
185
183
 
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')