25
25
from bzrlib.branch import Branch
26
26
from bzrlib.errors import NoWorkingTree, NotBranchError
27
from bzrlib import registry
27
28
from bzrlib.workingtree import WorkingTree
29
30
from errors import (NotCheckout, UncommittedCheckout, ParentMissingRevisions,
33
class ChangedFilesPolicy(object):
36
def check_remove_branch():
40
class AllowChanged(ChangedFilesPolicy):
43
def check_changed(klass, wt):
47
class CheckChanged(ChangedFilesPolicy):
50
def check_changed(klass, wt):
34
class AllowChanged(object):
37
def check_changed(klass, wt, remove_branch):
41
class CheckChanged(object):
44
def check_changed(klass, wt, remove_branch):
51
45
delta = wt.changes_from(wt.basis_tree(), want_unchanged=False)
52
46
if delta.has_changed():
53
klass.handle_changed(wt)
47
klass.handle_changed(wt, remove_branch)
56
50
class HaltOnChange(CheckChanged):
59
def handle_changed(wt):
53
def handle_changed(wt, remove_branch):
60
54
raise UncommittedCheckout()
63
57
class StoreChanges(CheckChanged):
66
def check_remove_branch():
67
raise AssertionError('Cannot store changes in deleted branch.')
70
def handle_changed(wt):
60
def handle_changed(wt, remove_branch):
71
61
from bzrlib.plugins.pipeline.pipeline import PipeManager
63
raise AssertionError('Cannot store changes in deleted branch.')
72
64
PipeManager.from_checkout(wt).store_uncommitted()
67
change_policy_registry = registry.Registry()
70
change_policy_registry.register('force', AllowChanged,
71
'Delete tree even if contents are modified.')
74
change_policy_registry.register('store', StoreChanges,
75
'Store changes in branch. (Requires'
79
change_policy_registry.register('check', StoreChanges,
80
'Stop if tree contents are modified.')
75
83
def zap(path, remove_branch=False, policy=HaltOnChange):
77
policy.check_remove_branch()
79
85
wt = bzrdir.BzrDir.open(path).open_workingtree(path,
80
86
recommend_upgrade=False)
187
193
def test_store_remove_branch(self):
188
194
self.requireFeature(PipelinePluginFeature)
189
checkout = self.make_checkout()
195
checkout = self.make_modified_checkout()
190
196
branch = self.make_branch('branch')
191
197
checkout.branch.set_parent(branch.base)
192
198
e = self.assertRaises(AssertionError, zap, 'checkout',
193
199
policy=StoreChanges, remove_branch=True)
194
200
self.assertEqual('Cannot store changes in deleted branch.', str(e))
202
def test_store_remove_branch_unmodified(self):
203
self.requireFeature(PipelinePluginFeature)
204
checkout = self.make_checkout()
205
branch = self.make_branch('branch')
206
checkout.branch.set_parent(branch.base)
207
zap('checkout', policy=StoreChanges, remove_branch=True)
196
209
return makeSuite(TestZap)