/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: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

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')
124
126
        # Check fails without --force
125
127
        err = self.assertRaises(
126
 
            (errors.CommandError, errors.NotBranchError),
 
128
            (errors.BzrCommandError, errors.NotBranchError),
127
129
            switch.switch, checkout.controldir, to_branch)
128
 
        if isinstance(err, errors.CommandError):
 
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')
147
149
        tree2.commit('rev2')
148
150
        checkout.merge_from_branch(tree2.branch)
149
151
        # Check the error reporting is as expected
150
 
        err = self.assertRaises(errors.CommandError,
151
 
                                switch.switch, checkout.controldir, tree2.branch)
 
152
        err = self.assertRaises(errors.BzrCommandError,
 
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."""
158
160
        tree = self.make_branch_and_tree('branch-1')
159
161
        self.build_tree(['branch-1/file-1'])
160
162
        tree.add('file-1')
161
 
        tree.commit(rev_id=b'rev1', message='rev1')
 
163
        tree.commit(rev_id='rev1', message='rev1')
162
164
        self.build_tree(['branch-1/file-2'])
163
165
        tree.add('file-2')
164
 
        tree.commit(rev_id=b'rev2', message='rev2')
 
166
        tree.commit(rev_id='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
 
172
174
    def test_switch_changing_root_id(self):
173
175
        tree = self._setup_tree()
174
176
        tree2 = self.make_branch_and_tree('tree-2')
175
 
        tree2.set_root_id(b'custom-root-id')
 
177
        tree2.set_root_id('custom-root-id')
176
178
        self.build_tree(['tree-2/file-2'])
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):
190
192
            'test factory')
191
193
        foo = self.make_branch('foo')
192
194
        checkout = foo.create_checkout('checkout', lightweight=True)
193
 
        self.build_tree_contents([('checkout/file', b'a')])
 
195
        self.build_tree_contents([('checkout/file', 'a')])
194
196
        checkout.add('file')
195
197
        checkout.commit('a')
196
198
        bar = foo.controldir.sprout('bar').open_workingtree()
197
 
        self.build_tree_contents([('bar/file', b'b')])
 
199
        self.build_tree_contents([('bar/file', '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
 
220
222
        checkout.commit(message='local only commit', local=True)
221
223
        self.build_tree(['checkout/file-4'])
222
224
        # Check the error reporting is as expected
223
 
        err = self.assertRaises(errors.CommandError,
224
 
                                switch.switch, checkout.controldir, to_branch)
 
225
        err = self.assertRaises(errors.BzrCommandError,
 
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')