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.'),
636
642
takes_args = ['location?']
637
643
encoding_type = 'replace'
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
656
662
location_url = to_transport.base
667
br_to = repository_to = dir_to = None
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:
664
to_transport = to_transport.clone('..')
665
if not create_prefix:
671
pass # Didn't find anything
673
# If we can open a branch, use its direct repository, otherwise see
674
# if there is a repository without a branch.
676
br_to = dir_to.open_branch()
677
except errors.NotBranchError:
678
# Didn't find a branch, can we find a repository?
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:
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
689
# XXX: Refactor the create_prefix/no_create_prefix code into a
690
# common helper function
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"
703
"\nYou may supply --create-prefix to create all"
704
" leading parent directories."
707
cur_transport = to_transport
708
needed = [cur_transport]
709
# Recurse upwards until we can create a directory successfully
711
new_transport = cur_transport.clone('..')
712
if new_transport.base == cur_transport.base:
713
raise errors.BzrCommandError("Failed to create path"
717
new_transport.mkdir('.')
718
except errors.NoSuchFile:
719
needed.append(new_transport)
720
cur_transport = new_transport
724
# Now we only need to create child directories
678
to_transport, relpath = needed[-1]
679
to_transport.mkdir(relpath)
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 "
726
cur_transport = needed.pop()
727
cur_transport.mkdir('.')
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)
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."
748
# We have a repository but no branch, copy the revisions, and then
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:
2322
2386
' you do not need to commit the result.'),
2326
from inspect import getdoc
2327
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
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):