21
21
from bzrlib.trace import note, warning
24
class PushResult(object):
25
"""Result of a push operation.
27
:ivar branch_push_result: Result of a push between branches
28
:ivar stacked_on: URL of the branch on which the result is stacked
32
self.branch_push_result = None
33
self.stacked_on = None
35
def report(self, to_file):
36
"""Write a human-readable description of the result."""
37
if self.branch_push_result is None:
38
if self.stacked_on is not None:
39
note('Created new stacked branch referring to %s.' %
42
note('Created new branch.')
44
self.branch_push_result.report(to_file)
24
47
def _show_push_branch(br_from, revision_id, location, to_file, verbose=False,
25
48
overwrite=False, remember=False, stacked_on=None, create_prefix=False,
26
49
use_existing_dir=False):
63
86
# Found a branch, so we must have found a repository
64
87
repository_to = br_to.repository
89
push_result = PushResult()
68
91
# The destination doesn't exist; create it.
69
92
# XXX: Refactor the create_prefix/no_create_prefix code into a
105
128
revision_id=revision_id, stacked_on=stacked_on)
106
129
# TODO: Some more useful message about what was copied
108
finally_stacked_on = br_to.get_stacked_on_url()
131
push_result.stacked_on = br_to.get_stacked_on_url()
109
132
except (errors.UnstackableBranchFormat,
110
133
errors.UnstackableRepositoryFormat,
111
134
errors.NotStacked):
112
finally_stacked_on = None
113
if finally_stacked_on is not None:
114
note('Created new stacked branch referring to %s.' %
117
note('Created new branch.')
135
push_result.stacked_on = None
118
136
# We successfully created the target, remember it
119
137
if br_from.get_push_location() is None or remember:
120
138
br_from.set_push_location(br_to.base)
134
152
"already exists at the destination location.")
135
153
repository_to.fetch(br_from.repository, revision_id=revision_id)
136
154
br_to = br_from.clone(dir_to, revision_id=revision_id)
137
note('Created new branch.')
138
155
if br_from.get_push_location() is None or remember:
139
156
br_from.set_push_location(br_to.base)
140
157
else: # We have a valid to branch
150
167
tree_to = dir_to.open_workingtree()
151
168
except errors.NotLocalUrl:
152
169
note("This transport does not update the working "
153
"tree of: %s. See 'bzr help working-trees' for "
154
"more information." % br_to.base)
155
push_result = br_from.push(br_to, overwrite,
156
stop_revision=revision_id)
170
"tree of: %s. See 'bzr help working-trees' for "
171
"more information." % br_to.base)
172
push_result.branch_push_result = br_from.push(br_to, overwrite,
173
stop_revision=revision_id)
157
174
except errors.NoWorkingTree:
158
push_result = br_from.push(br_to, overwrite,
159
stop_revision=revision_id)
175
push_result.branch_push_result = br_from.push(br_to, overwrite,
176
stop_revision=revision_id)
161
178
tree_to.lock_write()
163
push_result = br_from.push(tree_to.branch, overwrite,
164
stop_revision=revision_id)
180
push_result.branch_push_result = br_from.push(tree_to.branch,
181
overwrite, stop_revision=revision_id)
168
185
except errors.DivergedBranches:
169
186
raise errors.BzrCommandError('These branches have diverged.'
170
187
' Try using "merge" and then "push".')
171
if push_result is not None:
172
push_result.report(to_file)
173
old_revid = push_result.old_revid
174
old_revno = push_result.old_revno
188
push_result.report(to_file)
189
if push_result.branch_push_result is not None:
190
old_revid = push_result.branch_push_result.old_revid
191
old_revno = push_result.branch_push_result.old_revno
176
193
old_revid = _mod_revision.NULL_REVISION