450
449
except errors.NoWorkingTree:
451
450
raise errors.BzrCommandError("No working tree to remove")
452
451
except errors.NotLocalUrl:
453
raise errors.BzrCommandError("You cannot remove the working tree of a "
452
raise errors.BzrCommandError("You cannot remove the working tree"
456
changes = working.changes_from(working.basis_tree())
457
if changes.has_changed():
455
# XXX: What about pending merges ? -- vila 20090629
456
if working.has_changes(working.basis_tree()):
458
457
raise errors.UncommittedChanges(working)
460
459
working_path = working.bzrdir.root_transport.base
461
460
branch_path = working.branch.bzrdir.root_transport.base
462
461
if working_path != branch_path:
463
raise errors.BzrCommandError("You cannot remove the working tree from "
464
"a lightweight checkout")
462
raise errors.BzrCommandError("You cannot remove the working tree"
463
" from a lightweight checkout")
466
465
d.destroy_workingtree()
1107
1106
revision_id = None
1108
1107
if strict and tree is not None and revision_id is None:
1109
changes = tree.changes_from(tree.basis_tree())
1110
if changes.has_changed() or len(tree.get_parent_ids()) > 1:
1108
if (tree.has_changes(tree.basis_tree())
1109
or len(tree.get_parent_ids()) > 1):
1111
1110
raise errors.UncommittedChanges(
1112
1111
tree, more='Use --no-strict to force the push.')
1113
1112
if tree.last_revision() != tree.branch.last_revision():
3565
3564
merge refuses to run if there are any uncommitted changes, unless
3566
3565
--force is given.
3567
To select only some changes to merge, use "merge -i", which will prompt
3568
you to apply each diff hunk and file change, similar to "shelve".
3569
3571
To merge the latest revision from bzr.dev::
3608
3610
short_name='d',
3611
Option('preview', help='Instead of merging, show a diff of the merge.')
3613
Option('preview', help='Instead of merging, show a diff of the'
3615
Option('interactive', help='Select changes interactively.',
3614
3619
def run(self, location=None, revision=None, force=False,
3633
3639
except errors.NoSuchRevision:
3634
3640
basis_tree = tree.basis_tree()
3636
changes = tree.changes_from(basis_tree)
3637
if changes.has_changed():
3642
if tree.has_changes(basis_tree):
3638
3643
raise errors.UncommittedChanges(tree)
3640
3645
view_info = _get_view_info_for_change_reporter(tree)
3694
3699
merger.check_basis(False)
3696
return self._do_preview(merger)
3701
return self._do_preview(merger, cleanups)
3703
return self._do_interactive(merger, cleanups)
3698
3705
return self._do_merge(merger, change_reporter, allow_pending,
3701
3708
for cleanup in reversed(cleanups):
3704
def _do_preview(self, merger):
3705
from bzrlib.diff import show_diff_trees
3711
def _get_preview(self, merger, cleanups):
3706
3712
tree_merger = merger.make_merger()
3707
3713
tt = tree_merger.make_preview_transform()
3709
result_tree = tt.get_preview_tree()
3710
show_diff_trees(merger.this_tree, result_tree, self.outf,
3711
old_label='', new_label='')
3714
cleanups.append(tt.finalize)
3715
result_tree = tt.get_preview_tree()
3718
def _do_preview(self, merger, cleanups):
3719
from bzrlib.diff import show_diff_trees
3720
result_tree = self._get_preview(merger, cleanups)
3721
show_diff_trees(merger.this_tree, result_tree, self.outf,
3722
old_label='', new_label='')
3715
3724
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3716
3725
merger.change_reporter = change_reporter
3736
def _do_interactive(self, merger, cleanups):
3737
"""Perform an interactive merge.
3739
This works by generating a preview tree of the merge, then using
3740
Shelver to selectively remove the differences between the working tree
3741
and the preview tree.
3743
from bzrlib import shelf_ui
3744
result_tree = self._get_preview(merger, cleanups)
3745
writer = bzrlib.option.diff_writer_registry.get()
3746
shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
3747
reporter=shelf_ui.ApplyReporter(),
3748
diff_writer=writer(sys.stdout))
3727
3751
def sanity_check_merger(self, merger):
3728
3752
if (merger.show_base and
3729
3753
not merger.merge_type is _mod_merge.Merge3Merger):
5292
5316
takes_args = ['to_location']
5293
5317
takes_options = [Option('force',
5294
help='Switch even if local commits will be lost.')
5318
help='Switch even if local commits will be lost.'),
5319
Option('create-branch', short_name='b',
5320
help='Create the target branch from this one before'
5321
' switching to it.'),
5297
def run(self, to_location, force=False):
5324
def run(self, to_location, force=False, create_branch=False):
5298
5325
from bzrlib import switch
5299
5326
tree_location = '.'
5300
5327
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5302
5329
branch = control_dir.open_branch()
5303
5330
had_explicit_nick = branch.get_config().has_explicit_nickname()
5304
5331
except errors.NotBranchError:
5305
5333
had_explicit_nick = False
5307
to_branch = Branch.open(to_location)
5308
except errors.NotBranchError:
5309
this_url = self._get_branch_location(control_dir)
5310
to_branch = Branch.open(
5311
urlutils.join(this_url, '..', to_location))
5336
raise errors.BzrCommandError('cannot create branch without'
5338
if '/' not in to_location and '\\' not in to_location:
5339
# This path is meant to be relative to the existing branch
5340
this_url = self._get_branch_location(control_dir)
5341
to_location = urlutils.join(this_url, '..', to_location)
5342
to_branch = branch.bzrdir.sprout(to_location,
5343
possible_transports=[branch.bzrdir.root_transport],
5344
source_branch=branch).open_branch()
5346
# from_branch = control_dir.open_branch()
5347
# except errors.NotBranchError:
5348
# raise BzrCommandError('Cannot create a branch from this'
5349
# ' location when we cannot open this branch')
5350
# from_branch.bzrdir.sprout(
5354
to_branch = Branch.open(to_location)
5355
except errors.NotBranchError:
5356
this_url = self._get_branch_location(control_dir)
5357
to_branch = Branch.open(
5358
urlutils.join(this_url, '..', to_location))
5312
5359
switch.switch(control_dir, to_branch, force)
5313
5360
if had_explicit_nick:
5314
5361
branch = control_dir.open_branch() #get the new branch!