62
59
# test push for failure without push location set
63
60
os.chdir('branch_a')
64
out = self.run_bzr('push', retcode=3)
61
out = self.runbzr('push', retcode=3)
65
62
self.assertEquals(out,
66
63
('','bzr: ERROR: No push location known or specified.\n'))
68
65
# test not remembered if cannot actually push
69
self.run_bzr('push ../path/which/doesnt/exist', retcode=3)
66
self.run_bzr('push', '../path/which/doesnt/exist', retcode=3)
70
67
out = self.run_bzr('push', retcode=3)
72
69
('', 'bzr: ERROR: No push location known or specified.\n'),
75
72
# test implicit --remember when no push location set, push fails
76
out = self.run_bzr('push ../branch_b', retcode=3)
73
out = self.run_bzr('push', '../branch_b', retcode=3)
77
74
self.assertEquals(out,
78
75
('','bzr: ERROR: These branches have diverged. '
79
76
'Try using "merge" and then "push".\n'))
94
91
self.assertEqual(path,
95
92
branch_b.bzrdir.root_transport.base)
96
93
# test explicit --remember
97
self.run_bzr('push ../branch_c --remember')
94
self.run_bzr('push', '../branch_c', '--remember')
98
95
self.assertEquals(branch_a.get_push_location(),
99
96
branch_c.bzrdir.root_transport.base)
101
98
def test_push_without_tree(self):
102
99
# bzr push from a branch that does not have a checkout should work.
103
100
b = self.make_branch('.')
104
out, err = self.run_bzr('push pushed-location')
101
out, err = self.run_bzr('push', 'pushed-location')
105
102
self.assertEqual('', out)
106
103
self.assertEqual('Created new branch.\n', err)
107
104
b2 = Branch.open('pushed-location')
166
163
self.build_tree(['filename'])
167
164
t.add('filename', 'funky-chars<>%&;"\'')
168
165
t.commit('commit filename')
169
self.run_bzr('push ../new-tree')
166
self.run_bzr('push', '../new-tree')
171
168
def test_push_dash_d(self):
172
169
t = self.make_branch_and_tree('from')
173
170
t.commit(allow_pointless=True,
174
171
message='first commit')
175
self.run_bzr('push -d from to-one')
172
self.runbzr('push -d from to-one')
176
173
self.failUnlessExists('to-one')
177
self.run_bzr('push -d %s %s'
174
self.runbzr('push -d %s %s'
178
175
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
179
176
self.failUnlessExists('to-two')
245
242
a_bzrdir = self.make_bzrdir('dir')
247
244
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
249
246
working_dir='tree')
251
def test_push_with_revisionspec(self):
252
"""We should be able to push a revision older than the tip."""
253
tree_from = self.make_branch_and_tree('from')
254
tree_from.commit("One.", rev_id="from-1")
255
tree_from.commit("Two.", rev_id="from-2")
257
self.run_bzr('push -r1 ../to', working_dir='from')
259
tree_to = WorkingTree.open('to')
260
repo_to = tree_to.branch.repository
261
self.assertTrue(repo_to.has_revision('from-1'))
262
self.assertFalse(repo_to.has_revision('from-2'))
263
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
266
"bzr: ERROR: bzr push --revision takes one value.\n",
267
'push -r0..2 ../to', working_dir='from')
270
class RedirectingMemoryTransport(MemoryTransport):
272
def mkdir(self, path, mode=None):
273
path = self.abspath(path)[len(self._scheme):]
274
if path == '/source':
275
raise errors.RedirectRequested(
276
path, self._scheme + '/target', is_permanent=True)
277
elif path == '/infinite-loop':
278
raise errors.RedirectRequested(
279
path, self._scheme + '/infinite-loop', is_permanent=True)
281
return super(RedirectingMemoryTransport, self).mkdir(
285
class RedirectingMemoryServer(MemoryServer):
288
self._dirs = {'/': None}
291
self._scheme = 'redirecting-memory+%s:///' % id(self)
292
register_transport(self._scheme, self._memory_factory)
294
def _memory_factory(self, url):
295
result = RedirectingMemoryTransport(url)
296
result._dirs = self._dirs
297
result._files = self._files
298
result._locks = self._locks
302
unregister_transport(self._scheme, self._memory_factory)
305
class TestPushRedirect(ExternalBase):
308
ExternalBase.setUp(self)
309
self.memory_server = RedirectingMemoryServer()
310
self.memory_server.setUp()
311
self.addCleanup(self.memory_server.tearDown)
313
# Make the branch and tree that we'll be pushing.
314
t = self.make_branch_and_tree('tree')
315
self.build_tree(['tree/file'])
319
def test_push_redirects_on_mkdir(self):
320
"""If the push requires a mkdir, push respects redirect requests.
322
This is added primarily to handle lp:/ URI support, so that users can
323
push to new branches by specifying lp:/ URIs.
326
destination_url = self.memory_server.get_url() + 'source'
327
self.run_bzr('push %s' % destination_url)
330
local_revision = Branch.open('tree').last_revision()
331
remote_revision = Branch.open(
332
self.memory_server.get_url() + 'target').last_revision()
333
self.assertEqual(remote_revision, local_revision)
335
def test_push_gracefully_handles_too_many_redirects(self):
336
"""Push fails gracefully if the mkdir generates a large number of
340
destination_url = self.memory_server.get_url() + 'infinite-loop'
341
out, err = self.run_bzr_error(
342
['Too many redirections trying to make %s\\.\n'
343
% re.escape(destination_url)],
344
'push %s' % destination_url, retcode=3)
346
self.assertEqual('', out)