17
17
"""UI helper for the push command."""
20
branch as _mod_branch,
19
from __future__ import absolute_import
23
24
revision as _mod_revision,
27
from brzlib.trace import (
30
from .i18n import gettext
31
from brzlib.i18n import gettext
33
34
class PushResult(object):
60
61
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):
62
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
63
use_existing_dir=False, no_tree=False):
63
64
"""Push a branch to a location.
65
66
:param br_from: the source branch
76
77
:param create_prefix: if True, create the necessary parent directories
77
78
at the destination if they don't already exist
78
79
: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
80
directory exists without a current .bzr directory in it
82
to_transport = transport.get_transport(location, purpose='write')
82
to_transport = transport.get_transport(location)
84
84
dir_to = controldir.ControlDir.open_from_transport(to_transport)
85
85
except errors.NotBranchError:
91
91
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:
92
revision_id=revision_id, stacked_on=stacked_on,
93
create_prefix=create_prefix, use_existing_dir=use_existing_dir,
95
except errors.AlreadyControlDirError, err:
96
96
raise errors.BzrCommandError(gettext(
97
97
"Target directory %s already contains a .bzr directory, "
98
98
"but it is not valid.") % (location,))
99
except errors.FileExists:
99
except errors.FileExists, err:
100
100
if not use_existing_dir:
101
101
raise errors.BzrCommandError(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)
102
" already exists, but does not have a .bzr"
103
" directory. Supply --use-existing-dir to push"
104
" there anyway.") % location)
105
105
# This shouldn't occur, but if it does the FileExists error will be
106
106
# more informative than an UnboundLocalError for br_to.
108
108
except errors.NoSuchFile:
109
109
if not create_prefix:
110
110
raise errors.BzrCommandError(gettext("Parent directory of %s"
112
"\nYou may supply --create-prefix to create all"
113
" leading parent directories.")
112
"\nYou may supply --create-prefix to create all"
113
" leading parent directories.")
115
115
# This shouldn't occur (because create_prefix is true, so
116
116
# create_clone_on_transport should be catching NoSuchFile and
117
117
# creating the missing directories) but if it does the original
121
121
except errors.TooManyRedirections:
122
122
raise errors.BzrCommandError(gettext("Too many redirections trying "
123
"to make %s.") % location)
123
"to make %s.") % location)
124
124
push_result = PushResult()
125
125
# TODO: Some more useful message about what was copied
127
127
push_result.stacked_on = br_to.get_stacked_on_url()
128
except (_mod_branch.UnstackableBranchFormat,
128
except (errors.UnstackableBranchFormat,
129
129
errors.UnstackableRepositoryFormat,
130
130
errors.NotStacked):
131
131
push_result.stacked_on = None
142
142
warning("Ignoring request for a stacked branch as repository "
143
143
"already exists at the destination location.")
145
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
remember, create_prefix, lossy=lossy)
145
push_result = dir_to.push_branch(br_from, revision_id, overwrite,
146
remember, create_prefix)
147
147
except errors.DivergedBranches:
148
148
raise errors.BzrCommandError(gettext('These branches have diverged.'
149
' See "brz help diverged-branches"'
150
' for more information.'))
151
except errors.NoRoundtrippingSupport as e:
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)
149
' See "bzr help diverged-branches"'
150
' for more information.'))
151
except errors.NoRoundtrippingSupport, e:
152
raise errors.BzrCommandError(gettext("It is not possible to losslessly "
153
"push to %s. You may want to use dpush instead.") %
154
e.target_branch.mapping.vcs.abbreviation)
156
155
except errors.NoRepositoryPresent:
157
156
# we have a controldir but no branch or repository
158
157
# XXX: Figure out what to do other than complain.
159
158
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 is False:
164
warning("This transport does not update the working "
165
"tree of: %s. See 'brz help working-trees' for "
159
" control directory, but not a branch or repository. This"
160
" is an unsupported configuration. Please move the target"
161
" directory out of the way and try again.") % location)
162
if push_result.workingtree_updated == False:
163
warning("This transport does not update the working "
164
"tree of: %s. See 'bzr help working-trees' for "
166
165
"more information." % push_result.target_branch.base)
167
166
push_result.report(to_file)
169
168
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,
171
from brzlib.log import show_branch_change
172
show_branch_change(br_to, to_file, push_result.old_revno,
173
173
push_result.old_revid)