48
48
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
49
49
except errors.NotBranchError:
50
50
pass # Didn't find anything
52
# If we can open a branch, use its direct repository, otherwise see
53
# if there is a repository without a branch.
55
br_to = dir_to.open_branch()
56
except errors.NotBranchError:
57
# Didn't find a branch, can we find a repository?
59
repository_to = dir_to.find_repository()
60
except errors.NoRepositoryPresent:
63
# Found a branch, so we must have found a repository
64
repository_to = br_to.repository
116
102
finally_stacked_on)
118
104
note('Created new branch.')
119
# We successfully created the target, remember it
120
if br_from.get_push_location() is None or remember:
121
br_from.set_push_location(br_to.base)
122
elif repository_to is None:
123
# we have a bzrdir but no branch or repository
124
# XXX: Figure out what to do other than complain.
125
raise errors.BzrCommandError("At %s you have a valid .bzr control"
126
" directory, but not a branch or repository. This is an"
127
" unsupported configuration. Please move the target directory"
128
" out of the way and try again."
131
# We have a repository but no branch, copy the revisions, and then
133
106
if stacked_on is not None:
134
107
warning("Ignoring request for a stacked branch as repository "
135
108
"already exists at the destination location.")
136
repository_to.fetch(br_from.repository, revision_id=revision_id)
137
br_to = br_from.clone(dir_to, revision_id=revision_id)
138
note('Created new branch.')
139
if br_from.get_push_location() is None or remember:
140
br_from.set_push_location(br_to.base)
141
else: # We have a valid to branch
142
if stacked_on is not None:
143
warning("Ignoring request for a stacked branch as branch "
144
"already exists at the destination location.")
145
# We were able to connect to the remote location, so remember it.
146
# (We don't need to successfully push because of possible divergence.)
147
if br_from.get_push_location() is None or remember:
148
br_from.set_push_location(br_to.base)
109
inter = branch.InterBranchBzrDir.get(br_from, dir_to)
151
tree_to = dir_to.open_workingtree()
152
except errors.NotLocalUrl:
153
warning("This transport does not update the working "
154
"tree of: %s. See 'bzr help working-trees' for "
155
"more information." % br_to.base)
156
push_result = br_from.push(br_to, overwrite,
157
stop_revision=revision_id)
158
except errors.NoWorkingTree:
159
push_result = br_from.push(br_to, overwrite,
160
stop_revision=revision_id)
164
push_result = br_from.push(tree_to.branch, overwrite,
165
stop_revision=revision_id)
111
push_result = inter.push(revision_id=revision_id,
113
except errors.NoRepositoryPresent:
114
# we have a bzrdir but no branch or repository
115
# XXX: Figure out what to do other than complain.
116
raise errors.BzrCommandError("At %s you have a valid .bzr control"
117
" directory, but not a branch or repository. This is an"
118
" unsupported configuration. Please move the target directory"
119
" out of the way and try again."
169
121
except errors.DivergedBranches:
170
122
raise errors.BzrCommandError('These branches have diverged.'
171
123
' Try using "merge" and then "push".')
124
if not push_result.workingtree_updated:
125
warning("This transport does not update the working "
126
"tree of: %s. See 'bzr help working-trees' for "
127
"more information." % push_result.target_branch.base)
129
# We successfully pushed, remember it
130
if push_result.source_branch.get_push_location() is None or remember:
131
push_result.source_branch.set_push_location(push_result.target_branch.base)
172
133
if push_result is not None:
173
134
push_result.report(to_file)
174
135
old_revid = push_result.old_revid
175
136
old_revno = push_result.old_revno
137
br_to = push_result.target_branch
177
139
old_revid = _mod_revision.NULL_REVISION