59
58
class TestCommands(ExternalBase):
61
60
def test_invalid_commands(self):
62
self.runbzr("pants", retcode=3)
63
self.runbzr("--pants off", retcode=3)
64
self.runbzr("diff --message foo", retcode=3)
61
self.run_bzr("pants", retcode=3)
62
self.run_bzr("--pants off", retcode=3)
63
self.run_bzr("diff --message foo", retcode=3)
66
65
def test_revert(self):
69
68
file('hello', 'wt').write('foo')
70
self.runbzr('add hello')
71
self.runbzr('commit -m setup hello')
69
self.run_bzr('add hello')
70
self.run_bzr('commit -m setup hello')
73
72
file('goodbye', 'wt').write('baz')
74
self.runbzr('add goodbye')
75
self.runbzr('commit -m setup goodbye')
73
self.run_bzr('add goodbye')
74
self.run_bzr('commit -m setup goodbye')
77
76
file('hello', 'wt').write('bar')
78
77
file('goodbye', 'wt').write('qux')
79
self.runbzr('revert hello')
78
self.run_bzr('revert hello')
80
79
self.check_file_contents('hello', 'foo')
81
80
self.check_file_contents('goodbye', 'qux')
81
self.run_bzr('revert')
83
82
self.check_file_contents('goodbye', 'baz')
85
84
os.mkdir('revertdir')
86
self.runbzr('add revertdir')
87
self.runbzr('commit -m f')
85
self.run_bzr('add revertdir')
86
self.run_bzr('commit -m f')
88
87
os.rmdir('revertdir')
88
self.run_bzr('revert')
92
91
os.symlink('/unlikely/to/exist', 'symlink')
93
self.runbzr('add symlink')
94
self.runbzr('commit -m f')
92
self.run_bzr('add symlink')
93
self.run_bzr('commit -m f')
95
94
os.unlink('symlink')
95
self.run_bzr('revert')
97
96
self.failUnlessExists('symlink')
98
97
os.unlink('symlink')
99
98
os.symlink('a-different-path', 'symlink')
100
self.runbzr('revert')
99
self.run_bzr('revert')
101
100
self.assertEqual('/unlikely/to/exist',
102
101
os.readlink('symlink'))
104
103
self.log("skipping revert symlink tests")
106
105
file('hello', 'wt').write('xyz')
107
self.runbzr('commit -m xyz hello')
108
self.runbzr('revert -r 1 hello')
106
self.run_bzr('commit -m xyz hello')
107
self.run_bzr('revert -r 1 hello')
109
108
self.check_file_contents('hello', 'foo')
110
self.runbzr('revert hello')
109
self.run_bzr('revert hello')
111
110
self.check_file_contents('hello', 'xyz')
112
111
os.chdir('revertdir')
113
self.runbzr('revert')
112
self.run_bzr('revert')
116
115
def test_main_version(self):
117
116
"""Check output from version command and master option is reasonable"""
118
117
# output is intentionally passed through to stdout so that we
119
118
# can see the version being tested
120
output = self.runbzr('version', backtick=1)
119
output = self.run_bzr(['version'])[0]
121
120
self.log('bzr version output:')
123
122
self.assert_(output.startswith('Bazaar (bzr) '))
124
123
self.assertNotEqual(output.index('Canonical'), -1)
125
124
# make sure --version is consistent
126
tmp_output = self.runbzr('--version', backtick=1)
127
self.log('bzr --version output:')
125
tmp_output = self.run_bzr(['--version'])[0]
129
126
self.assertEquals(output, tmp_output)
131
128
def example_branch(test):
133
130
file('hello', 'wt').write('foo')
134
test.runbzr('add hello')
135
test.runbzr('commit -m setup hello')
131
test.run_bzr('add hello')
132
test.run_bzr('commit -m setup hello')
136
133
file('goodbye', 'wt').write('baz')
137
test.runbzr('add goodbye')
138
test.runbzr('commit -m setup goodbye')
134
test.run_bzr('add goodbye')
135
test.run_bzr('commit -m setup goodbye')
140
137
def test_pull_verbose(self):
141
138
"""Pull changes from one branch to another and watch the output."""
147
143
self.example_branch()
146
self.run_bzr('branch a b')
152
148
open('b', 'wb').write('else\n')
154
bzr(['commit', '-m', 'added b'])
149
self.run_bzr('add b')
150
self.run_bzr(['commit', '-m', 'added b'])
157
out = bzr('pull --verbose ../b', backtick=True)
153
out = self.run_bzr('pull --verbose ../b')[0]
158
154
self.failIfEqual(out.find('Added Revisions:'), -1)
159
155
self.failIfEqual(out.find('message:\n added b'), -1)
160
156
self.failIfEqual(out.find('added b'), -1)
162
158
# Check that --overwrite --verbose prints out the removed entries
163
bzr('commit -m foo --unchanged')
159
self.run_bzr('commit -m foo --unchanged')
165
bzr('commit -m baz --unchanged')
166
bzr('pull ../a', retcode=3)
167
out = bzr('pull --overwrite --verbose ../a', backtick=1)
161
self.run_bzr('commit -m baz --unchanged')
162
self.run_bzr('pull ../a', retcode=3)
163
out = self.run_bzr('pull --overwrite --verbose ../a')[0]
169
165
remove_loc = out.find('Removed Revisions:')
170
166
self.failIfEqual(remove_loc, -1)
183
179
"""Using and remembering different locations"""
187
self.runbzr('commit -m unchanged --unchanged')
188
self.runbzr('pull', retcode=3)
189
self.runbzr('merge', retcode=3)
190
self.runbzr('branch . ../b')
183
self.run_bzr('commit -m unchanged --unchanged')
184
self.run_bzr('pull', retcode=3)
185
self.run_bzr('merge', retcode=3)
186
self.run_bzr('branch . ../b')
193
self.runbzr('branch . ../c')
194
self.runbzr('pull ../c')
189
self.run_bzr('branch . ../c')
190
self.run_bzr('pull ../c')
191
self.run_bzr('merge')
197
self.runbzr('pull ../b')
199
self.runbzr('pull ../c')
200
self.runbzr('branch ../c ../d')
193
self.run_bzr('pull ../b')
195
self.run_bzr('pull ../c')
196
self.run_bzr('branch ../c ../d')
201
197
osutils.rmtree('../c')
206
self.runbzr('pull', retcode=3)
207
self.runbzr('pull ../a --remember')
202
self.run_bzr('pull', retcode=3)
203
self.run_bzr('pull ../a --remember')
210
206
def test_unknown_command(self):
211
207
"""Handling of unknown command."""
212
out, err = self.run_bzr_captured(['fluffy-badger'],
208
out, err = self.run_bzr(['fluffy-badger'],
214
210
self.assertEquals(out, '')
215
211
err.index('unknown command')
221
217
file('hello', 'wb').write("hi world")
222
218
file('answer', 'wb').write("42")
225
self.runbzr('commit -m base')
226
self.runbzr('branch . ../other')
227
self.runbzr('branch . ../this')
221
self.run_bzr('commit -m base')
222
self.run_bzr('branch . ../other')
223
self.run_bzr('branch . ../this')
228
224
os.chdir('../other')
229
225
file('hello', 'wb').write("Hello.")
230
226
file('answer', 'wb').write("Is anyone there?")
231
self.runbzr('commit -m other')
227
self.run_bzr('commit -m other')
232
228
os.chdir('../this')
233
229
file('hello', 'wb').write("Hello, world")
234
self.runbzr('mv answer question')
230
self.run_bzr('mv answer question')
235
231
file('question', 'wb').write("What do you get when you multiply six"
237
self.runbzr('commit -m this')
233
self.run_bzr('commit -m this')
239
235
def test_status(self):
240
236
os.mkdir('branch1')
241
237
os.chdir('branch1')
243
self.runbzr('commit --unchanged --message f')
244
self.runbzr('branch . ../branch2')
245
self.runbzr('branch . ../branch3')
246
self.runbzr('commit --unchanged --message peter')
239
self.run_bzr('commit --unchanged --message f')
240
self.run_bzr('branch . ../branch2')
241
self.run_bzr('branch . ../branch3')
242
self.run_bzr('commit --unchanged --message peter')
247
243
os.chdir('../branch2')
248
self.runbzr('merge ../branch1')
249
self.runbzr('commit --unchanged --message pumpkin')
244
self.run_bzr('merge ../branch1')
245
self.run_bzr('commit --unchanged --message pumpkin')
250
246
os.chdir('../branch3')
251
self.runbzr('merge ../branch2')
252
message = self.capture('status')
247
self.run_bzr('merge ../branch2')
248
message = self.run_bzr('status')[0]
255
251
def test_conflicts(self):
256
252
"""Handling of merge conflicts"""
257
253
self.create_conflicts()
258
self.runbzr('merge ../other --show-base', retcode=1)
254
self.run_bzr('merge ../other --show-base', retcode=1)
259
255
conflict_text = file('hello').read()
260
256
self.assert_('<<<<<<<' in conflict_text)
261
257
self.assert_('>>>>>>>' in conflict_text)
262
258
self.assert_('=======' in conflict_text)
263
259
self.assert_('|||||||' in conflict_text)
264
260
self.assert_('hi world' in conflict_text)
265
self.runbzr('revert')
266
self.runbzr('resolve --all')
267
self.runbzr('merge ../other', retcode=1)
261
self.run_bzr('revert')
262
self.run_bzr('resolve --all')
263
self.run_bzr('merge ../other', retcode=1)
268
264
conflict_text = file('hello').read()
269
265
self.assert_('|||||||' not in conflict_text)
270
266
self.assert_('hi world' not in conflict_text)
271
result = self.runbzr('conflicts', backtick=1)
267
result = self.run_bzr('conflicts')[0]
272
268
self.assertEquals(result, "Text conflict in hello\nText conflict in"
274
result = self.runbzr('status', backtick=1)
270
result = self.run_bzr('status')[0]
275
271
self.assert_("conflicts:\n Text conflict in hello\n"
276
272
" Text conflict in question\n" in result, result)
277
self.runbzr('resolve hello')
278
result = self.runbzr('conflicts', backtick=1)
273
self.run_bzr('resolve hello')
274
result = self.run_bzr('conflicts')[0]
279
275
self.assertEquals(result, "Text conflict in question\n")
280
self.runbzr('commit -m conflicts', retcode=3)
281
self.runbzr('resolve --all')
282
result = self.runbzr('conflicts', backtick=1)
283
self.runbzr('commit -m conflicts')
276
self.run_bzr('commit -m conflicts', retcode=3)
277
self.run_bzr('resolve --all')
278
result = self.run_bzr('conflicts')[0]
279
self.run_bzr('commit -m conflicts')
284
280
self.assertEquals(result, "")
286
282
def test_push(self):
290
286
self.example_branch()
292
288
# with no push target, fail
293
self.runbzr('push', retcode=3)
289
self.run_bzr('push', retcode=3)
294
290
# with an explicit target work
295
self.runbzr('push ../output-branch')
291
self.run_bzr('push ../output-branch')
296
292
# with an implicit target work
298
294
# nothing missing
299
self.runbzr('missing ../output-branch')
295
self.run_bzr('missing ../output-branch')
300
296
# advance this branch
301
self.runbzr('commit --unchanged -m unchanged')
297
self.run_bzr('commit --unchanged -m unchanged')
303
299
os.chdir('../output-branch')
304
300
# There is no longer a difference as long as we have
305
301
# access to the working tree
308
304
# But we should be missing a revision
309
self.runbzr('missing ../my-branch', retcode=1)
305
self.run_bzr('missing ../my-branch', retcode=1)
311
307
# diverge the branches
312
self.runbzr('commit --unchanged -m unchanged')
308
self.run_bzr('commit --unchanged -m unchanged')
313
309
os.chdir('../my-branch')
314
310
# cannot push now
315
self.runbzr('push', retcode=3)
311
self.run_bzr('push', retcode=3)
316
312
# and there are difference
317
self.runbzr('missing ../output-branch', retcode=1)
318
self.runbzr('missing --verbose ../output-branch', retcode=1)
313
self.run_bzr('missing ../output-branch', retcode=1)
314
self.run_bzr('missing --verbose ../output-branch', retcode=1)
319
315
# but we can force a push
320
self.runbzr('push --overwrite')
316
self.run_bzr('push --overwrite')
321
317
# nothing missing
322
self.runbzr('missing ../output-branch')
318
self.run_bzr('missing ../output-branch')
324
320
# pushing to a new dir with no parent should fail
325
self.runbzr('push ../missing/new-branch', retcode=3)
321
self.run_bzr('push ../missing/new-branch', retcode=3)
326
322
# unless we provide --create-prefix
327
self.runbzr('push --create-prefix ../missing/new-branch')
323
self.run_bzr('push --create-prefix ../missing/new-branch')
328
324
# nothing missing
329
self.runbzr('missing ../missing/new-branch')
325
self.run_bzr('missing ../missing/new-branch')
331
327
def test_external_command(self):
332
328
"""Test that external commands can be run by setting the path
403
396
f.write('hello world!\n')
406
self.assertEquals(capture('unknowns'), 'test.txt\n')
399
self.assertEquals(self.run_bzr('unknowns')[0], 'test.txt\n')
408
out = capture("status")
401
out = self.run_bzr("status")[0]
409
402
self.assertEquals(out, 'unknown:\n test.txt\n')
411
404
f = file('test2.txt', 'wt')
412
405
f.write('goodbye cruel world...\n')
415
out = capture("status test.txt")
408
out = self.run_bzr("status test.txt")[0]
416
409
self.assertEquals(out, "unknown:\n test.txt\n")
418
out = capture("status")
411
out = self.run_bzr("status")[0]
419
412
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
421
414
os.unlink('test2.txt')
423
416
progress("command aliases")
417
out = self.run_bzr("st")[0]
425
418
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
427
out = capture("stat")
420
out = self.run_bzr("stat")[0]
428
421
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
430
423
progress("command help")
433
runbzr("help commands")
434
runbzr("help slartibartfast", 3)
424
self.run_bzr("help st")
426
self.run_bzr("help commands")
427
self.run_bzr("help slartibartfast", retcode=3)
436
out = capture("help ci")
437
out.index('aliases:\n')
429
out = self.run_bzr("help ci")[0]
430
out.index('aliases: ci, checkin\n')
439
432
f = file('hello.txt', 'wt')
440
433
f.write('some nice new content\n')
443
runbzr("add hello.txt")
436
self.run_bzr("add hello.txt")
445
438
f = file('msg.tmp', 'wt')
446
439
f.write('this is my new commit\nand it has multiple lines, for fun')
449
runbzr('commit -F msg.tmp')
451
self.assertEquals(capture('revno'), '1\n')
452
runbzr('export -r 1 export-1.tmp')
453
runbzr('export export.tmp')
457
runbzr('log -v --forward')
458
runbzr('log -m', retcode=3)
459
log_out = capture('log -m commit')
442
self.run_bzr('commit -F msg.tmp')
444
self.assertEquals(self.run_bzr('revno')[0], '1\n')
445
self.run_bzr('export -r 1 export-1.tmp')
446
self.run_bzr('export export.tmp')
449
self.run_bzr('log -v')
450
self.run_bzr('log -v --forward')
451
self.run_bzr('log -m', retcode=3)
452
log_out = self.run_bzr('log -m commit')[0]
460
453
self.assert_("this is my new commit\n and" in log_out)
461
454
self.assert_("rename nested" not in log_out)
462
455
self.assert_('revision-id' not in log_out)
463
self.assert_('revision-id' in capture('log --show-ids -m commit'))
456
self.assert_('revision-id' in self.run_bzr('log --show-ids -m commit')[0])
465
log_out = capture('log --line')
458
log_out = self.run_bzr('log --line')[0]
466
459
# determine the widest line we want
467
460
max_width = terminal_width() - 1
468
461
for line in log_out.splitlines():
473
466
progress("file with spaces in name")
474
467
mkdir('sub directory')
475
468
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
477
runbzr('diff', retcode=1)
478
runbzr('commit -m add-spaces')
482
runbzr('log --forward')
469
self.run_bzr('add .')
470
self.run_bzr('diff', retcode=1)
471
self.run_bzr('commit -m add-spaces')
472
self.run_bzr('check')
475
self.run_bzr('log --forward')
486
479
if has_symlinks():
487
480
progress("symlinks")
488
481
mkdir('symlinks')
489
482
chdir('symlinks')
491
484
os.symlink("NOWHERE1", "link1")
493
self.assertEquals(self.capture('unknowns'), '')
494
runbzr(['commit', '-m', '1: added symlink link1'])
485
self.run_bzr('add link1')
486
self.assertEquals(self.run_bzr('unknowns')[0], '')
487
self.run_bzr(['commit', '-m', '1: added symlink link1'])
498
self.assertEquals(self.capture('unknowns'), '')
490
self.run_bzr('add d1')
491
self.assertEquals(self.run_bzr('unknowns')[0], '')
499
492
os.symlink("NOWHERE2", "d1/link2")
500
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
493
self.assertEquals(self.run_bzr('unknowns')[0], 'd1/link2\n')
501
494
# is d1/link2 found when adding d1
503
self.assertEquals(self.capture('unknowns'), '')
495
self.run_bzr('add d1')
496
self.assertEquals(self.run_bzr('unknowns')[0], '')
504
497
os.symlink("NOWHERE3", "d1/link3")
505
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
506
runbzr(['commit', '-m', '2: added dir, symlink'])
498
self.assertEquals(self.run_bzr('unknowns')[0], 'd1/link3\n')
499
self.run_bzr(['commit', '-m', '2: added dir, symlink'])
508
runbzr('rename d1 d2')
509
runbzr('move d2/link2 .')
510
runbzr('move link1 d2')
501
self.run_bzr('rename d1 d2')
502
self.run_bzr('move d2/link2 .')
503
self.run_bzr('move link1 d2')
511
504
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
512
505
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
513
runbzr('add d2/link3')
514
runbzr('diff', retcode=1)
515
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
506
self.run_bzr('add d2/link3')
507
self.run_bzr('diff', retcode=1)
508
self.run_bzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
517
510
os.unlink("link2")
518
511
os.symlink("TARGET 2", "link2")
519
512
os.unlink("d2/link1")
520
513
os.symlink("TARGET 1", "d2/link1")
521
runbzr('diff', retcode=1)
522
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
523
runbzr(['commit', '-m', '4: retarget of two links'])
514
self.run_bzr('diff', retcode=1)
515
self.assertEquals(self.run_bzr("relpath d2/link1")[0], "d2/link1\n")
516
self.run_bzr(['commit', '-m', '4: retarget of two links'])
525
runbzr('remove --keep d2/link1')
526
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
527
runbzr(['commit', '-m', '5: remove d2/link1'])
518
self.run_bzr('remove --keep d2/link1')
519
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
520
self.run_bzr(['commit', '-m', '5: remove d2/link1'])
528
521
# try with the rm alias
529
runbzr('add d2/link1')
530
runbzr(['commit', '-m', '6: add d2/link1'])
531
runbzr('rm --keep d2/link1')
532
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
533
runbzr(['commit', '-m', '7: remove d2/link1'])
522
self.run_bzr('add d2/link1')
523
self.run_bzr(['commit', '-m', '6: add d2/link1'])
524
self.run_bzr('rm --keep d2/link1')
525
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
526
self.run_bzr(['commit', '-m', '7: remove d2/link1'])
537
runbzr('rename d2/link3 d1/link3new')
538
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
539
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
543
runbzr(['export', '-r', '1', 'exp1.tmp'])
529
self.run_bzr('add d1')
530
self.run_bzr('rename d2/link3 d1/link3new')
531
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
532
self.run_bzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
534
self.run_bzr(['check'])
536
self.run_bzr(['export', '-r', '1', 'exp1.tmp'])
544
537
chdir("exp1.tmp")
545
538
self.assertEquals(listdir_sorted("."), [ "link1" ])
546
539
self.assertEquals(os.readlink("link1"), "NOWHERE1")
549
runbzr(['export', '-r', '2', 'exp2.tmp'])
542
self.run_bzr(['export', '-r', '2', 'exp2.tmp'])
550
543
chdir("exp2.tmp")
551
544
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
554
runbzr(['export', '-r', '3', 'exp3.tmp'])
547
self.run_bzr(['export', '-r', '3', 'exp3.tmp'])
555
548
chdir("exp3.tmp")
556
549
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
557
550
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
603
596
def test_log(self):
604
597
self.build_tree(['branch/', 'branch/file'])
605
self.capture('init branch')
606
self.capture('add branch/file')
607
self.capture('commit -m foo branch')
598
self.run_bzr('init branch')[0]
599
self.run_bzr('add branch/file')[0]
600
self.run_bzr('commit -m foo branch')[0]
608
601
url = self.get_readonly_url('branch/file')
609
output = self.capture('log %s' % url)
602
output = self.run_bzr('log %s' % url)[0]
610
603
self.assertEqual(8, len(output.split('\n')))
612
605
def test_check(self):
613
606
self.build_tree(['branch/', 'branch/file'])
614
self.capture('init branch')
615
self.capture('add branch/file')
616
self.capture('commit -m foo branch')
607
self.run_bzr('init branch')[0]
608
self.run_bzr('add branch/file')[0]
609
self.run_bzr('commit -m foo branch')[0]
617
610
url = self.get_readonly_url('branch/')
618
611
self.run_bzr('check', url)