~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2004-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
54
54
    )
55
55
from bzrlib.branch import Branch
56
56
from bzrlib.conflicts import ConflictList
57
 
from bzrlib.transport import memory
58
57
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
59
58
from bzrlib.smtp_connection import SMTPConnection
60
59
from bzrlib.workingtree import WorkingTree
453
452
    To re-create the working tree, use "bzr checkout".
454
453
    """
455
454
    _see_also = ['checkout', 'working-trees']
456
 
    takes_args = ['location*']
 
455
    takes_args = ['location?']
457
456
    takes_options = [
458
457
        Option('force',
459
458
               help='Remove the working tree even if it has '
460
459
                    'uncommitted changes.'),
461
460
        ]
462
461
 
463
 
    def run(self, location_list, force=False):
464
 
        if not location_list:
465
 
            location_list=['.']
466
 
 
467
 
        for location in location_list:
468
 
            d = bzrdir.BzrDir.open(location)
469
 
            
470
 
            try:
471
 
                working = d.open_workingtree()
472
 
            except errors.NoWorkingTree:
473
 
                raise errors.BzrCommandError("No working tree to remove")
474
 
            except errors.NotLocalUrl:
475
 
                raise errors.BzrCommandError("You cannot remove the working tree"
476
 
                                             " of a remote path")
477
 
            if not force:
478
 
                if (working.has_changes()):
479
 
                    raise errors.UncommittedChanges(working)
480
 
 
481
 
            working_path = working.bzrdir.root_transport.base
482
 
            branch_path = working.branch.bzrdir.root_transport.base
483
 
            if working_path != branch_path:
484
 
                raise errors.BzrCommandError("You cannot remove the working tree"
485
 
                                             " from a lightweight checkout")
486
 
 
487
 
            d.destroy_workingtree()
 
462
    def run(self, location='.', force=False):
 
463
        d = bzrdir.BzrDir.open(location)
 
464
 
 
465
        try:
 
466
            working = d.open_workingtree()
 
467
        except errors.NoWorkingTree:
 
468
            raise errors.BzrCommandError("No working tree to remove")
 
469
        except errors.NotLocalUrl:
 
470
            raise errors.BzrCommandError("You cannot remove the working tree"
 
471
                                         " of a remote path")
 
472
        if not force:
 
473
            if (working.has_changes()):
 
474
                raise errors.UncommittedChanges(working)
 
475
 
 
476
        working_path = working.bzrdir.root_transport.base
 
477
        branch_path = working.branch.bzrdir.root_transport.base
 
478
        if working_path != branch_path:
 
479
            raise errors.BzrCommandError("You cannot remove the working tree"
 
480
                                         " from a lightweight checkout")
 
481
 
 
482
        d.destroy_workingtree()
488
483
 
489
484
 
490
485
class cmd_revno(Command):
3446
3441
    def get_transport_type(typestring):
3447
3442
        """Parse and return a transport specifier."""
3448
3443
        if typestring == "sftp":
3449
 
            from bzrlib.tests import stub_sftp
3450
 
            return stub_sftp.SFTPAbsoluteServer
 
3444
            from bzrlib.transport.sftp import SFTPAbsoluteServer
 
3445
            return SFTPAbsoluteServer
3451
3446
        if typestring == "memory":
3452
 
            from bzrlib.tests import test_server
3453
 
            return memory.MemoryServer
 
3447
            from bzrlib.transport.memory import MemoryServer
 
3448
            return MemoryServer
3454
3449
        if typestring == "fakenfs":
3455
 
            from bzrlib.tests import test_server
3456
 
            return test_server.FakeNFSServer
 
3450
            from bzrlib.transport.fakenfs import FakeNFSServer
 
3451
            return FakeNFSServer
3457
3452
        msg = "No known transport type %s. Supported types are: sftp\n" %\
3458
3453
            (typestring)
3459
3454
        raise errors.BzrCommandError(msg)
3782
3777
                    raise errors.BzrCommandError(
3783
3778
                        'Cannot use -r with merge directives or bundles')
3784
3779
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
3785
 
                   mergeable, None)
 
3780
                   mergeable, pb)
3786
3781
 
3787
3782
        if merger is None and uncommitted:
3788
3783
            if revision is not None and len(revision) > 0:
3789
3784
                raise errors.BzrCommandError('Cannot use --uncommitted and'
3790
3785
                    ' --revision at the same time.')
3791
 
            merger = self.get_merger_from_uncommitted(tree, location, None)
 
3786
            merger = self.get_merger_from_uncommitted(tree, location, pb)
3792
3787
            allow_pending = False
3793
3788
 
3794
3789
        if merger is None:
3795
3790
            merger, allow_pending = self._get_merger_from_branch(tree,
3796
 
                location, revision, remember, possible_transports, None)
 
3791
                location, revision, remember, possible_transports, pb)
3797
3792
 
3798
3793
        merger.merge_type = merge_type
3799
3794
        merger.reprocess = reprocess
4070
4065
        # list, we imply that the working tree text has seen and rejected
4071
4066
        # all the changes from the other tree, when in fact those changes
4072
4067
        # have not yet been seen.
 
4068
        pb = ui.ui_factory.nested_progress_bar()
4073
4069
        tree.set_parent_ids(parents[:1])
4074
4070
        try:
4075
 
            merger = _mod_merge.Merger.from_revision_ids(None, tree, parents[1])
 
4071
            merger = _mod_merge.Merger.from_revision_ids(pb,
 
4072
                                                         tree, parents[1])
4076
4073
            merger.interesting_ids = interesting_ids
4077
4074
            merger.merge_type = merge_type
4078
4075
            merger.show_base = show_base
4080
4077
            conflicts = merger.do_merge()
4081
4078
        finally:
4082
4079
            tree.set_parent_ids(parents)
 
4080
            pb.finished()
4083
4081
        if conflicts > 0:
4084
4082
            return 1
4085
4083
        else:
4154
4152
    @staticmethod
4155
4153
    def _revert_tree_to_revision(tree, revision, file_list, no_backup):
4156
4154
        rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
4157
 
        tree.revert(file_list, rev_tree, not no_backup, None,
4158
 
            report_changes=True)
 
4155
        pb = ui.ui_factory.nested_progress_bar()
 
4156
        try:
 
4157
            tree.revert(file_list, rev_tree, not no_backup, pb,
 
4158
                report_changes=True)
 
4159
        finally:
 
4160
            pb.finished()
4159
4161
 
4160
4162
 
4161
4163
class cmd_assert_fail(Command):
4610
4612
                    'This format does not remember old locations.')
4611
4613
            else:
4612
4614
                if location is None:
4613
 
                    if b.get_bound_location() is not None:
4614
 
                        raise errors.BzrCommandError('Branch is already bound')
4615
 
                    else:
4616
 
                        raise errors.BzrCommandError('No location supplied '
4617
 
                            'and no previous location known')
 
4615
                    raise errors.BzrCommandError('No location supplied and no '
 
4616
                        'previous location known')
4618
4617
        b_other = Branch.open(location)
4619
4618
        try:
4620
4619
            b.bind(b_other)
4717
4716
                rev_id = b.get_rev_id(revno)
4718
4717
 
4719
4718
        if rev_id is None or _mod_revision.is_null(rev_id):
4720
 
            ui.ui_factory.note('No revisions to uncommit.')
 
4719
            self.outf.write('No revisions to uncommit.\n')
4721
4720
            return 1
4722
4721
 
4723
 
        log_collector = ui.ui_factory.make_output_stream()
4724
4722
        lf = log_formatter('short',
4725
 
                           to_file=log_collector,
 
4723
                           to_file=self.outf,
4726
4724
                           show_timezone='original')
4727
4725
 
4728
4726
        show_log(b,
4733
4731
                 end_revision=last_revno)
4734
4732
 
4735
4733
        if dry_run:
4736
 
            ui.ui_factory.note('Dry-run, pretending to remove the above revisions.')
 
4734
            print 'Dry-run, pretending to remove the above revisions.'
 
4735
            if not force:
 
4736
                val = raw_input('Press <enter> to continue')
4737
4737
        else:
4738
 
            ui.ui_factory.note('The above revision(s) will be removed.')
4739
 
 
4740
 
        if not force:
4741
 
            if not ui.ui_factory.get_boolean('Are you sure [y/N]? '):
4742
 
                ui.ui_factory.note('Canceled')
4743
 
                return 0
 
4738
            print 'The above revision(s) will be removed.'
 
4739
            if not force:
 
4740
                val = raw_input('Are you sure [y/N]? ')
 
4741
                if val.lower() not in ('y', 'yes'):
 
4742
                    print 'Canceled'
 
4743
                    return 0
4744
4744
 
4745
4745
        mutter('Uncommitting from {%s} to {%s}',
4746
4746
               last_rev_id, rev_id)
4747
4747
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
4748
4748
                 revno=revno, local=local)
4749
 
        ui.ui_factory.note('You can restore the old tip by running:\n'
4750
 
             '  bzr pull . -r revid:%s' % last_rev_id)
 
4749
        note('You can restore the old tip by running:\n'
 
4750
             '  bzr pull . -r revid:%s', last_rev_id)
4751
4751
 
4752
4752
 
4753
4753
class cmd_break_lock(Command):
5912
5912
    )
5913
5913
from bzrlib.foreign import cmd_dpush
5914
5914
from bzrlib.sign_my_commits import cmd_sign_my_commits
 
5915
from bzrlib.weave_commands import cmd_versionedfile_list, \
 
5916
        cmd_weave_plan_merge, cmd_weave_merge_text