~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2005-10-30 14:56:26 UTC
  • Revision ID: robertc@robertcollins.net-20051030145626-2f57bd49824dd1d7
Add a --create-prefix to the new push command.

As part of this, some option parsing errors will raise 'BzrOptionError',
allowing granular detection for decorating commands. (Robert Collins).

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
 
from bzrlib.errors import DivergedBranches
 
30
from bzrlib.errors import DivergedBranches, NoSuchFile
31
31
from bzrlib.option import Option
32
32
from bzrlib.revisionspec import RevisionSpec
33
33
import bzrlib.trace
412
412
    do a merge (see bzr help merge) from the other branch, and commit that
413
413
    before doing a 'push --overwrite'.
414
414
    """
415
 
    takes_options = ['remember', 'overwrite']
 
415
    takes_options = ['remember', 'overwrite', 
 
416
                     Option('create-prefix', 
 
417
                            help='Create the path leading up to the branch '
 
418
                                 'if it does not already exist')]
416
419
    takes_args = ['location?']
417
420
 
418
 
    def run(self, location=None, remember=False, overwrite=False):
 
421
    def run(self, location=None, remember=False, overwrite=False,
 
422
            create_prefix=False):
419
423
        import errno
420
424
        from shutil import rmtree
421
425
        from bzrlib.transport import get_transport
433
437
        except NotBranchError:
434
438
            # create a branch.
435
439
            transport = get_transport(location).clone('..')
436
 
            transport.mkdir(transport.relpath(location))
 
440
            if not create_prefix:
 
441
                try:
 
442
                    transport.mkdir(transport.relpath(location))
 
443
                except NoSuchFile:
 
444
                    raise BzrCommandError("Parent directory of %s "
 
445
                                          "does not exist." % location)
 
446
            else:
 
447
                current = transport.base
 
448
                needed = [(transport, transport.relpath(location))]
 
449
                while needed:
 
450
                    try:
 
451
                        transport, relpath = needed[-1]
 
452
                        transport.mkdir(relpath)
 
453
                        needed.pop()
 
454
                    except NoSuchFile:
 
455
                        new_transport = transport.clone('..')
 
456
                        needed.append((new_transport,
 
457
                                       new_transport.relpath(transport.base)))
 
458
                        if new_transport.base == transport.base:
 
459
                            raise BzrCommandError("Could not creeate "
 
460
                                                  "path prefix.")
 
461
                        
 
462
            NoSuchFile
437
463
            br_to = Branch.initialize(location)
438
464
        try:
439
465
            br_to.pull(br_from, overwrite)