~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
630
630
    """
631
631
 
632
632
    takes_options = ['remember', 'overwrite', 'verbose',
633
 
                     Option('create-prefix', 
 
633
                     Option('create-prefix',
634
634
                            help='Create the path leading up to the branch '
635
 
                                 'if it does not already exist')]
 
635
                                 'if it does not already exist'),
 
636
                     Option('use-existing-dir',
 
637
                            help='By default push will fail if the target'
 
638
                                 ' directory exists, but does not already'
 
639
                                 ' have a control directory. This flag will'
 
640
                                 ' allow push to proceed.'),
 
641
                     ]
636
642
    takes_args = ['location?']
637
643
    encoding_type = 'replace'
638
644
 
639
645
    def run(self, location=None, remember=False, overwrite=False,
640
 
            create_prefix=False, verbose=False):
 
646
            create_prefix=False, verbose=False, use_existing_dir=False):
641
647
        # FIXME: Way too big!  Put this into a function called from the
642
648
        # command.
643
649
        
656
662
        location_url = to_transport.base
657
663
 
658
664
        old_rh = []
 
665
        count = 0
 
666
 
 
667
        br_to = repository_to = dir_to = None
659
668
        try:
660
 
            dir_to = bzrdir.BzrDir.open(location_url)
661
 
            br_to = dir_to.open_branch()
 
669
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
662
670
        except errors.NotBranchError:
663
 
            # create a branch.
664
 
            to_transport = to_transport.clone('..')
665
 
            if not create_prefix:
 
671
            pass # Didn't find anything
 
672
        else:
 
673
            # If we can open a branch, use its direct repository, otherwise see
 
674
            # if there is a repository without a branch.
 
675
            try:
 
676
                br_to = dir_to.open_branch()
 
677
            except errors.NotBranchError:
 
678
                # Didn't find a branch, can we find a repository?
666
679
                try:
667
 
                    relurl = to_transport.relpath(location_url)
668
 
                    mutter('creating directory %s => %s', location_url, relurl)
669
 
                    to_transport.mkdir(relurl)
670
 
                except errors.NoSuchFile:
671
 
                    raise errors.BzrCommandError("Parent directory of %s "
672
 
                                                 "does not exist." % location)
 
680
                    repository_to = dir_to.find_repository()
 
681
                except errors.NoRepositoryPresent:
 
682
                    pass
673
683
            else:
674
 
                current = to_transport.base
675
 
                needed = [(to_transport, to_transport.relpath(location_url))]
 
684
                # Found a branch, so we must have found a repository
 
685
                repository_to = br_to.repository
 
686
 
 
687
        old_rh = []
 
688
        if dir_to is None:
 
689
            # XXX: Refactor the create_prefix/no_create_prefix code into a
 
690
            #      common helper function
 
691
            try:
 
692
                to_transport.mkdir('.')
 
693
            except errors.FileExists:
 
694
                if not use_existing_dir:
 
695
                    raise errors.BzrCommandError("Target directory %s"
 
696
                         " already exists, but does not have a valid .bzr"
 
697
                         " directory. Supply --use-existing-dir to push"
 
698
                         " there anyway." % location)
 
699
            except errors.NoSuchFile:
 
700
                if not create_prefix:
 
701
                    raise errors.BzrCommandError("Parent directory of %s"
 
702
                        " does not exist."
 
703
                        "\nYou may supply --create-prefix to create all"
 
704
                        " leading parent directories."
 
705
                        % location)
 
706
 
 
707
                cur_transport = to_transport
 
708
                needed = [cur_transport]
 
709
                # Recurse upwards until we can create a directory successfully
 
710
                while True:
 
711
                    new_transport = cur_transport.clone('..')
 
712
                    if new_transport.base == cur_transport.base:
 
713
                        raise errors.BzrCommandError("Failed to create path"
 
714
                                                     " prefix for %s."
 
715
                                                     % location)
 
716
                    try:
 
717
                        new_transport.mkdir('.')
 
718
                    except errors.NoSuchFile:
 
719
                        needed.append(new_transport)
 
720
                        cur_transport = new_transport
 
721
                    else:
 
722
                        break
 
723
 
 
724
                # Now we only need to create child directories
676
725
                while needed:
677
 
                    try:
678
 
                        to_transport, relpath = needed[-1]
679
 
                        to_transport.mkdir(relpath)
680
 
                        needed.pop()
681
 
                    except errors.NoSuchFile:
682
 
                        new_transport = to_transport.clone('..')
683
 
                        needed.append((new_transport,
684
 
                                       new_transport.relpath(to_transport.base)))
685
 
                        if new_transport.base == to_transport.base:
686
 
                            raise errors.BzrCommandError("Could not create "
687
 
                                                         "path prefix.")
 
726
                    cur_transport = needed.pop()
 
727
                    cur_transport.mkdir('.')
 
728
            
 
729
            # Now the target directory exists, but doesn't have a .bzr
 
730
            # directory. So we need to create it, along with any work to create
 
731
            # all of the dependent branches, etc.
688
732
            dir_to = br_from.bzrdir.clone(location_url,
689
733
                revision_id=br_from.last_revision())
690
734
            br_to = dir_to.open_branch()
692
736
            # We successfully created the target, remember it
693
737
            if br_from.get_push_location() is None or remember:
694
738
                br_from.set_push_location(br_to.base)
695
 
        else:
 
739
        elif repository_to is None:
 
740
            # we have a bzrdir but no branch or repository
 
741
            # XXX: Figure out what to do other than complain.
 
742
            raise errors.BzrCommandError("At %s you have a valid .bzr control"
 
743
                " directory, but not a branch or repository. This is an"
 
744
                " unsupported configuration. Please move the target directory"
 
745
                " out of the way and try again."
 
746
                % location)
 
747
        elif br_to is None:
 
748
            # We have a repository but no branch, copy the revisions, and then
 
749
            # create a branch.
 
750
            last_revision_id = br_from.last_revision()
 
751
            repository_to.fetch(br_from.repository,
 
752
                                revision_id=last_revision_id)
 
753
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
 
754
            count = len(br_to.revision_history())
 
755
            if br_from.get_push_location() is None or remember:
 
756
                br_from.set_push_location(br_to.base)
 
757
        else: # We have a valid to branch
696
758
            # We were able to connect to the remote location, so remember it
697
759
            # we don't need to successfully push because of possible divergence.
698
760
            if br_from.get_push_location() is None or remember:
826
888
    --basis is to speed up checking out from remote branches.  When specified, it
827
889
    uses the inventory and file contents from the basis branch in preference to the
828
890
    branch being checked out.
 
891
 
 
892
    See "help checkouts" for more information on checkouts.
829
893
    """
