697
697
' directory exists, but does not already'
698
698
' have a control directory. This flag will'
699
699
' allow push to proceed.'),
701
help='Create a shallow branch that only refers to another branch '
702
'for the commit history. Only the work not present in that '
703
'other branch is included in this shallow branch.',
706
help='Create a shallow branch with an automatic reference url. '
707
'The chosen url is the parent branches public location. See '
708
'--reference for more information.'),
701
710
takes_args = ['location?']
702
711
encoding_type = 'replace'
704
713
def run(self, location=None, remember=False, overwrite=False,
705
create_prefix=False, verbose=False,
706
use_existing_dir=False,
714
create_prefix=False, verbose=False, use_existing_dir=False,
715
directory=None, reference=None, shallow=False):
708
716
# FIXME: Way too big! Put this into a function called from the
710
718
if directory is None:
712
720
br_from = Branch.open_containing(directory)[0]
721
# shallow branch where to refer to logic:
722
if reference is not None:
723
reference = urlutils.normalize_url(reference)
726
parent_url = br_from.get_parent()
728
parent = Branch.open(parent_url)
729
reference = parent.get_public_branch()
731
# I considered excluding non-http url's here, thus forcing
732
# 'public' branches only, but that only works for some
733
# users, so its best to just depend on the user spotting an
734
# error by the feedback given to them. RBC 20080227.
735
reference = parent_url
737
raise errors.BzrCommandError(
738
"Could not determine branch to refer to.")
739
# where to push logic:
713
740
stored_loc = br_from.get_push_location()
714
741
if location is None:
715
742
if stored_loc is None:
780
807
# Now the target directory exists, but doesn't have a .bzr
781
808
# directory. So we need to create it, along with any work to create
782
809
# all of the dependent branches, etc.
783
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
784
revision_id=br_from.last_revision())
810
if reference is not None:
811
# This should be buried in the clone method itself. TODO.
813
# if the from format is stackable, this will either work or
814
# trigger NotStacked. If its not an error will be given to
816
br_from.get_stacked_on()
817
except errors.NotStacked:
819
# now we need to sprout the repository,
820
dir_to = br_from.bzrdir._format.initialize_on_transport(to_transport)
821
br_from.repository._format.initialize(dir_to)
822
br_to = br_from._format.initialize(dir_to)
823
br_to.set_stacked_on(reference)
824
# and copy the data up.
827
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
828
revision_id=br_from.last_revision())
785
829
br_to = dir_to.open_branch()
786
830
# TODO: Some more useful message about what was copied
787
note('Created new branch.')
831
if reference is not None:
832
note('Created new shallow branch referring to %s.' % reference)
834
note('Created new branch.')
788
835
# We successfully created the target, remember it
789
836
if br_from.get_push_location() is None or remember:
790
837
br_from.set_push_location(br_to.base)
865
912
_see_also = ['checkout']
866
913
takes_args = ['from_location', 'to_location?']
867
914
takes_options = ['revision', Option('hardlink',
868
help='Hard-link working tree files where possible.')]
915
help='Hard-link working tree files where possible.'),
917
help='Create a shallow branch referring to the source branch. '
918
'The new branch will depend on the availability of the source '
919
'branch for all operations.'),
869
921
aliases = ['get', 'clone']
871
923
def run(self, from_location, to_location=None, revision=None,
924
hardlink=False, shallow=False):
873
925
from bzrlib.tag import _merge_tags_if_possible
874
926
if revision is None:
875
927
revision = [None]
908
960
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
909
961
possible_transports=[to_transport],
910
962
accelerator_tree=accelerator_tree,
963
hardlink=hardlink, shallow=shallow)
912
964
branch = dir.open_branch()
913
965
except errors.NoSuchRevision:
914
966
to_transport.delete_tree('.')
918
970
branch.control_files.put_utf8('branch-name', name)
919
971
_merge_tags_if_possible(br_from, branch)
920
note('Branched %d revision(s).' % branch.revno())
973
note('Created new shallow branch referring to %s.' %
974
branch.get_stacked_on())
975
except (errors.NotStacked, errors.UnstackableBranchFormat,
976
errors.UnstackableRepositoryFormat), e:
977
note('Branched %d revision(s).' % branch.revno())