/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 bzrlib/tests/test_switch.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Tests for breezy.switch."""
 
17
"""Tests for bzrlib.switch."""
18
18
 
19
19
 
20
20
import os
21
21
 
22
 
from breezy import (
 
22
from bzrlib import (
23
23
    branch,
24
24
    errors,
25
25
    lock,
53
53
 
54
54
    def _setup_uncommitted(self, same_revision=False):
55
55
        tree = self._setup_tree()
56
 
        to_branch = tree.controldir.sprout('branch-2').open_branch()
 
56
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
57
57
        self.build_tree(['branch-1/file-2'])
58
58
        if not same_revision:
59
59
            tree.add('file-2')
70
70
        checkout, to_branch = self._setup_uncommitted()
71
71
        self.assertPathDoesNotExist('checkout/file-1')
72
72
        self.assertPathExists('checkout/file-2')
73
 
        switch.switch(checkout.controldir, to_branch, store_uncommitted=True)
 
73
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
74
74
        self.assertPathExists('checkout/file-1')
75
75
        self.assertPathDoesNotExist('checkout/file-2')
76
76
        self.assertPathDoesNotExist('checkout/file-3')
82
82
        self.assertPathDoesNotExist('checkout/file-1')
83
83
        self.assertPathExists('checkout/file-2')
84
84
        self.assertPathExists('checkout/file-3')
85
 
        switch.switch(checkout.controldir, to_branch, store_uncommitted=True)
 
85
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
86
86
        checkout = workingtree.WorkingTree.open('checkout')
87
 
        switch.switch(checkout.controldir, old_branch, store_uncommitted=True)
 
87
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
88
88
        self.assertPathDoesNotExist('checkout/file-1')
89
89
        self.assertPathExists('checkout/file-2')
90
90
        self.assertPathExists('checkout/file-3')
93
93
        """Test switch updates tree and restores uncommitted changes."""
94
94
        checkout, to_branch = self._setup_uncommitted(same_revision=True)
95
95
        old_branch = self._master_if_present(checkout.branch)
96
 
        switch.switch(checkout.controldir, to_branch, store_uncommitted=True)
 
96
        switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
97
97
        checkout = workingtree.WorkingTree.open('checkout')
98
 
        switch.switch(checkout.controldir, old_branch, store_uncommitted=True)
 
98
        switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
99
99
        self.assertPathExists('checkout/file-3')
100
100
 
101
101
    def test_switch_updates(self):
103
103
        checkout, to_branch = self._setup_uncommitted()
104
104
        self.assertPathDoesNotExist('checkout/file-1')
105
105
        self.assertPathExists('checkout/file-2')
106
 
        switch.switch(checkout.controldir, to_branch)
 
106
        switch.switch(checkout.bzrdir, to_branch)
107
107
        self.assertPathExists('checkout/file-1')
108
108
        self.assertPathDoesNotExist('checkout/file-2')
109
109
        self.assertPathExists('checkout/file-3')
119
119
        tree.commit('rev2')
120
120
        self.build_tree(['checkout/file-3'])
121
121
        checkout.add('file-3')
122
 
        checkout_dir = checkout.controldir
 
122
        checkout_dir = checkout.bzrdir
123
123
        # rename the branch on disk, the checkout object is now invalid.
124
124
        os.rename('branch-1', 'branch-2')
125
125
        to_branch = branch.Branch.open('branch-2')
126
126
        # Check fails without --force
127
127
        err = self.assertRaises(
128
128
            (errors.BzrCommandError, errors.NotBranchError),
129
 
            switch.switch, checkout.controldir, to_branch)
 
129
            switch.switch, checkout.bzrdir, to_branch)
130
130
        if isinstance(err, errors.BzrCommandError):
131
131
            self.assertContainsRe(str(err),
132
132
                'Unable to connect to current master branch .*'
133
133
                'To switch anyway, use --force.')
134
 
        switch.switch(checkout.controldir, to_branch, force=True)
 
134
        switch.switch(checkout.bzrdir, to_branch, force=True)
135
135
        self.assertPathDoesNotExist('checkout/file-1')
136
136
        self.assertPathExists('checkout/file-2')
137
137
        self.assertPathExists('checkout/file-3')
140
140
        """Test graceful failure if pending merges are outstanding."""
141
141
        # Create 2 branches and a checkout
142
142
        tree = self._setup_tree()
143
 
        tree2 = tree.controldir.sprout('branch-2').open_workingtree()
 
143
        tree2 = tree.bzrdir.sprout('branch-2').open_workingtree()
144
144
        checkout = tree.branch.create_checkout('checkout',
145
145
            lightweight=self.lightweight)
146
146
        # Change tree2 and merge it into the checkout without committing
150
150
        checkout.merge_from_branch(tree2.branch)
151
151
        # Check the error reporting is as expected
152
152
        err = self.assertRaises(errors.BzrCommandError,
153
 
            switch.switch, checkout.controldir, tree2.branch)
 
153
            switch.switch, checkout.bzrdir, tree2.branch)
154
154
        self.assertContainsRe(str(err),
155
155
            "Pending merges must be committed or reverted before using switch")
156
156
 
160
160
        tree = self.make_branch_and_tree('branch-1')
161
161
        self.build_tree(['branch-1/file-1'])
162
162
        tree.add('file-1')
163
 
        tree.commit(rev_id=b'rev1', message='rev1')
 
163
        tree.commit(rev_id='rev1', message='rev1')
164
164
        self.build_tree(['branch-1/file-2'])
165
165
        tree.add('file-2')
166
 
        tree.commit(rev_id=b'rev2', message='rev2')
 
166
        tree.commit(rev_id='rev2', message='rev2')
167
167
        # Check it out and switch to revision 1
168
168
        checkout = tree.branch.create_checkout('checkout',
169
169
            lightweight=self.lightweight)
170
 
        switch.switch(checkout.controldir, tree.branch, revision_id="rev1")
 
170
        switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
171
171
        self.assertPathExists('checkout/file-1')
172
172
        self.assertPathDoesNotExist('checkout/file-2')
173
173
 
174
174
    def test_switch_changing_root_id(self):
175
175
        tree = self._setup_tree()
176
176
        tree2 = self.make_branch_and_tree('tree-2')
177
 
        tree2.set_root_id(b'custom-root-id')
 
177
        tree2.set_root_id('custom-root-id')
178
178
        self.build_tree(['tree-2/file-2'])
179
179
        tree2.add(['file-2'])
180
180
        tree2.commit('rev1b')
181
181
        checkout = tree.branch.create_checkout('checkout',
182
182
            lightweight=self.lightweight)
183
 
        switch.switch(checkout.controldir, tree2.branch)
 
183
        switch.switch(checkout.bzrdir, tree2.branch)
184
184
        self.assertEqual('custom-root-id', tree2.get_root_id())
185
185
 
186
186
    def test_switch_configurable_file_merger(self):
192
192
            'test factory')
193
193
        foo = self.make_branch('foo')
194
194
        checkout = foo.create_checkout('checkout', lightweight=True)
195
 
        self.build_tree_contents([('checkout/file', b'a')])
 
195
        self.build_tree_contents([('checkout/file', 'a')])
196
196
        checkout.add('file')
197
197
        checkout.commit('a')
198
 
        bar = foo.controldir.sprout('bar').open_workingtree()
199
 
        self.build_tree_contents([('bar/file', b'b')])
 
198
        bar = foo.bzrdir.sprout('bar').open_workingtree()
 
199
        self.build_tree_contents([('bar/file', 'b')])
200
200
        bar.commit('b')
201
201
        self.build_tree_contents([('checkout/file', 'c')])
202
 
        switch.switch(checkout.controldir, bar.branch)
 
202
        switch.switch(checkout.bzrdir, bar.branch)
203
203
 
204
204
 
205
205
class TestSwitchHeavyweight(TestSwitch):
211
211
    def test_switch_with_local_commits(self):
212
212
        """Test switch complains about local commits unless --force given."""
213
213
        tree = self._setup_tree()
214
 
        to_branch = tree.controldir.sprout('branch-2').open_branch()
 
214
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
215
215
        self.build_tree(['branch-1/file-2'])
216
216
        tree.add('file-2')
217
217
        tree.remove('file-1')
223
223
        self.build_tree(['checkout/file-4'])
224
224
        # Check the error reporting is as expected
225
225
        err = self.assertRaises(errors.BzrCommandError,
226
 
            switch.switch, checkout.controldir, to_branch)
 
226
            switch.switch, checkout.bzrdir, to_branch)
227
227
        self.assertContainsRe(str(err),
228
228
            'Cannot switch as local commits found in the checkout.')
229
229
        # Check all is ok when force is given
230
230
        self.assertPathDoesNotExist('checkout/file-1')
231
231
        self.assertPathExists('checkout/file-2')
232
 
        switch.switch(checkout.controldir, to_branch, force=True)
 
232
        switch.switch(checkout.bzrdir, to_branch, force=True)
233
233
        self.assertPathExists('checkout/file-1')
234
234
        self.assertPathDoesNotExist('checkout/file-2')
235
235
        self.assertPathDoesNotExist('checkout/file-3')