~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:
250
250
    To re-create the working tree, use "bzr checkout".
251
251
    """
252
252
    _see_also = ['checkout', 'working-trees']
253
 
 
254
253
    takes_args = ['location?']
 
254
    takes_options = [
 
255
        Option('force',
 
256
               help='Remove the working tree even if it has '
 
257
                    'uncommitted changes.'),
 
258
        ]
255
259
 
256
 
    def run(self, location='.'):
 
260
    def run(self, location='.', force=False):
257
261
        d = bzrdir.BzrDir.open(location)
258
262
        
259
263
        try:
263
267
        except errors.NotLocalUrl:
264
268
            raise errors.BzrCommandError("You cannot remove the working tree of a "
265
269
                                         "remote path")
266
 
        
 
270
        if not force:
 
271
            changes = working.changes_from(working.basis_tree())
 
272
            if changes.has_changed():
 
273
                raise errors.UncommittedChanges(working)
 
274
 
267
275
        working_path = working.bzrdir.root_transport.base
268
276
        branch_path = working.branch.bzrdir.root_transport.base
269
277
        if working_path != branch_path:
837
845
            help='Create a stacked branch referring to the source branch. '
838
846
                'The new branch will depend on the availability of the source '
839
847
                'branch for all operations.'),
 
848
        Option('standalone',
 
849
               help='Do not use a shared repository, even if available.'),
840
850
        ]
841
851
    aliases = ['get', 'clone']
842
852
 
843
853
    def run(self, from_location, to_location=None, revision=None,
844
 
            hardlink=False, stacked=False):
 
854
            hardlink=False, stacked=False, standalone=False):
845
855
        from bzrlib.tag import _merge_tags_if_possible
846
856
        if revision is None:
847
857
            revision = [None]
876
886
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
877
887
                                            possible_transports=[to_transport],
878
888
                                            accelerator_tree=accelerator_tree,
879
 
                                            hardlink=hardlink, stacked=stacked)
 
889
                                            hardlink=hardlink, stacked=stacked,
 
890
                                            force_new_repo=standalone)
880
891
                branch = dir.open_branch()
881
892
            except errors.NoSuchRevision:
882
893
                to_transport.delete_tree('.')
1312
1323
            _create_prefix(to_transport)
1313
1324
 
1314
1325
        try:
1315
 
            existing_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
 
1326
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1316
1327
        except errors.NotBranchError:
1317
1328
            # really a NotBzrDir error...
1318
1329
            create_branch = bzrdir.BzrDir.create_branch_convenience
1319
1330
            branch = create_branch(to_transport.base, format=format,
1320
1331
                                   possible_transports=[to_transport])
 
1332
            a_bzrdir = branch.bzrdir
1321
1333
        else:
1322
1334
            from bzrlib.transport.local import LocalTransport
1323
 
            if existing_bzrdir.has_branch():
 
1335
            if a_bzrdir.has_branch():
1324
1336
                if (isinstance(to_transport, LocalTransport)
1325
 
                    and not existing_bzrdir.has_workingtree()):
 
1337
                    and not a_bzrdir.has_workingtree()):
1326
1338
                        raise errors.BranchExistsWithoutWorkingTree(location)
1327
1339
                raise errors.AlreadyBranchError(location)
1328
 
            else:
1329
 
                branch = existing_bzrdir.create_branch()
1330
 
                existing_bzrdir.create_workingtree()
 
1340
            branch = a_bzrdir.create_branch()
 
1341
            a_bzrdir.create_workingtree()
1331
1342
        if append_revisions_only:
1332
1343
            try:
1333
1344
                branch.set_append_revisions_only(True)
1336
1347
                    ' to append-revisions-only.  Try --experimental-branch6')
1337
1348
        if not is_quiet():
1338
1349
            from bzrlib.info import show_bzrdir_info
1339
 
            show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
1340
 
                to_transport)[0], verbose=0, outfile=self.outf)
 
1350
            show_bzrdir_info(a_bzrdir, verbose=0, outfile=self.outf)
1341
1351
 
1342
1352
 
1343
1353
class cmd_init_repository(Command):
1391
1401
        repo.set_make_working_trees(not no_trees)
1392
1402
        if not is_quiet():
1393
1403
            from bzrlib.info import show_bzrdir_info
1394
 
            show_bzrdir_info(bzrdir.BzrDir.open_containing_from_transport(
1395
 
                to_transport)[0], verbose=0, outfile=self.outf)
 
1404
            show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
1396
1405
 
1397
1406
 
1398
1407
class cmd_diff(Command):
3318
3327
            Option('other', 'Same as --theirs-only.'),
3319
3328
            'log-format',
3320
3329
            'show-ids',
3321
 
            'verbose'
 
3330
            'verbose',
 
3331
            Option('include-merges', 'Show merged revisions.'),
3322
3332
            ]
3323
3333
    encoding_type = 'replace'
3324
3334
 
3325
3335
    @display_command
3326
3336
    def run(self, other_branch=None, reverse=False, mine_only=False,
3327
 
            theirs_only=False, log_format=None, long=False, short=False, line=False, 
3328
 
            show_ids=False, verbose=False, this=False, other=False):
 
3337
            theirs_only=False,
 
3338
            log_format=None, long=False, short=False, line=False,
 
3339
            show_ids=False, verbose=False, this=False, other=False,
 
3340
            include_merges=False):
3329
3341
        from bzrlib.missing import find_unmerged, iter_log_revisions
3330
3342
 
3331
3343
        if this:
3361
3373
            remote_branch.lock_read()
3362
3374
            try:
3363
3375
                local_extra, remote_extra = find_unmerged(
3364
 
                    local_branch, remote_branch, restrict)
 
3376
                    local_branch, remote_branch, restrict,
 
3377
                    backward=not reverse,
 
3378
                    include_merges=include_merges)
3365
3379
 
3366
3380
                if log_format is None:
3367
3381
                    registry = log.log_formatter_registry
3369
3383
                lf = log_format(to_file=self.outf,
3370
3384
                                show_ids=show_ids,
3371
3385
                                show_timezone='original')
3372
 
                if reverse is False:
3373
 
                    if local_extra is not None:
3374
 
                        local_extra.reverse()
3375
 
                    if remote_extra is not None:
3376
 
                        remote_extra.reverse()
3377
3386
 
3378
3387
                status_code = 0
3379
3388
                if local_extra and not theirs_only:
3544
3553
    @display_command
3545
3554
    def run(self, filename, all=False, long=False, revision=None,
3546
3555
            show_ids=False):
3547
 
        from bzrlib.annotate import annotate_file
 
3556
        from bzrlib.annotate import annotate_file, annotate_file_tree
3548
3557
        wt, branch, relpath = \
3549
3558
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
3550
3559
        if wt is not None:
3566
3575
            if file_id is None:
3567
3576
                raise errors.NotVersionedError(filename)
3568
3577
            file_version = tree.inventory[file_id].revision
3569
 
            annotate_file(branch, file_version, file_id, long, all, self.outf,
3570
 
                          show_ids=show_ids)
 
3578
            if wt is not None and revision is None:
 
3579
                # If there is a tree and we're not annotating historical
 
3580
                # versions, annotate the working tree's content.
 
3581
                annotate_file_tree(wt, file_id, self.outf, long, all,
 
3582
                    show_ids=show_ids)
 
3583
            else:
 
3584
                annotate_file(branch, file_version, file_id, long, all, self.outf,
 
3585
                              show_ids=show_ids)
3571
3586
        finally:
3572
3587
            if wt is not None:
3573
3588
                wt.unlock()
4561
4576
        try:
4562
4577
            to_branch = Branch.open(to_location)
4563
4578
        except errors.NotBranchError:
 
4579
            this_branch = control_dir.open_branch()
 
4580
            # This may be a heavy checkout, where we want the master branch
 
4581
            this_url = this_branch.get_bound_location()
 
4582
            # If not, use a local sibling
 
4583
            if this_url is None:
 
4584
                this_url = this_branch.base
4564
4585
            to_branch = Branch.open(
4565
 
                control_dir.open_branch().base + '../' + to_location)
 
4586
                urlutils.join(this_url, '..', to_location))
4566
4587
        switch.switch(control_dir, to_branch, force)
4567
4588
        note('Switched to branch: %s',
4568
4589
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))