/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/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2009-07-15 07:32:26 UTC
  • mfrom: (4536 +trunk)
  • mto: (4536.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4537.
  • Revision ID: v.ladeuil+lp@free.fr-20090715073226-a7ylxd6ctbzeu0o6
Merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    revision as _mod_revision,
46
46
    symbol_versioning,
47
47
    transport,
48
 
    tree as _mod_tree,
49
48
    ui,
50
49
    urlutils,
51
50
    views,
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 "
454
 
                                         "remote path")
 
452
            raise errors.BzrCommandError("You cannot remove the working tree"
 
453
                                         " of a remote path")
455
454
        if not force:
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)
459
458
 
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")
465
464
 
466
465
        d.destroy_workingtree()
467
466
 
1106
1105
        else:
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
3566
 
 
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
 
3568
3570
    :Examples:
3569
3571
        To merge the latest revision from bzr.dev::
3570
3572
 
3608
3610
               short_name='d',
3609
3611
               type=unicode,
3610
3612
               ),
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'
 
3614
               ' merge.'),
 
3615
        Option('interactive', help='Select changes interactively.',
 
3616
            short_name='i')
3612
3617
    ]
3613
3618
 
3614
3619
    def run(self, location=None, revision=None, force=False,
3616
3621
            uncommitted=False, pull=False,
3617
3622
            directory=None,
3618
3623
            preview=False,
 
3624
            interactive=False,
3619
3625
            ):
3620
3626
        if merge_type is None:
3621
3627
            merge_type = _mod_merge.Merge3Merger
3633
3639
        except errors.NoSuchRevision:
3634
3640
            basis_tree = tree.basis_tree()
3635
3641
        if not force:
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)
3639
3644
 
3640
3645
        view_info = _get_view_info_for_change_reporter(tree)
3693
3698
                    return 0
3694
3699
            merger.check_basis(False)
3695
3700
            if preview:
3696
 
                return self._do_preview(merger)
 
3701
                return self._do_preview(merger, cleanups)
 
3702
            elif interactive:
 
3703
                return self._do_interactive(merger, cleanups)
3697
3704
            else:
3698
3705
                return self._do_merge(merger, change_reporter, allow_pending,
3699
3706
                                      verified)
3701
3708
            for cleanup in reversed(cleanups):
3702
3709
                cleanup()
3703
3710
 
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()
3708
 
        try:
3709
 
            result_tree = tt.get_preview_tree()
3710
 
            show_diff_trees(merger.this_tree, result_tree, self.outf,
3711
 
                            old_label='', new_label='')
3712
 
        finally:
3713
 
            tt.finalize()
 
3714
        cleanups.append(tt.finalize)
 
3715
        result_tree = tt.get_preview_tree()
 
3716
        return result_tree
 
3717
 
 
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='')
3714
3723
 
3715
3724
    def _do_merge(self, merger, change_reporter, allow_pending, verified):
3716
3725
        merger.change_reporter = change_reporter
3724
3733
        else:
3725
3734
            return 0
3726
3735
 
 
3736
    def _do_interactive(self, merger, cleanups):
 
3737
        """Perform an interactive merge.
 
3738
 
 
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.
 
3742
        """
 
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))
 
3749
        shelver.run()
 
3750
 
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):
5291
5315
 
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.'),
5295
5322
                     ]
5296
5323
 
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:
 
5332
            branch = None
5305
5333
            had_explicit_nick = False
5306
 
        try:
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))
 
5334
        if create_branch:
 
5335
            if branch is None:
 
5336
                raise errors.BzrCommandError('cannot create branch without'
 
5337
                                             ' source branch')
 
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()
 
5345
            # try:
 
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(
 
5351
            pass
 
5352
        else:
 
5353
            try:
 
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!