830
894
    takes_args = ['branch_location?', 'to_location?']
831
895
    takes_options = ['revision', # , 'basis']
2322
2386
                             ' you do not need to commit the result.'),
2323
2387
                     ]
2324
2388
 
2325
 
    def help(self):
2326
 
        from inspect import getdoc
2327
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2328
 
 
2329
2389
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2330
2390
            show_base=False, reprocess=False, remember=False, 
2331
2391
            uncommitted=False, pull=False):
2459
2519
                     Option('show-base', help="Show base revision text in "
2460
2520
                            "conflicts")]
2461
2521
 
2462
 
    def help(self):
2463
 
        from inspect import getdoc
2464
 
        return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2465
 
 
2466
2522
    def run(self, file_list=None, merge_type=None, show_base=False,
2467
2523
            reprocess=False):
2468
2524
        if merge_type is None:
2850
2906
 
2851
2907
 
2852
2908
class cmd_bind(Command):
2853
 
    """Bind the current branch to a master branch.
2854
 
 
2855
 
    After binding, commits must succeed on the master branch
2856
 
    before they are executed on the local one.
 
2909
    """Convert the current branch into a checkout of the supplied branch.
 
2910
 
 
2911
    Once converted into a checkout, commits must succeed on the master branch
 
2912
    before they will be applied to the local branch.
 
2913
 
 
2914
    See "help checkouts" for more information on checkouts.
2857
2915
    """
2858
2916
 
2859
2917
    takes_args = ['location']
2870
2928
 
2871
2929
 
2872
2930
class cmd_unbind(Command):
2873
 
    """Unbind the current branch from its master branch.
2874
 
 
2875
 
    After unbinding, the local branch is considered independent.
2876
 
    All subsequent commits will be local.
 
2931
    """Convert the current checkout into a regular branch.
 
2932
 
 
2933
    After unbinding, the local branch is considered independent and subsequent
 
2934
    commits will be local only.
 
2935
 
 
2936
    See "help checkouts" for more information on checkouts.
2877
2937
    """
2878
2938
 
2879
2939
    takes_args = []