~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2006-03-06 07:11:09 UTC
  • mfrom: (1591 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1593.
  • Revision ID: mbp@sourcefrog.net-20060306071109-6b35534e38610c43
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
596
596
                else:
597
597
                    raise
598
598
            try:
 
599
                # preserve whatever source format we have.
599
600
                dir = br_from.bzrdir.sprout(to_location, revision_id, basis_dir)
600
601
                branch = dir.open_branch()
601
602
            except bzrlib.errors.NoSuchRevision:
604
605
                raise BzrCommandError(msg)
605
606
            except bzrlib.errors.UnlistableBranch:
606
607
                rmtree(to_location)
607
 
                msg = "The branch %s cannot be used as a --basis"
 
608
                msg = "The branch %s cannot be used as a --basis" % (basis,)
608
609
                raise BzrCommandError(msg)
609
610
            if name:
610
611
                branch.control_files.put_utf8('branch-name', name)
630
631
    branch being checked out. [Not implemented yet.]
631
632
    """
632
633
    takes_args = ['branch_location', 'to_location?']
633
 
    takes_options = ['revision'] # , 'basis']
 
634
    takes_options = ['revision', # , 'basis']
 
635
                     Option('lightweight',
 
636
                            help="perform a lightweight checkout. Lightweight "
 
637
                                 "checkouts depend on access to the branch for "
 
638
                                 "every operation. Normal checkouts can perform "
 
639
                                 "common operations like diff and status without "
 
640
                                 "such access, and also support local commits."
 
641
                            ),
 
642
                     ]
634
643
 
635
 
    def run(self, branch_location, to_location=None, revision=None, basis=None):
 
644
    def run(self, branch_location, to_location=None, revision=None, basis=None,
 
645
            lightweight=False):
636
646
        if revision is None:
637
647
            revision = [None]
638
648
        elif len(revision) > 1:
656
666
                                      to_location)
657
667
            else:
658
668
                raise
659
 
        checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
660
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
661
 
        checkout.create_workingtree(revision_id)
 
669
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
 
670
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
671
        try:
 
672
            if lightweight:
 
673
                checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
 
674
                bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
675
            else:
 
676
                checkout_branch =  bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
677
                    to_location, force_new_tree=False)
 
678
                checkout = checkout_branch.bzrdir
 
679
                checkout_branch.bind(source)
 
680
                if revision_id is not None:
 
681
                    rh = checkout_branch.revision_history()
 
682
                    checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
 
683
            checkout.create_workingtree(revision_id)
 
684
        finally:
 
685
            bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
662
686
 
663
687
 
664
688
class cmd_renames(Command):
685
709
    """Update a tree to have the latest code committed to its branch.
686
710
    
687
711
    This will perform a merge into the working tree, and may generate
688
 
    conflicts. If you have any uncommitted changes, you will still 
689
 
    need to commit them after the update.
 
712
    conflicts. If you have any local changes, you will still 
 
713
    need to commit them after the update for the update to be complete.
 
714
    
 
715
    If you want to discard your local changes, you can just do a 
 
716
    'bzr revert' instead of 'bzr commit' after the update.
690
717
    """
691
718
    takes_args = ['dir?']
692
719
 
695
722
        tree.lock_write()
696
723
        try:
697
724
            if tree.last_revision() == tree.branch.last_revision():
698
 
                note("Tree is up to date.")
699
 
                return
 
725
                # may be up to date, check master too.
 
726
                master = tree.branch.get_master_branch()
 
727
                if master is None or master.last_revision == tree.last_revision():
 
728
                    note("Tree is up to date.")
 
729
                    return
700
730
            conflicts = tree.update()
701
731
            note('Updated to revision %d.' %
702
732
                 (tree.branch.revision_id_to_revno(tree.last_revision()),))
1385
1415
                     Option('strict',
1386
1416
                            help="refuse to commit if there are unknown "
1387
1417
                            "files in the working tree."),
 
1418
                     Option('local',
 
1419
                            help="perform a local only commit in a bound "
 
1420
                                 "branch. Such commits are not pushed to "
 
1421
                                 "the master branch until a normal commit "
 
1422
                                 "is performed."
 
1423
                            ),
1388
1424
                     ]
1389
1425
    aliases = ['ci', 'checkin']
1390
1426
 
1391
1427
    def run(self, message=None, file=None, verbose=True, selected_list=None,
1392
 
            unchanged=False, strict=False):
 
1428
            unchanged=False, strict=False, local=False):
1393
1429
        from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1394
1430
                StrictCommitFailed)
1395
1431
        from bzrlib.msgeditor import edit_commit_message, \
1406
1442
        # TODO: if the commit *does* happen to fail, then save the commit 
1407
1443
        # message to a temporary file where it can be recovered
1408
1444
        tree, selected_list = tree_files(selected_list)
 
1445
        if local and not tree.branch.get_bound_location():
 
1446
            raise errors.LocalRequiresBoundBranch()
1409
1447
        if message is None and not file:
1410
1448
            template = make_commit_message_template(tree, selected_list)
1411
1449
            message = edit_commit_message(template)
1424
1462
            
1425
1463
        try:
1426
1464
            tree.commit(message, specific_files=selected_list,
1427
 
                        allow_pointless=unchanged, strict=strict)
 
1465
                        allow_pointless=unchanged, strict=strict, local=local)
1428
1466
        except PointlessCommit:
1429
1467
            # FIXME: This should really happen before the file is read in;
1430
1468
            # perhaps prepare the commit; get the message; then actually commit
1436
1474
        except StrictCommitFailed:
1437
1475
            raise BzrCommandError("Commit refused because there are unknown "
1438
1476
                                  "files in the working tree.")
 
1477
        except errors.BoundBranchOutOfDate, e:
 
1478
            raise BzrCommandError(str(e)
 
1479
                                  + ' Either unbind, update, or'
 
1480
                                    ' pass --local to commit.')
 
1481
 
1439
1482
        note('Committed revision %d.' % (tree.branch.revno(),))
1440
1483
 
1441
1484
 
2122
2165
                raise BzrCommandError('Please supply either one revision, or a range.')
2123
2166
 
2124
2167
 
 
2168
class cmd_bind(Command):
 
2169
    """Bind the current branch to a master branch.
 
2170
 
 
2171
    After binding, commits must succeed on the master branch
 
2172
    before they are executed on the local one.
 
2173
    """
 
2174
 
 
2175
    takes_args = ['location']
 
2176
    takes_options = []
 
2177
 
 
2178
    def run(self, location=None):
 
2179
        b, relpath = Branch.open_containing(u'.')
 
2180
        b_other = Branch.open(location)
 
2181
        try:
 
2182
            b.bind(b_other)
 
2183
        except DivergedBranches:
 
2184
            raise BzrCommandError('These branches have diverged.'
 
2185
                                  ' Try merging, and then bind again.')
 
2186
 
 
2187
 
 
2188
class cmd_unbind(Command):
 
2189
    """Bind the current branch to its parent.
 
2190
 
 
2191
    After unbinding, the local branch is considered independent.
 
2192
    """
 
2193
 
 
2194
    takes_args = []
 
2195
    takes_options = []
 
2196
 
 
2197
    def run(self):
 
2198
        b, relpath = Branch.open_containing(u'.')
 
2199
        if not b.unbind():
 
2200
            raise BzrCommandError('Local branch is not bound')
 
2201
 
 
2202
 
2125
2203
class cmd_uncommit(bzrlib.commands.Command):
2126
2204
    """Remove the last committed revision.
2127
2205