721
721
' directory exists, but does not already'
722
722
' have a control directory. This flag will'
723
723
' allow push to proceed.'),
725
help='Create a stacked branch that references the public location '
726
'of the parent branch.'),
728
help='Create a stacked branch that refers to another branch '
729
'for the commit history. Only the work not present in the '
730
'referenced branch is included in the branch created.',
725
733
takes_args = ['location?']
726
734
encoding_type = 'replace'
728
736
def run(self, location=None, remember=False, overwrite=False,
729
create_prefix=False, verbose=False, revision=None,
730
use_existing_dir=False,
732
# FIXME: Way too big! Put this into a function called from the
737
create_prefix=False, verbose=False, revision=None,
738
use_existing_dir=False, directory=None, stacked_on=None,
740
from bzrlib.push import _show_push_branch
742
# Get the source branch and revision_id
734
743
if directory is None:
736
745
br_from = Branch.open_containing(directory)[0]
737
stored_loc = br_from.get_push_location()
739
if stored_loc is None:
740
raise errors.BzrCommandError("No push location known or specified.")
742
display_url = urlutils.unescape_for_display(stored_loc,
744
self.outf.write("Using saved location: %s\n" % display_url)
745
location = stored_loc
747
to_transport = transport.get_transport(location)
749
br_to = repository_to = dir_to = None
751
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
752
except errors.NotBranchError:
753
pass # Didn't find anything
755
# If we can open a branch, use its direct repository, otherwise see
756
# if there is a repository without a branch.
758
br_to = dir_to.open_branch()
759
except errors.NotBranchError:
760
# Didn't find a branch, can we find a repository?
762
repository_to = dir_to.find_repository()
763
except errors.NoRepositoryPresent:
766
# Found a branch, so we must have found a repository
767
repository_to = br_to.repository
769
746
if revision is not None:
770
747
if len(revision) == 1:
771
748
revision_id = revision[0].in_history(br_from).rev_id
776
753
revision_id = br_from.last_revision()
782
# The destination doesn't exist; create it.
783
# XXX: Refactor the create_prefix/no_create_prefix code into a
784
# common helper function
786
def make_directory(transport):
790
def redirected(redirected_transport, e, redirection_notice):
791
return transport.get_transport(e.get_target_url())
794
to_transport = transport.do_catching_redirections(
795
make_directory, to_transport, redirected)
796
except errors.FileExists:
797
if not use_existing_dir:
798
raise errors.BzrCommandError("Target directory %s"
799
" already exists, but does not have a valid .bzr"
800
" directory. Supply --use-existing-dir to push"
801
" there anyway." % location)
802
except errors.NoSuchFile:
803
if not create_prefix:
804
raise errors.BzrCommandError("Parent directory of %s"
806
"\nYou may supply --create-prefix to create all"
807
" leading parent directories."
809
_create_prefix(to_transport)
810
except errors.TooManyRedirections:
811
raise errors.BzrCommandError("Too many redirections trying "
812
"to make %s." % location)
814
# Now the target directory exists, but doesn't have a .bzr
815
# directory. So we need to create it, along with any work to create
816
# all of the dependent branches, etc.
817
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
818
revision_id=revision_id)
819
br_to = dir_to.open_branch()
820
# TODO: Some more useful message about what was copied
821
note('Created new branch.')
822
# We successfully created the target, remember it
823
if br_from.get_push_location() is None or remember:
824
br_from.set_push_location(br_to.base)
825
elif repository_to is None:
826
# we have a bzrdir but no branch or repository
827
# XXX: Figure out what to do other than complain.
828
raise errors.BzrCommandError("At %s you have a valid .bzr control"
829
" directory, but not a branch or repository. This is an"
830
" unsupported configuration. Please move the target directory"
831
" out of the way and try again."
834
# We have a repository but no branch, copy the revisions, and then
836
repository_to.fetch(br_from.repository, revision_id=revision_id)
837
br_to = br_from.clone(dir_to, revision_id=revision_id)
838
note('Created new branch.')
839
if br_from.get_push_location() is None or remember:
840
br_from.set_push_location(br_to.base)
841
else: # We have a valid to branch
842
# We were able to connect to the remote location, so remember it
843
# we don't need to successfully push because of possible divergence.
844
if br_from.get_push_location() is None or remember:
845
br_from.set_push_location(br_to.base)
847
old_rh = br_to.revision_history()
850
tree_to = dir_to.open_workingtree()
851
except errors.NotLocalUrl:
852
warning("This transport does not update the working "
853
"tree of: %s. See 'bzr help working-trees' for "
854
"more information." % br_to.base)
855
push_result = br_from.push(br_to, overwrite,
856
stop_revision=revision_id)
857
except errors.NoWorkingTree:
858
push_result = br_from.push(br_to, overwrite,
859
stop_revision=revision_id)
863
push_result = br_from.push(tree_to.branch, overwrite,
864
stop_revision=revision_id)
868
except errors.DivergedBranches:
869
raise errors.BzrCommandError('These branches have diverged.'
870
' Try using "merge" and then "push".')
871
if push_result is not None:
872
push_result.report(self.outf)
874
new_rh = br_to.revision_history()
877
from bzrlib.log import show_changed_revisions
878
show_changed_revisions(br_to, old_rh, new_rh,
881
# we probably did a clone rather than a push, so a message was
755
# Get the stacked_on branch, if any
756
if stacked_on is not None:
757
stacked_on = urlutils.normalize_url(stacked_on)
759
parent_url = br_from.get_parent()
761
parent = Branch.open(parent_url)
762
stacked_on = parent.get_public_branch()
764
# I considered excluding non-http url's here, thus forcing
765
# 'public' branches only, but that only works for some
766
# users, so it's best to just depend on the user spotting an
767
# error by the feedback given to them. RBC 20080227.
768
stacked_on = parent_url
770
raise errors.BzrCommandError(
771
"Could not determine branch to refer to.")
773
# Get the destination location
775
stored_loc = br_from.get_push_location()
776
if stored_loc is None:
777
raise errors.BzrCommandError(
778
"No push location known or specified.")
780
display_url = urlutils.unescape_for_display(stored_loc,
782
self.outf.write("Using saved location: %s\n" % display_url)
783
location = stored_loc
785
_show_push_branch(br_from, revision_id, location, self.outf,
786
verbose=verbose, overwrite=overwrite, remember=remember,
787
stacked_on=stacked_on, create_prefix=create_prefix,
788
use_existing_dir=use_existing_dir)
886
791
class cmd_branch(Command):
939
849
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
940
850
possible_transports=[to_transport],
941
851
accelerator_tree=accelerator_tree,
852
hardlink=hardlink, stacked=stacked)
943
853
branch = dir.open_branch()
944
854
except errors.NoSuchRevision:
945
855
to_transport.delete_tree('.')
946
msg = "The branch %s has no revision %s." % (from_location, revision[0])
856
msg = "The branch %s has no revision %s." % (from_location,
947
858
raise errors.BzrCommandError(msg)
948
859
_merge_tags_if_possible(br_from, branch)
949
note('Branched %d revision(s).' % branch.revno())
860
# If the source branch is stacked, the new branch may
861
# be stacked whether we asked for that explicitly or not.
862
# We therefore need a try/except here and not just 'if stacked:'
864
note('Created new stacked branch referring to %s.' %
865
branch.get_stacked_on_url())
866
except (errors.NotStacked, errors.UnstackableBranchFormat,
867
errors.UnstackableRepositoryFormat), e:
868
note('Branched %d revision(s).' % branch.revno())
1936
1855
class cmd_ignore(Command):
1937
1856
"""Ignore specified files or patterns.
1858
See ``bzr help patterns`` for details on the syntax of patterns.
1939
1860
To remove patterns from the ignore list, edit the .bzrignore file.
1941
Trailing slashes on patterns are ignored.
1942
If the pattern contains a slash or is a regular expression, it is compared
1943
to the whole path from the branch root. Otherwise, it is compared to only
1944
the last component of the path. To match a file only in the root
1945
directory, prepend './'.
1947
Ignore patterns specifying absolute paths are not allowed.
1949
Ignore patterns may include globbing wildcards such as::
1951
? - Matches any single character except '/'
1952
* - Matches 0 or more characters except '/'
1953
/**/ - Matches 0 or more directories in a path
1954
[a-z] - Matches a single character from within a group of characters
1956
Ignore patterns may also be Python regular expressions.
1957
Regular expression ignore patterns are identified by a 'RE:' prefix
1958
followed by the regular expression. Regular expression ignore patterns
1959
may not include named or numbered groups.
1861
After adding, editing or deleting that file either indirectly by
1862
using this command or directly by using an editor, be sure to commit
1961
1865
Note: ignore patterns containing shell wildcards must be quoted from
1962
1866
the shell on Unix.
4524
4405
If none of these is available, --bind-to must be specified.
4408
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
4527
4409
takes_args = ['location?']
4528
4410
takes_options = [RegistryOption.from_kwargs('target_type',
4529
4411
title='Target type',
4530
4412
help='The type to reconfigure the directory to.',
4531
4413
value_switches=True, enum_switch=False,
4532
branch='Reconfigure to a branch.',
4533
tree='Reconfigure to a tree.',
4534
checkout='Reconfigure to a checkout.',
4535
lightweight_checkout='Reconfigure to a lightweight'
4537
standalone='Reconfigure to be standalone.',
4414
branch='Reconfigure to be an unbound branch '
4415
'with no working tree.',
4416
tree='Reconfigure to be an unbound branch '
4417
'with a working tree.',
4418
checkout='Reconfigure to be a bound branch '
4419
'with a working tree.',
4420
lightweight_checkout='Reconfigure to be a lightweight'
4421
' checkout (with no local history).',
4422
standalone='Reconfigure to be a standalone branch '
4423
'(i.e. stop using shared repository).',
4538
4424
use_shared='Reconfigure to use a shared repository.'),
4539
4425
Option('bind-to', help='Branch to bind checkout to.',