/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: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

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