~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-08-29 10:57:01 UTC
  • mfrom: (1092.1.41)
  • Revision ID: mbp@sourcefrog.net-20050829105701-7aaa81ecf1bfee05
- merge in merge improvements and additional tests 
  from aaron and lifeless

robertc@robertcollins.net-20050825131100-85772edabc817481

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
# would help with validation and shell completion.
28
28
 
29
29
 
 
30
# TODO: Help messages for options.
 
31
 
 
32
# TODO: Define arguments by objects, rather than just using names.
 
33
# Those objects can specify the expected type of the argument, which
 
34
# would help with validation and shell completion.
 
35
 
 
36
 
30
37
import sys
31
38
import os
32
39
 
469
476
    takes_options = ['verbose', 'no-recurse']
470
477
    
471
478
    def run(self, file_list, verbose=False, no_recurse=False):
472
 
        from bzrlib.add import smart_add
473
 
 
 
479
        from bzrlib.add import smart_add, _PrintAddCallback
474
480
        recurse = not no_recurse
475
 
        for path, kind, file_id in smart_add(file_list, verbose, recurse):
476
 
            print 'added', path
 
481
        smart_add(file_list, verbose, not no_recurse,
 
482
                  callback=_PrintAddCallback)
477
483
 
478
484
 
479
485
 
620
626
        import tempfile
621
627
        from shutil import rmtree
622
628
        import errno
 
629
        from bzrlib.branch import pull_loc
623
630
        
624
631
        br_to = find_branch('.')
625
632
        stored_loc = None
672
679
    aliases = ['get', 'clone']
673
680
 
674
681
    def run(self, from_location, to_location=None, revision=None):
 
682
        from bzrlib.branch import copy_branch, find_cached_branch
 
683
        import tempfile
675
684
        import errno
676
 
        from bzrlib.merge import merge
677
 
        from bzrlib.branch import DivergedBranches, \
678
 
             find_cached_branch, Branch
679
685
        from shutil import rmtree
680
 
        from meta_store import CachedStore
681
 
        import tempfile
682
686
        cache_root = tempfile.mkdtemp()
683
 
 
684
 
        if revision is None:
685
 
            revision = [None]
686
 
        elif len(revision) > 1:
687
 
            raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
688
 
 
689
687
        try:
 
688
            if revision is None:
 
689
                revision = [None]
 
690
            elif len(revision) > 1:
 
691
                raise BzrCommandError(
 
692
                    'bzr branch --revision takes exactly 1 revision value')
690
693
            try:
691
694
                br_from = find_cached_branch(from_location, cache_root)
692
695
            except OSError, e:
695
698
                                          ' exist.' % to_location)
696
699
                else:
697
700
                    raise
698
 
 
699
701
            if to_location is None:
700
702
                to_location = os.path.basename(from_location.rstrip("/\\"))
701
 
 
702
703
            try:
703
704
                os.mkdir(to_location)
704
705
            except OSError, e:
710
711
                                          to_location)
711
712
                else:
712
713
                    raise
713
 
            br_to = Branch(to_location, init=True)
714
 
 
715
 
            br_to.set_root_id(br_from.get_root_id())
716
 
 
717
 
            if revision:
718
 
                if revision[0] is None:
719
 
                    revno = br_from.revno()
720
 
                else:
721
 
                    revno, rev_id = br_from.get_revision_info(revision[0])
722
 
                try:
723
 
                    br_to.update_revisions(br_from, stop_revision=revno)
724
 
                except bzrlib.errors.NoSuchRevision:
725
 
                    rmtree(to_location)
726
 
                    msg = "The branch %s has no revision %d." % (from_location,
727
 
                                                                 revno)
728
 
                    raise BzrCommandError(msg)
729
 
 
730
 
            merge((to_location, -1), (to_location, 0), this_dir=to_location,
731
 
                  check_clean=False, ignore_zero=True)
732
 
            from_location = pull_loc(br_from)
733
 
            br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
714
            try:
 
715
                copy_branch(br_from, to_location, revision[0])
 
716
            except bzrlib.errors.NoSuchRevision:
 
717
                rmtree(to_location)
 
718
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
 
719
                raise BzrCommandError(msg)
734
720
        finally:
735
721
            rmtree(cache_root)
736
722
 
737
723
 
738
 
def pull_loc(branch):
739
 
    # TODO: Should perhaps just make attribute be 'base' in
740
 
    # RemoteBranch and Branch?
741
 
    if hasattr(branch, "baseurl"):
742
 
        return branch.baseurl
743
 
    else:
744
 
        return branch.base
745
 
 
746
 
 
747
 
 
748
724
class cmd_renames(Command):
749
725
    """Show list of renamed files.
750
726
 
1411
1387
class cmd_selftest(Command):
1412
1388
    """Run internal test suite"""
1413
1389
    hidden = True
1414
 
    takes_options = ['verbose']
1415
 
    def run(self, verbose=False):
 
1390
    takes_options = ['verbose', 'pattern']
 
1391
    def run(self, verbose=False, pattern=".*"):
1416
1392
        import bzrlib.ui
1417
1393
        from bzrlib.selftest import selftest
1418
 
 
1419
1394
        # we don't want progress meters from the tests to go to the
1420
1395
        # real output; and we don't want log messages cluttering up
1421
1396
        # the real logs.
1422
 
 
1423
1397
        save_ui = bzrlib.ui.ui_factory
1424
1398
        bzrlib.trace.info('running tests...')
1425
1399
        try:
1426
1400
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1427
 
            result = selftest(verbose=verbose)
 
1401
            result = selftest(verbose=verbose, pattern=pattern)
1428
1402
            if result:
1429
1403
                bzrlib.trace.info('tests passed')
1430
1404
            else:
1553
1527
            merge_type = ApplyMerge3
1554
1528
 
1555
1529
        if revision is None or len(revision) < 1:
1556
 
            base = (None, None)
 
1530
            base = [None, None]
1557
1531
            other = (branch, -1)
1558
1532
        else:
1559
1533
            if len(revision) == 1:
1583
1557
 
1584
1558
    def run(self, revision=None, no_backup=False, file_list=None):
1585
1559
        from bzrlib.merge import merge
 
1560
        from bzrlib.branch import Branch
1586
1561
        if file_list is not None:
1587
1562
            if len(file_list) == 0:
1588
1563
                raise BzrCommandError("No files specified")
1595
1570
              ignore_zero=True,
1596
1571
              backup_files=not no_backup,
1597
1572
              file_list=file_list)
 
1573
        if not file_list:
 
1574
            Branch('.').set_pending_merges([])
1598
1575
 
1599
1576
 
1600
1577
class cmd_assert_fail(Command):
1714
1691
    'root':                   str,
1715
1692
    'no-backup':              None,
1716
1693
    'merge-type':             get_merge_type,
 
1694
    'pattern':                str,
1717
1695
    }
1718
1696
 
1719
1697
SHORT_OPTIONS = {
1982
1960
 
1983
1961
def main(argv):
1984
1962
    import bzrlib.ui
1985
 
    
1986
1963
    bzrlib.trace.log_startup(argv)
1987
 
 
1988
1964
    bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
1989
1965
 
1990
1966
    try: