62
60
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
63
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
64
use_existing_dir=False, no_tree=False):
61
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
62
use_existing_dir=False, no_tree=False, lossy=False):
65
63
"""Push a branch to a location.
67
65
:param br_from: the source branch
79
77
at the destination if they don't already exist
80
78
:param use_existing_dir: if True, proceed even if the destination
81
79
directory exists without a current control directory in it
80
:param lossy: Allow lossy push
83
to_transport = transport.get_transport(location)
82
to_transport = transport.get_transport(location, purpose='write')
85
84
dir_to = controldir.ControlDir.open_from_transport(to_transport)
86
85
except errors.NotBranchError:
92
91
br_to = br_from.create_clone_on_transport(to_transport,
93
revision_id=revision_id, stacked_on=stacked_on,
94
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
96
except errors.AlreadyControlDirError as err:
92
revision_id=revision_id, stacked_on=stacked_on,
93
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
95
except errors.AlreadyControlDirError:
97
96
raise errors.BzrCommandError(gettext(
98
97
"Target directory %s already contains a .bzr directory, "
99
98
"but it is not valid.") % (location,))
100
except errors.FileExists as err:
99
except errors.FileExists:
101
100
if not use_existing_dir:
102
101
raise errors.BzrCommandError(gettext("Target directory %s"
103
" already exists, but does not have a .bzr"
104
" directory. Supply --use-existing-dir to push"
105
" there anyway.") % location)
102
" already exists, but does not have a .bzr"
103
" directory. Supply --use-existing-dir to push"
104
" there anyway.") % location)
106
105
# This shouldn't occur, but if it does the FileExists error will be
107
106
# more informative than an UnboundLocalError for br_to.
109
108
except errors.NoSuchFile:
110
109
if not create_prefix:
111
110
raise errors.BzrCommandError(gettext("Parent directory of %s"
113
"\nYou may supply --create-prefix to create all"
114
" leading parent directories.")
112
"\nYou may supply --create-prefix to create all"
113
" leading parent directories.")
116
115
# This shouldn't occur (because create_prefix is true, so
117
116
# create_clone_on_transport should be catching NoSuchFile and
118
117
# creating the missing directories) but if it does the original
135
134
push_result.old_revno = 0
136
135
# Remembers if asked explicitly or no previous location is set
138
or (remember is None and br_from.get_push_location() is None)):
137
or (remember is None and br_from.get_push_location() is None)):
139
138
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
140
139
br_from.set_push_location(br_to.base)
143
142
warning("Ignoring request for a stacked branch as repository "
144
143
"already exists at the destination location.")
146
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
147
remember, create_prefix)
145
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
remember, create_prefix, lossy=lossy)
148
147
except errors.DivergedBranches:
149
148
raise errors.BzrCommandError(gettext('These branches have diverged.'
150
' See "brz help diverged-branches"'
151
' for more information.'))
149
' See "brz help diverged-branches"'
150
' for more information.'))
152
151
except errors.NoRoundtrippingSupport as e:
153
raise errors.BzrCommandError(gettext("It is not possible to losslessly "
154
"push to %s. You may want to use dpush instead.") %
155
e.target_branch.mapping.vcs.abbreviation)
152
raise errors.BzrCommandError(
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)
156
156
except errors.NoRepositoryPresent:
157
157
# we have a controldir but no branch or repository
158
158
# XXX: Figure out what to do other than complain.
159
159
raise errors.BzrCommandError(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 == False:
164
warning("This transport does not update the working "
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
165
"tree of: %s. See 'brz help working-trees' for "
166
166
"more information." % push_result.target_branch.base)
167
167
push_result.report(to_file)
169
169
br_to = push_result.target_branch
170
with br_to.lock_read():
172
171
from .log import show_branch_change
173
show_branch_change(br_to, to_file, push_result.old_revno,
172
show_branch_change(br_to, to_file, push_result.old_revno,
174
173
push_result.old_revid)