41
51
tree.commit('rev1')
54
def _setup_uncommitted(self, same_revision=False):
55
tree = self._setup_tree()
56
to_branch = tree.bzrdir.sprout('branch-2').open_branch()
57
self.build_tree(['branch-1/file-2'])
62
checkout = tree.branch.create_checkout('checkout',
63
lightweight=self.lightweight)
64
self.build_tree(['checkout/file-3'])
65
checkout.add('file-3')
66
return checkout, to_branch
68
def test_switch_store_uncommitted(self):
69
"""Test switch updates tree and stores uncommitted changes."""
70
checkout, to_branch = self._setup_uncommitted()
71
self.assertPathDoesNotExist('checkout/file-1')
72
self.assertPathExists('checkout/file-2')
73
switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
74
self.assertPathExists('checkout/file-1')
75
self.assertPathDoesNotExist('checkout/file-2')
76
self.assertPathDoesNotExist('checkout/file-3')
78
def test_switch_restore_uncommitted(self):
79
"""Test switch updates tree and restores uncommitted changes."""
80
checkout, to_branch = self._setup_uncommitted()
81
old_branch = self._master_if_present(checkout.branch)
82
self.assertPathDoesNotExist('checkout/file-1')
83
self.assertPathExists('checkout/file-2')
84
self.assertPathExists('checkout/file-3')
85
switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
86
checkout = workingtree.WorkingTree.open('checkout')
87
switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
88
self.assertPathDoesNotExist('checkout/file-1')
89
self.assertPathExists('checkout/file-2')
90
self.assertPathExists('checkout/file-3')
92
def test_switch_restore_uncommitted_same_revision(self):
93
"""Test switch updates tree and restores uncommitted changes."""
94
checkout, to_branch = self._setup_uncommitted(same_revision=True)
95
old_branch = self._master_if_present(checkout.branch)
96
switch.switch(checkout.bzrdir, to_branch, store_uncommitted=True)
97
checkout = workingtree.WorkingTree.open('checkout')
98
switch.switch(checkout.bzrdir, old_branch, store_uncommitted=True)
99
self.assertPathExists('checkout/file-3')
44
101
def test_switch_updates(self):
45
102
"""Test switch updates tree and keeps uncommitted changes."""
46
tree = self._setup_tree()
47
to_branch = tree.bzrdir.sprout('branch-2').open_branch()
48
self.build_tree(['branch-1/file-2'])
52
checkout = tree.branch.create_checkout('checkout',
53
lightweight=self.lightweight)
54
self.build_tree(['checkout/file-3'])
55
checkout.add('file-3')
56
self.failIfExists('checkout/file-1')
57
self.failUnlessExists('checkout/file-2')
103
checkout, to_branch = self._setup_uncommitted()
104
self.assertPathDoesNotExist('checkout/file-1')
105
self.assertPathExists('checkout/file-2')
58
106
switch.switch(checkout.bzrdir, to_branch)
59
self.failUnlessExists('checkout/file-1')
60
self.failIfExists('checkout/file-2')
61
self.failUnlessExists('checkout/file-3')
107
self.assertPathExists('checkout/file-1')
108
self.assertPathDoesNotExist('checkout/file-2')
109
self.assertPathExists('checkout/file-3')
63
111
def test_switch_after_branch_moved(self):
64
112
"""Test switch after the branch is moved."""
84
132
'Unable to connect to current master branch .*'
85
133
'To switch anyway, use --force.')
86
134
switch.switch(checkout.bzrdir, to_branch, force=True)
87
self.failIfExists('checkout/file-1')
88
self.failUnlessExists('checkout/file-2')
89
self.failUnlessExists('checkout/file-3')
135
self.assertPathDoesNotExist('checkout/file-1')
136
self.assertPathExists('checkout/file-2')
137
self.assertPathExists('checkout/file-3')
91
139
def test_switch_when_pending_merges(self):
92
140
"""Test graceful failure if pending merges are outstanding."""
179
227
self.assertContainsRe(str(err),
180
228
'Cannot switch as local commits found in the checkout.')
181
229
# Check all is ok when force is given
182
self.failIfExists('checkout/file-1')
183
self.failUnlessExists('checkout/file-2')
230
self.assertPathDoesNotExist('checkout/file-1')
231
self.assertPathExists('checkout/file-2')
184
232
switch.switch(checkout.bzrdir, to_branch, force=True)
185
self.failUnlessExists('checkout/file-1')
186
self.failIfExists('checkout/file-2')
187
self.failIfExists('checkout/file-3')
188
self.failUnlessExists('checkout/file-4')
233
self.assertPathExists('checkout/file-1')
234
self.assertPathDoesNotExist('checkout/file-2')
235
self.assertPathDoesNotExist('checkout/file-3')
236
self.assertPathExists('checkout/file-4')
189
237
# Check that the checkout is a true mirror of the bound branch
190
238
self.assertEqual(to_branch.last_revision_info(),
191
239
checkout.branch.last_revision_info())