49
47
"""Write a human-readable description of the result."""
50
48
if self.branch_push_result is None:
51
49
if self.stacked_on is not None:
52
note(gettext('Created new stacked branch referring to %s.') %
50
note('Created new stacked branch referring to %s.' %
55
note(gettext('Created new branch.'))
53
note('Created new branch.')
57
55
self.branch_push_result.report(to_file)
60
58
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
61
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
62
use_existing_dir=False, no_tree=False, lossy=False):
59
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
60
use_existing_dir=False, no_tree=False):
63
61
"""Push a branch to a location.
65
63
:param br_from: the source branch
67
65
:param location: the url of the destination
68
66
:param to_file: the output stream
69
67
:param verbose: if True, display more output than normal
70
:param overwrite: list of things to overwrite ("history", "tags")
71
or boolean indicating for everything
68
:param overwrite: if False, a current branch at the destination may not
69
have diverged from the source, otherwise the push fails
72
70
:param remember: if True, store the location as the push location for
74
72
:param stacked_on: the url of the branch, if any, to stack on;
76
74
:param create_prefix: if True, create the necessary parent directories
77
75
at the destination if they don't already exist
78
76
:param use_existing_dir: if True, proceed even if the destination
79
directory exists without a current control directory in it
80
:param lossy: Allow lossy push
77
directory exists without a current .bzr directory in it
82
to_transport = transport.get_transport(location, purpose='write')
79
to_transport = transport.get_transport(location)
84
dir_to = controldir.ControlDir.open_from_transport(to_transport)
81
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
85
82
except errors.NotBranchError:
86
83
# Didn't find anything
91
88
br_to = br_from.create_clone_on_transport(to_transport,
92
revision_id=revision_id, stacked_on=stacked_on,
93
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
95
except errors.AlreadyControlDirError:
96
raise errors.CommandError(gettext(
97
"Target directory %s already contains a .bzr directory, "
98
"but it is not valid.") % (location,))
99
except errors.FileExists:
89
revision_id=revision_id, stacked_on=stacked_on,
90
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
92
except errors.FileExists, err:
93
if err.path.endswith('/.bzr'):
94
raise errors.BzrCommandError(
95
"Target directory %s already contains a .bzr directory, "
96
"but it is not valid." % (location,))
100
97
if not use_existing_dir:
101
raise errors.CommandError(gettext("Target directory %s"
102
" already exists, but does not have a .bzr"
103
" directory. Supply --use-existing-dir to push"
104
" there anyway.") % location)
98
raise errors.BzrCommandError("Target directory %s"
99
" already exists, but does not have a .bzr"
100
" directory. Supply --use-existing-dir to push"
101
" there anyway." % location)
105
102
# This shouldn't occur, but if it does the FileExists error will be
106
103
# more informative than an UnboundLocalError for br_to.
108
105
except errors.NoSuchFile:
109
106
if not create_prefix:
110
raise errors.CommandError(gettext("Parent directory of %s"
112
"\nYou may supply --create-prefix to create all"
113
" leading parent directories.")
107
raise errors.BzrCommandError("Parent directory of %s"
109
"\nYou may supply --create-prefix to create all"
110
" leading parent directories."
115
112
# This shouldn't occur (because create_prefix is true, so
116
113
# create_clone_on_transport should be catching NoSuchFile and
117
114
# creating the missing directories) but if it does the original
119
116
# UnboundLocalError for br_to.
121
118
except errors.TooManyRedirections:
122
raise errors.CommandError(gettext("Too many redirections trying "
123
"to make %s.") % location)
119
raise errors.BzrCommandError("Too many redirections trying "
120
"to make %s." % location)
124
121
push_result = PushResult()
125
122
# TODO: Some more useful message about what was copied
127
124
push_result.stacked_on = br_to.get_stacked_on_url()
128
except (_mod_branch.UnstackableBranchFormat,
125
except (errors.UnstackableBranchFormat,
129
126
errors.UnstackableRepositoryFormat,
130
127
errors.NotStacked):
131
128
push_result.stacked_on = None
134
131
push_result.old_revno = 0
135
132
# Remembers if asked explicitly or no previous location is set
137
or (remember is None and br_from.get_push_location() is None)):
138
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
134
or (remember is None and br_from.get_push_location() is None)):
139
135
br_from.set_push_location(br_to.base)
141
137
if stacked_on is not None:
142
138
warning("Ignoring request for a stacked branch as repository "
143
139
"already exists at the destination location.")
145
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
remember, create_prefix, lossy=lossy)
141
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
142
remember, create_prefix)
147
143
except errors.DivergedBranches:
148
raise errors.CommandError(gettext('These branches have diverged.'
149
' See "brz help diverged-branches"'
150
' for more information.'))
151
except errors.NoRoundtrippingSupport as e:
152
raise errors.CommandError(
153
gettext("It is not possible to losslessly "
154
"push to %s. You may want to use --lossy.") %
155
e.target_branch.mapping.vcs.abbreviation)
144
raise errors.BzrCommandError('These branches have diverged.'
145
' See "bzr help diverged-branches"'
146
' for more information.')
147
except errors.NoRoundtrippingSupport, e:
148
raise errors.BzrCommandError("It is not possible to losslessly "
149
"push to %s. You may want to use dpush instead." %
150
e.target_branch.mapping.vcs.abbreviation)
156
151
except errors.NoRepositoryPresent:
157
# we have a controldir but no branch or repository
152
# we have a bzrdir but no branch or repository
158
153
# XXX: Figure out what to do other than complain.
159
raise errors.CommandError(gettext("At %s you have a valid .bzr"
160
" control directory, but not a branch or repository. This"
161
" is an unsupported configuration. Please move the target"
162
" directory out of the way and try again.") % location)
163
if push_result.workingtree_updated is False:
164
warning("This transport does not update the working "
165
"tree of: %s. See 'brz help working-trees' for "
154
raise errors.BzrCommandError("At %s you have a valid .bzr"
155
" control directory, but not a branch or repository. This"
156
" is an unsupported configuration. Please move the target"
157
" directory out of the way and try again." % location)
158
if push_result.workingtree_updated == False:
159
warning("This transport does not update the working "
160
"tree of: %s. See 'bzr help working-trees' for "
166
161
"more information." % push_result.target_branch.base)
167
162
push_result.report(to_file)
169
164
br_to = push_result.target_branch
170
with br_to.lock_read():
171
from .log import show_branch_change
172
show_branch_change(br_to, to_file, push_result.old_revno,
167
from bzrlib.log import show_branch_change
168
show_branch_change(br_to, to_file, push_result.old_revno,
173
169
push_result.old_revid)