/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2009-04-20 04:19:45 UTC
  • mto: This revision was merged to the branch mainline in revision 4304.
  • Revision ID: robertc@robertcollins.net-20090420041945-qvim67wg99c3euki
Move directory checking for bzr push options into Branch.create_clone_on_transport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1134
1134
        return format
1135
1135
 
1136
1136
    def create_clone_on_transport(self, to_transport, revision_id=None,
1137
 
        stacked_on=None):
 
1137
        stacked_on=None, create_prefix=False, use_existing_dir=False):
1138
1138
        """Create a clone of this branch and its bzrdir.
1139
1139
 
1140
1140
        :param to_transport: The transport to clone onto.
1141
1141
        :param revision_id: The revision id to use as tip in the new branch.
1142
1142
            If None the tip is obtained from this branch.
1143
1143
        :param stacked_on: An optional URL to stack the clone on.
 
1144
        :param create_prefix: Create any missing directories leading up to
 
1145
            to_transport.
 
1146
        :param use_existing_dir: Use an existing directory if one exists.
1144
1147
        """
 
1148
        # The destination doesn't exist; create it.
 
1149
        # XXX: Refactor the create_prefix/no_create_prefix code into a
 
1150
        #      common helper function
 
1151
 
 
1152
        def make_directory(transport):
 
1153
            transport.mkdir('.')
 
1154
            return transport
 
1155
 
 
1156
        def redirected(transport, e, redirection_notice):
 
1157
            note(redirection_notice)
 
1158
            return transport._redirected_to(e.source, e.target)
 
1159
 
 
1160
        try:
 
1161
            to_transport = transport.do_catching_redirections(
 
1162
                make_directory, to_transport, redirected)
 
1163
        except errors.FileExists:
 
1164
            if not use_existing_dir:
 
1165
                raise errors.BzrCommandError("Target directory %s"
 
1166
                     " already exists, but does not have a valid .bzr"
 
1167
                     " directory. Supply --use-existing-dir to push"
 
1168
                     " there anyway." % to_transport.base)
 
1169
        except errors.NoSuchFile:
 
1170
            if not create_prefix:
 
1171
                raise errors.BzrCommandError("Parent directory of %s"
 
1172
                    " does not exist."
 
1173
                    "\nYou may supply --create-prefix to create all"
 
1174
                    " leading parent directories."
 
1175
                    % to_transport.base)
 
1176
            to_transport.create_prefix()
 
1177
        except errors.TooManyRedirections:
 
1178
            raise errors.BzrCommandError("Too many redirections trying "
 
1179
                                         "to make %s." % to_transport.base)
 
1180
 
 
1181
        # Now the target directory exists, but doesn't have a .bzr
 
1182
        # directory. So we need to create it, along with any work to create
 
1183
        # all of the dependent branches, etc.
1145
1184
        # XXX: Fix the bzrdir API to allow getting the branch back from the
1146
1185
        # clone call. Or something. 20090224 RBC/spiv.
 
1186
        if revision_id is None:
 
1187
            revision_id = self.last_revision()
1147
1188
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1148
1189
            revision_id=revision_id, stacked_on=stacked_on)
1149
1190
        return dir_to.open_branch()