537
537
location can be accessed.
540
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
540
takes_options = ['remember', 'overwrite', 'revision', 'verbose',
542
help='branch to pull into, '
543
'rather than the one containing the working directory',
541
548
takes_args = ['location?']
542
549
encoding_type = 'replace'
544
551
def run(self, location=None, remember=False, overwrite=False,
545
revision=None, verbose=False):
552
revision=None, verbose=False,
546
554
# FIXME: too much stuff is in the command class
555
if directory is None:
548
tree_to = WorkingTree.open_containing(u'.')[0]
558
tree_to = WorkingTree.open_containing(directory)[0]
549
559
branch_to = tree_to.branch
550
560
except errors.NoWorkingTree:
552
branch_to = Branch.open_containing(u'.')[0]
562
branch_to = Branch.open_containing(directory)[0]
555
565
if location is not None:
634
643
takes_options = ['remember', 'overwrite', 'verbose',
635
Option('create-prefix',
636
help='Create the path leading up to the branch '
637
'if it does not already exist')]
644
Option('create-prefix',
645
help='Create the path leading up to the branch '
646
'if it does not already exist'),
648
help='branch to push from, '
649
'rather than the one containing the working directory',
653
Option('use-existing-dir',
654
help='By default push will fail if the target'
655
' directory exists, but does not already'
656
' have a control directory. This flag will'
657
' allow push to proceed.'),
638
659
takes_args = ['location?']
639
660
encoding_type = 'replace'
641
662
def run(self, location=None, remember=False, overwrite=False,
642
create_prefix=False, verbose=False):
663
create_prefix=False, verbose=False,
664
use_existing_dir=False,
643
666
# FIXME: Way too big! Put this into a function called from the
646
br_from = Branch.open_containing('.')[0]
668
if directory is None:
670
br_from = Branch.open_containing(directory)[0]
647
671
stored_loc = br_from.get_push_location()
648
672
if location is None:
649
673
if stored_loc is None:
658
682
location_url = to_transport.base
687
br_to = repository_to = dir_to = None
662
dir_to = bzrdir.BzrDir.open(location_url)
663
br_to = dir_to.open_branch()
689
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
664
690
except errors.NotBranchError:
666
to_transport = to_transport.clone('..')
667
if not create_prefix:
691
pass # Didn't find anything
693
# If we can open a branch, use its direct repository, otherwise see
694
# if there is a repository without a branch.
696
br_to = dir_to.open_branch()
697
except errors.NotBranchError:
698
# Didn't find a branch, can we find a repository?
669
relurl = to_transport.relpath(location_url)
670
mutter('creating directory %s => %s', location_url, relurl)
671
to_transport.mkdir(relurl)
672
except errors.NoSuchFile:
673
raise errors.BzrCommandError("Parent directory of %s "
674
"does not exist." % location)
700
repository_to = dir_to.find_repository()
701
except errors.NoRepositoryPresent:
676
current = to_transport.base
677
needed = [(to_transport, to_transport.relpath(location_url))]
704
# Found a branch, so we must have found a repository
705
repository_to = br_to.repository
709
# XXX: Refactor the create_prefix/no_create_prefix code into a
710
# common helper function
712
to_transport.mkdir('.')
713
except errors.FileExists:
714
if not use_existing_dir:
715
raise errors.BzrCommandError("Target directory %s"
716
" already exists, but does not have a valid .bzr"
717
" directory. Supply --use-existing-dir to push"
718
" there anyway." % location)
719
except errors.NoSuchFile:
720
if not create_prefix:
721
raise errors.BzrCommandError("Parent directory of %s"
723
"\nYou may supply --create-prefix to create all"
724
" leading parent directories."
727
cur_transport = to_transport
728
needed = [cur_transport]
729
# Recurse upwards until we can create a directory successfully
731
new_transport = cur_transport.clone('..')
732
if new_transport.base == cur_transport.base:
733
raise errors.BzrCommandError("Failed to create path"
737
new_transport.mkdir('.')
738
except errors.NoSuchFile:
739
needed.append(new_transport)
740
cur_transport = new_transport
744
# Now we only need to create child directories
680
to_transport, relpath = needed[-1]
681
to_transport.mkdir(relpath)
683
except errors.NoSuchFile:
684
new_transport = to_transport.clone('..')
685
needed.append((new_transport,
686
new_transport.relpath(to_transport.base)))
687
if new_transport.base == to_transport.base:
688
raise errors.BzrCommandError("Could not create "
746
cur_transport = needed.pop()
747
cur_transport.mkdir('.')
749
# Now the target directory exists, but doesn't have a .bzr
750
# directory. So we need to create it, along with any work to create
751
# all of the dependent branches, etc.
690
752
dir_to = br_from.bzrdir.clone(location_url,
691
753
revision_id=br_from.last_revision())
692
754
br_to = dir_to.open_branch()
694
756
# We successfully created the target, remember it
695
757
if br_from.get_push_location() is None or remember:
696
758
br_from.set_push_location(br_to.base)
759
elif repository_to is None:
760
# we have a bzrdir but no branch or repository
761
# XXX: Figure out what to do other than complain.
762
raise errors.BzrCommandError("At %s you have a valid .bzr control"
763
" directory, but not a branch or repository. This is an"
764
" unsupported configuration. Please move the target directory"
765
" out of the way and try again."
768
# We have a repository but no branch, copy the revisions, and then
770
last_revision_id = br_from.last_revision()
771
repository_to.fetch(br_from.repository,
772
revision_id=last_revision_id)
773
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
774
count = len(br_to.revision_history())
775
if br_from.get_push_location() is None or remember:
776
br_from.set_push_location(br_to.base)
777
else: # We have a valid to branch
698
778
# We were able to connect to the remote location, so remember it
699
779
# we don't need to successfully push because of possible divergence.
700
780
if br_from.get_push_location() is None or remember:
1125
1201
takes_args = ['location?']
1126
1202
takes_options = [
1127
RegistryOption('format',
1128
help='Specify a format for this branch. See "bzr '
1129
'help formats" for details',
1130
converter=bzrdir.format_registry.make_bzrdir,
1131
registry=bzrdir.format_registry,
1132
value_switches=True, title="Branch Format"),
1203
RegistryOption('format',
1204
help='Specify a format for this branch. '
1205
'See "help formats".',
1206
registry=bzrdir.format_registry,
1207
converter=bzrdir.format_registry.make_bzrdir,
1208
value_switches=True,
1209
title="Branch Format",
1134
1212
def run(self, location=None, format=None):
1135
1213
if format is None:
1136
1214
format = bzrdir.format_registry.make_bzrdir('default')
1448
1526
# find the file id to log:
1450
dir, fp = bzrdir.BzrDir.open_containing(location)
1451
b = dir.open_branch()
1528
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
1455
inv = dir.open_workingtree().inventory
1456
except (errors.NotBranchError, errors.NotLocalUrl):
1457
# either no tree, or is remote.
1458
inv = b.basis_tree().inventory
1532
tree = b.basis_tree()
1533
inv = tree.inventory
1459
1534
file_id = inv.path2id(fp)
1460
1535
if file_id is None:
1461
1536
raise errors.BzrCommandError(
2315
2394
takes_args = ['branch?']
2316
2395
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2317
Option('show-base', help="Show base revision text in "
2319
Option('uncommitted', help='Apply uncommitted changes'
2320
' from a working copy, instead of branch changes'),
2321
Option('pull', help='If the destination is already'
2322
' completely merged into the source, pull from the'
2323
' source rather than merging. When this happens,'
2324
' you do not need to commit the result.'),
2328
from inspect import getdoc
2329
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2396
Option('show-base', help="Show base revision text in "
2398
Option('uncommitted', help='Apply uncommitted changes'
2399
' from a working copy, instead of branch changes'),
2400
Option('pull', help='If the destination is already'
2401
' completely merged into the source, pull from the'
2402
' source rather than merging. When this happens,'
2403
' you do not need to commit the result.'),
2405
help='branch to merge into, '
2406
'rather than the one containing the working directory',
2331
2412
def run(self, branch=None, revision=None, force=False, merge_type=None,
2332
show_base=False, reprocess=False, remember=False,
2333
uncommitted=False, pull=False):
2413
show_base=False, reprocess=False, remember=False,
2414
uncommitted=False, pull=False,
2334
2417
if merge_type is None:
2335
2418
merge_type = _mod_merge.Merge3Merger
2337
tree = WorkingTree.open_containing(u'.')[0]
2420
if directory is None: directory = u'.'
2421
tree = WorkingTree.open_containing(directory)[0]
2338
2422
change_reporter = delta.ChangeReporter(tree.inventory)
2340
2424
if branch is not None: