83
93
if bzr_email is not None:
84
94
os.environ['BZREMAIL'] = bzr_email
86
def test_nick_command(self):
87
"""bzr nick for viewing, setting nicknames"""
91
nick = self.runbzr("nick",backtick=True)
92
self.assertEqual(nick, 'me.dev\n')
93
nick = self.runbzr("nick moo")
94
nick = self.runbzr("nick",backtick=True)
95
self.assertEqual(nick, 'moo\n')
97
96
def test_invalid_commands(self):
98
self.runbzr("pants", retcode=3)
99
self.runbzr("--pants off", retcode=3)
100
self.runbzr("diff --message foo", retcode=3)
102
def test_remove_deleted(self):
104
self.build_tree(['a'])
105
self.runbzr(['add', 'a'])
106
self.runbzr(['commit', '-m', 'added a'])
108
self.runbzr(['remove', 'a'])
97
self.runbzr("pants", retcode=1)
98
self.runbzr("--pants off", retcode=1)
99
self.runbzr("diff --message foo", retcode=1)
101
def test_empty_commit(self):
103
self.build_tree(['hello.txt'])
104
self.runbzr("commit -m empty", retcode=1)
105
self.runbzr("add hello.txt")
106
self.runbzr("commit -m added")
108
def test_empty_commit_message(self):
110
file('foo.c', 'wt').write('int main() {}')
111
self.runbzr(['add', 'foo.c'])
112
self.runbzr(["commit", "-m", ""] , retcode=1)
110
114
def test_ignore_patterns(self):
112
self.assertEquals(self.capture('unknowns'), '')
115
from bzrlib.branch import Branch
117
b = Branch.initialize('.')
118
self.assertEquals(list(b.unknowns()), [])
114
120
file('foo.tmp', 'wt').write('tmp files are ignored')
115
self.assertEquals(self.capture('unknowns'), '')
121
self.assertEquals(list(b.unknowns()), [])
122
assert self.capture('unknowns') == ''
117
124
file('foo.c', 'wt').write('int main() {}')
118
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
125
self.assertEquals(list(b.unknowns()), ['foo.c'])
126
assert self.capture('unknowns') == 'foo.c\n'
120
128
self.runbzr(['add', 'foo.c'])
121
self.assertEquals(self.capture('unknowns'), '')
129
assert self.capture('unknowns') == ''
123
131
# 'ignore' works when creating the .bzignore file
124
132
file('foo.blah', 'wt').write('blah')
125
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
133
self.assertEquals(list(b.unknowns()), ['foo.blah'])
126
134
self.runbzr('ignore *.blah')
127
self.assertEquals(self.capture('unknowns'), '')
128
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
135
self.assertEquals(list(b.unknowns()), [])
136
assert file('.bzrignore', 'rU').read() == '*.blah\n'
130
138
# 'ignore' works when then .bzrignore file already exists
131
139
file('garh', 'wt').write('garh')
132
self.assertEquals(self.capture('unknowns'), 'garh\n')
140
self.assertEquals(list(b.unknowns()), ['garh'])
141
assert self.capture('unknowns') == 'garh\n'
133
142
self.runbzr('ignore garh')
134
self.assertEquals(self.capture('unknowns'), '')
135
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
143
self.assertEquals(list(b.unknowns()), [])
144
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
137
146
def test_revert(self):
138
147
self.runbzr('init')
226
239
self.runbzr('export ../latest')
227
240
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
228
241
self.runbzr('export ../first -r 1')
229
self.assert_(not os.path.exists('../first/goodbye'))
242
assert not os.path.exists('../first/goodbye')
230
243
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
231
244
self.runbzr('export ../first.gz -r 1')
232
245
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
233
246
self.runbzr('export ../first.bz2 -r 1')
234
247
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
248
self.runbzr('export ../first.tar -r 1')
249
assert os.path.isfile('../first.tar')
236
250
from tarfile import TarFile
237
self.runbzr('export ../first.tar -r 1')
238
self.assert_(os.path.isfile('../first.tar'))
239
251
tf = TarFile('../first.tar')
240
self.assert_('first/hello' in tf.getnames(), tf.getnames())
252
assert 'first/hello' in tf.getnames(), tf.getnames()
241
253
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
254
self.runbzr('export ../first.tar.gz -r 1')
243
self.assert_(os.path.isfile('../first.tar.gz'))
255
assert os.path.isfile('../first.tar.gz')
244
256
self.runbzr('export ../first.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tbz2'))
257
assert os.path.isfile('../first.tbz2')
246
258
self.runbzr('export ../first.tar.bz2 -r 1')
247
self.assert_(os.path.isfile('../first.tar.bz2'))
259
assert os.path.isfile('../first.tar.bz2')
248
260
self.runbzr('export ../first.tar.tbz2 -r 1')
249
self.assert_(os.path.isfile('../first.tar.tbz2'))
261
assert os.path.isfile('../first.tar.tbz2')
251
262
from bz2 import BZ2File
252
263
tf = TarFile('../first.tar.tbz2',
253
264
fileobj=BZ2File('../first.tar.tbz2', 'r'))
254
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
265
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
255
266
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
256
267
self.runbzr('export ../first2.tar -r 1 --root pizza')
257
268
tf = TarFile('../first2.tar')
258
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
260
from zipfile import ZipFile
261
self.runbzr('export ../first.zip -r 1')
262
self.failUnlessExists('../first.zip')
263
zf = ZipFile('../first.zip')
264
self.assert_('first/hello' in zf.namelist(), zf.namelist())
265
self.assertEqual(zf.read('first/hello'), 'foo')
267
self.runbzr('export ../first2.zip -r 1 --root pizza')
268
zf = ZipFile('../first2.zip')
269
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
271
self.runbzr('export ../first-zip --format=zip -r 1')
272
zf = ZipFile('../first-zip')
273
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
269
assert 'pizza/hello' in tf.getnames(), tf.getnames()
272
self.example_branch()
273
file('hello', 'wt').write('hello world!')
274
self.runbzr('commit -m fixing hello')
275
output = self.runbzr('diff -r 2..3', backtick=1)
276
self.assert_('\n+hello world!' in output)
277
output = self.runbzr('diff -r last:3..last:1', backtick=1)
278
self.assert_('\n+baz' in output)
280
def test_diff_branches(self):
281
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
282
branch = Branch.initialize('branch1')
284
branch.commit('add file')
285
copy_branch(branch, 'branch2')
286
print >> open('branch2/file', 'w'), 'new content'
287
branch2 = Branch.open('branch2')
288
branch2.commit('update file')
289
# should open branch1 and diff against branch2,
290
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
291
self.assertEquals(("=== modified file 'file'\n"
296
"+contents of branch1/file\n"
275
299
def test_branch(self):
276
300
"""Branch from one branch to another."""
279
303
self.example_branch()
281
305
self.runbzr('branch a b')
282
b = bzrlib.branch.Branch.open('b')
283
self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
284
306
self.runbzr('branch a c -r 1')
286
308
self.runbzr('commit -m foo --unchanged')
289
def test_branch_basis(self):
290
# ensure that basis really does grab from the basis by having incomplete source
291
tree = self.make_branch_and_tree('commit_tree')
292
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
294
tree.commit('revision 1', rev_id='1')
295
source = self.make_branch_and_tree('source')
296
# this gives us an incomplete repository
297
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
298
tree.commit('revision 2', rev_id='2', allow_pointless=True)
299
tree.bzrdir.open_branch().copy_content_into(source.branch)
300
tree.copy_content_into(source)
301
self.assertFalse(source.branch.repository.has_revision('2'))
303
self.runbzr('branch source target --basis commit_tree')
304
target = bzrdir.BzrDir.open('target')
305
self.assertEqual('2', target.open_branch().last_revision())
306
self.assertEqual('2', target.open_workingtree().last_revision())
307
self.assertTrue(target.open_branch().repository.has_revision('2'))
309
def test_inventory(self):
311
def output_equals(value, *args):
312
out = self.runbzr(['inventory'] + list(args), backtick=True)
313
self.assertEquals(out, value)
316
open('a', 'wb').write('hello\n')
322
output_equals('a\n', '--kind', 'file')
323
output_equals('b\n', '--kind', 'directory')
326
"""Test the abilities of 'bzr ls'"""
328
def bzrout(*args, **kwargs):
329
kwargs['backtick'] = True
330
return self.runbzr(*args, **kwargs)
332
def ls_equals(value, *args):
333
out = self.runbzr(['ls'] + list(args), backtick=True)
334
self.assertEquals(out, value)
337
open('a', 'wb').write('hello\n')
340
bzr('ls --verbose --null', retcode=3)
343
ls_equals('? a\n', '--verbose')
344
ls_equals('a\n', '--unknown')
345
ls_equals('', '--ignored')
346
ls_equals('', '--versioned')
347
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
348
ls_equals('', '--ignored', '--versioned')
349
ls_equals('a\0', '--null')
352
ls_equals('V a\n', '--verbose')
310
# naughty - abstraction violations RBC 20050928
311
print "test_branch used to delete the stores, how is this meant to work ?"
312
#shutil.rmtree('a/.bzr/revision-store')
313
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
314
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
315
self.runbzr('branch a d --basis b')
317
def test_merge(self):
318
from bzrlib.branch import Branch
322
self.example_branch()
324
self.runbzr('branch a b')
326
file('goodbye', 'wt').write('quux')
327
self.runbzr(['commit', '-m', "more u's are always good"])
330
file('hello', 'wt').write('quuux')
331
# We can't merge when there are in-tree changes
332
self.runbzr('merge ../b', retcode=1)
333
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
334
self.runbzr('merge ../b')
335
self.check_file_contents('goodbye', 'quux')
336
# Merging a branch pulls its revision into the tree
338
b = Branch.open('../b')
339
a.get_revision_xml(b.last_revision())
340
self.log('pending merges: %s', a.pending_merges())
341
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
342
# % (a.pending_merges(), b.last_patch())
344
def test_merge_with_missing_file(self):
345
"""Merge handles missing file conflicts"""
349
print >> file('sub/a.txt', 'wb'), "hello"
350
print >> file('b.txt', 'wb'), "hello"
351
print >> file('sub/c.txt', 'wb'), "hello"
354
self.runbzr(('commit', '-m', 'added a'))
355
self.runbzr('branch . ../b')
356
print >> file('sub/a.txt', 'ab'), "there"
357
print >> file('b.txt', 'ab'), "there"
358
print >> file('sub/c.txt', 'ab'), "there"
359
self.runbzr(('commit', '-m', 'Added there'))
360
os.unlink('sub/a.txt')
361
os.unlink('sub/c.txt')
364
self.runbzr(('commit', '-m', 'Removed a.txt'))
366
print >> file('sub/a.txt', 'ab'), "something"
367
print >> file('b.txt', 'ab'), "something"
368
print >> file('sub/c.txt', 'ab'), "something"
369
self.runbzr(('commit', '-m', 'Modified a.txt'))
370
self.runbzr('merge ../a/')
371
assert os.path.exists('sub/a.txt.THIS')
372
assert os.path.exists('sub/a.txt.BASE')
374
self.runbzr('merge ../b/')
375
assert os.path.exists('sub/a.txt.OTHER')
376
assert os.path.exists('sub/a.txt.BASE')
379
"""Pull changes from one branch to another."""
383
self.example_branch()
384
self.runbzr('pull', retcode=1)
385
self.runbzr('missing', retcode=1)
386
self.runbzr('missing .')
387
self.runbzr('missing')
389
self.runbzr('pull /', retcode=1)
393
self.runbzr('branch a b')
355
396
os.mkdir('subdir')
359
open('subdir/b', 'wb').write('b\n')
365
bzr('commit -m subdir')
373
, '--verbose', '--non-recursive')
375
# Check what happens in a sub-directory
387
, '--from-root', '--null')
390
, '--from-root', '--non-recursive')
394
# Check what happens when we supply a specific revision
395
ls_equals('a\n', '--revision', '1')
397
, '--verbose', '--revision', '1')
400
ls_equals('', '--revision', '1')
402
# Now try to do ignored files.
404
open('blah.py', 'wb').write('unknown\n')
405
open('blah.pyo', 'wb').write('ignored\n')
417
ls_equals('blah.pyo\n'
419
ls_equals('blah.py\n'
428
file("myfile", "wb").write("My contents\n")
430
self.runbzr('commit -m myfile')
431
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
433
def test_pull_verbose(self):
434
"""Pull changes from one branch to another and watch the output."""
440
self.example_branch()
445
open('b', 'wb').write('else\n')
447
bzr(['commit', '-m', 'added b'])
397
self.runbzr('add subdir')
398
self.runbzr('commit -m blah --unchanged')
450
out = bzr('pull --verbose ../b', backtick=True)
451
self.failIfEqual(out.find('Added Revisions:'), -1)
452
self.failIfEqual(out.find('message:\n added b'), -1)
453
self.failIfEqual(out.find('added b'), -1)
455
# Check that --overwrite --verbose prints out the removed entries
456
bzr('commit -m foo --unchanged')
401
b = Branch.open('../b')
402
assert a.revision_history() == b.revision_history()[:-1]
403
self.runbzr('pull ../b')
404
assert a.revision_history() == b.revision_history()
405
self.runbzr('commit -m blah2 --unchanged')
458
bzr('commit -m baz --unchanged')
459
bzr('pull ../a', retcode=3)
460
out = bzr('pull --overwrite --verbose ../a', backtick=1)
462
remove_loc = out.find('Removed Revisions:')
463
self.failIfEqual(remove_loc, -1)
464
added_loc = out.find('Added Revisions:')
465
self.failIfEqual(added_loc, -1)
467
removed_message = out.find('message:\n baz')
468
self.failIfEqual(removed_message, -1)
469
self.failUnless(remove_loc < removed_message < added_loc)
471
added_message = out.find('message:\n foo')
472
self.failIfEqual(added_message, -1)
473
self.failUnless(added_loc < added_message)
407
self.runbzr('commit -m blah3 --unchanged')
408
self.runbzr('pull ../a', retcode=1)
409
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
412
self.runbzr('merge ../b')
413
self.runbzr('commit -m blah4 --unchanged')
414
os.chdir('../b/subdir')
415
self.runbzr('pull ../../a')
416
assert a.revision_history()[-1] == b.revision_history()[-1]
417
self.runbzr('commit -m blah5 --unchanged')
418
self.runbzr('commit -m blah6 --unchanged')
420
self.runbzr('pull ../a')
422
self.runbzr('commit -m blah7 --unchanged')
423
self.runbzr('merge ../b')
424
self.runbzr('commit -m blah8 --unchanged')
425
self.runbzr('pull ../b')
426
self.runbzr('pull ../b')
475
428
def test_locations(self):
476
429
"""Using and remembering different locations"""
479
432
self.runbzr('init')
480
433
self.runbzr('commit -m unchanged --unchanged')
481
self.runbzr('pull', retcode=3)
482
self.runbzr('merge', retcode=3)
434
self.runbzr('pull', retcode=1)
435
self.runbzr('merge', retcode=1)
483
436
self.runbzr('branch . ../b')
485
438
self.runbzr('pull')
497
450
self.runbzr('pull')
499
self.runbzr('pull', retcode=3)
452
self.runbzr('pull', retcode=1)
500
453
self.runbzr('pull ../a --remember')
501
454
self.runbzr('pull')
503
456
def test_add_reports(self):
504
457
"""add command prints the names of added files."""
506
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
507
out = self.run_bzr_captured(['add'], retcode=0)[0]
458
b = Branch.initialize('.')
459
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
460
out = self.run_bzr_captured(['add'], retcode = 0)[0]
508
461
# the ordering is not defined at the moment
509
462
results = sorted(out.rstrip('\n').split('\n'))
510
self.assertEquals(['If you wish to add some of these files, please'\
511
' add them by name.',
515
'ignored 1 file(s) matching "CVS"'],
517
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
518
results = sorted(out.rstrip('\n').split('\n'))
519
self.assertEquals(['If you wish to add some of these files, please'\
520
' add them by name.',
521
'ignored CVS matching "CVS"'],
463
self.assertEquals(['added dir',
464
'added dir'+os.sep+'sub.txt',
524
468
def test_add_quiet_is(self):
525
469
"""add -q does not print the names of added files."""
470
b = Branch.initialize('.')
527
471
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
528
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
472
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
529
473
# the ordering is not defined at the moment
530
474
results = sorted(out.rstrip('\n').split('\n'))
531
475
self.assertEquals([''], results)
533
def test_add_in_unversioned(self):
534
"""Try to add a file in an unversioned directory.
536
"bzr add" should add the parent(s) as necessary.
539
self.build_tree(['inertiatic/', 'inertiatic/esp'])
540
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
541
self.run_bzr('add', 'inertiatic/esp')
542
self.assertEquals(self.capture('unknowns'), '')
544
# Multiple unversioned parents
545
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
546
self.assertEquals(self.capture('unknowns'), 'veil\n')
547
self.run_bzr('add', 'veil/cerpin/taxt')
548
self.assertEquals(self.capture('unknowns'), '')
550
# Check whacky paths work
551
self.build_tree(['cicatriz/', 'cicatriz/esp'])
552
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
553
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
554
self.assertEquals(self.capture('unknowns'), '')
556
def test_add_in_versioned(self):
557
"""Try to add a file in a versioned directory.
559
"bzr add" should do this happily.
562
self.build_tree(['inertiatic/', 'inertiatic/esp'])
563
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
564
self.run_bzr('add', '--no-recurse', 'inertiatic')
565
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
566
self.run_bzr('add', 'inertiatic/esp')
567
self.assertEquals(self.capture('unknowns'), '')
569
def test_subdir_add(self):
570
"""Add in subdirectory should add only things from there down"""
571
from bzrlib.workingtree import WorkingTree
573
eq = self.assertEqual
577
t = self.make_branch_and_tree('.')
579
self.build_tree(['src/', 'README'])
581
eq(sorted(t.unknowns()),
584
self.run_bzr('add', 'src')
586
self.build_tree(['src/foo.c'])
591
self.assertEquals(self.capture('unknowns'), 'README\n')
592
eq(len(t.read_working_inventory()), 3)
596
self.assertEquals(self.capture('unknowns'), '')
597
self.run_bzr('check')
599
477
def test_unknown_command(self):
600
478
"""Handling of unknown command."""
601
479
out, err = self.run_bzr_captured(['fluffy-badger'],
603
481
self.assertEquals(out, '')
604
482
err.index('unknown command')
606
def create_conflicts(self):
607
"""Create a conflicted tree"""
484
def test_conflicts(self):
485
"""Handling of merge conflicts"""
610
488
file('hello', 'wb').write("hi world")
624
502
file('question', 'wb').write("What do you get when you multiply six"
626
504
self.runbzr('commit -m this')
628
def test_remerge(self):
629
"""Remerge command works as expected"""
630
self.create_conflicts()
631
self.runbzr('merge ../other --show-base', retcode=1)
632
conflict_text = file('hello').read()
633
assert '|||||||' in conflict_text
634
assert 'hi world' in conflict_text
635
self.runbzr('remerge', retcode=1)
636
conflict_text = file('hello').read()
637
assert '|||||||' not in conflict_text
638
assert 'hi world' not in conflict_text
639
os.unlink('hello.OTHER')
640
os.unlink('question.OTHER')
641
self.runbzr('remerge jello --merge-type weave', retcode=3)
642
self.runbzr('remerge hello --merge-type weave', retcode=1)
643
assert os.path.exists('hello.OTHER')
644
self.assertIs(False, os.path.exists('question.OTHER'))
645
file_id = self.runbzr('file-id hello')
646
file_id = self.runbzr('file-id hello.THIS', retcode=3)
647
self.runbzr('remerge --merge-type weave', retcode=1)
648
assert os.path.exists('hello.OTHER')
649
assert not os.path.exists('hello.BASE')
650
assert '|||||||' not in conflict_text
651
assert 'hi world' not in conflict_text
652
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
653
self.runbzr('remerge . --show-base --reprocess', retcode=3)
654
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
655
self.runbzr('remerge hello --show-base', retcode=1)
656
self.runbzr('remerge hello --reprocess', retcode=1)
657
self.runbzr('resolve --all')
658
self.runbzr('commit -m done',)
659
self.runbzr('remerge', retcode=3)
661
def test_status(self):
665
self.runbzr('commit --unchanged --message f')
666
self.runbzr('branch . ../branch2')
667
self.runbzr('branch . ../branch3')
668
self.runbzr('commit --unchanged --message peter')
669
os.chdir('../branch2')
670
self.runbzr('merge ../branch1')
671
self.runbzr('commit --unchanged --message pumpkin')
672
os.chdir('../branch3')
673
self.runbzr('merge ../branch2')
674
message = self.capture('status')
677
def test_conflicts(self):
678
"""Handling of merge conflicts"""
679
self.create_conflicts()
680
self.runbzr('merge ../other --show-base', retcode=1)
681
conflict_text = file('hello').read()
682
self.assert_('<<<<<<<' in conflict_text)
683
self.assert_('>>>>>>>' in conflict_text)
684
self.assert_('=======' in conflict_text)
685
self.assert_('|||||||' in conflict_text)
686
self.assert_('hi world' in conflict_text)
687
self.runbzr('revert')
688
self.runbzr('resolve --all')
689
self.runbzr('merge ../other', retcode=1)
690
conflict_text = file('hello').read()
691
self.assert_('|||||||' not in conflict_text)
692
self.assert_('hi world' not in conflict_text)
505
self.runbzr('merge ../other')
693
506
result = self.runbzr('conflicts', backtick=1)
694
self.assertEquals(result, "Text conflict in hello\nText conflict in"
507
self.assertEquals(result, "hello\nquestion\n")
696
508
result = self.runbzr('status', backtick=1)
697
self.assert_("conflicts:\n Text conflict in hello\n"
698
" Text conflict in question\n" in result, result)
509
assert "conflicts:\n hello\n question\n" in result, result
699
510
self.runbzr('resolve hello')
700
511
result = self.runbzr('conflicts', backtick=1)
701
self.assertEquals(result, "Text conflict in question\n")
702
self.runbzr('commit -m conflicts', retcode=3)
512
self.assertEquals(result, "question\n")
513
self.runbzr('commit -m conflicts', retcode=1)
703
514
self.runbzr('resolve --all')
704
515
result = self.runbzr('conflicts', backtick=1)
705
516
self.runbzr('commit -m conflicts')
706
517
self.assertEquals(result, "")
709
# create a source branch
710
os.mkdir('my-branch')
711
os.chdir('my-branch')
712
self.example_branch()
714
# with no push target, fail
715
self.runbzr('push', retcode=3)
716
# with an explicit target work
717
self.runbzr('push ../output-branch')
718
# with an implicit target work
721
self.runbzr('missing ../output-branch')
722
# advance this branch
723
self.runbzr('commit --unchanged -m unchanged')
725
os.chdir('../output-branch')
726
# There is no longer a difference as long as we have
727
# access to the working tree
730
# But we should be missing a revision
731
self.runbzr('missing ../my-branch', retcode=1)
733
# diverge the branches
734
self.runbzr('commit --unchanged -m unchanged')
735
os.chdir('../my-branch')
737
self.runbzr('push', retcode=3)
738
# and there are difference
739
self.runbzr('missing ../output-branch', retcode=1)
740
self.runbzr('missing --verbose ../output-branch', retcode=1)
741
# but we can force a push
742
self.runbzr('push --overwrite')
744
self.runbzr('missing ../output-branch')
746
# pushing to a new dir with no parent should fail
747
self.runbzr('push ../missing/new-branch', retcode=3)
748
# unless we provide --create-prefix
749
self.runbzr('push --create-prefix ../missing/new-branch')
751
self.runbzr('missing ../missing/new-branch')
753
def test_external_command(self):
754
"""Test that external commands can be run by setting the path
756
# We don't at present run bzr in a subprocess for blackbox tests, and so
757
# don't really capture stdout, only the internal python stream.
758
# Therefore we don't use a subcommand that produces any output or does
759
# anything -- we just check that it can be run successfully.
760
cmd_name = 'test-command'
761
if sys.platform == 'win32':
763
oldpath = os.environ.get('BZRPATH', None)
766
if os.environ.has_key('BZRPATH'):
767
del os.environ['BZRPATH']
769
f = file(cmd_name, 'wb')
770
if sys.platform == 'win32':
771
f.write('@echo off\n')
773
f.write('#!/bin/sh\n')
774
# f.write('echo Hello from test-command')
776
os.chmod(cmd_name, 0755)
778
# It should not find the command in the local
779
# directory by default, since it is not in my path
780
bzr(cmd_name, retcode=3)
782
# Now put it into my path
783
os.environ['BZRPATH'] = '.'
787
# Make sure empty path elements are ignored
788
os.environ['BZRPATH'] = os.pathsep
790
bzr(cmd_name, retcode=3)
794
os.environ['BZRPATH'] = oldpath
797
519
def listdir_sorted(dir):
798
520
L = os.listdir(dir)
828
550
self.assertEquals(capture('unknowns'), 'test.txt\n')
830
552
out = capture("status")
831
self.assertEquals(out, 'unknown:\n test.txt\n')
553
assert out == 'unknown:\n test.txt\n'
833
555
out = capture("status --all")
834
self.assertEquals(out, "unknown:\n test.txt\n")
556
assert out == "unknown:\n test.txt\n"
836
558
out = capture("status test.txt --all")
837
self.assertEquals(out, "unknown:\n test.txt\n")
559
assert out == "unknown:\n test.txt\n"
839
561
f = file('test2.txt', 'wt')
840
562
f.write('goodbye cruel world...\n')
843
565
out = capture("status test.txt")
844
self.assertEquals(out, "unknown:\n test.txt\n")
566
assert out == "unknown:\n test.txt\n"
846
568
out = capture("status")
847
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
569
assert out == ("unknown:\n"
849
573
os.unlink('test2.txt')
851
575
progress("command aliases")
852
576
out = capture("st --all")
853
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
577
assert out == ("unknown:\n"
855
580
out = capture("stat")
856
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
581
assert out == ("unknown:\n"
858
584
progress("command help")
859
585
runbzr("help st")
861
587
runbzr("help commands")
862
runbzr("help slartibartfast", 3)
588
runbzr("help slartibartfast", 1)
864
590
out = capture("help ci")
865
591
out.index('aliases: ')
867
593
progress("can't rename unversioned file")
868
runbzr("rename test.txt new-test.txt", 3)
594
runbzr("rename test.txt new-test.txt", 1)
870
596
progress("adding a file")
872
598
runbzr("add test.txt")
873
self.assertEquals(capture("unknowns"), '')
874
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
599
assert capture("unknowns") == ''
600
assert capture("status --all") == ("added:\n"
876
603
progress("rename newly-added file")
877
604
runbzr("rename test.txt hello.txt")
878
self.assert_(os.path.exists("hello.txt"))
879
self.assert_(not os.path.exists("test.txt"))
605
assert os.path.exists("hello.txt")
606
assert not os.path.exists("test.txt")
881
self.assertEquals(capture("revno"), '0\n')
608
assert capture("revno") == '0\n'
883
610
progress("add first revision")
884
611
runbzr(['commit', '-m', 'add first revision'])
886
613
progress("more complex renames")
888
runbzr("rename hello.txt sub1", 3)
889
runbzr("rename hello.txt sub1/hello.txt", 3)
890
runbzr("move hello.txt sub1", 3)
615
runbzr("rename hello.txt sub1", 1)
616
runbzr("rename hello.txt sub1/hello.txt", 1)
617
runbzr("move hello.txt sub1", 1)
892
619
runbzr("add sub1")
893
620
runbzr("rename sub1 sub2")
894
621
runbzr("move hello.txt sub2")
895
self.assertEqual(capture("relpath sub2/hello.txt"),
896
pathjoin("sub2", "hello.txt\n"))
622
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
898
self.assert_(exists("sub2"))
899
self.assert_(exists("sub2/hello.txt"))
900
self.assert_(not exists("sub1"))
901
self.assert_(not exists("hello.txt"))
624
assert exists("sub2")
625
assert exists("sub2/hello.txt")
626
assert not exists("sub1")
627
assert not exists("hello.txt")
903
629
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
906
632
runbzr('add sub1')
907
633
runbzr('move sub2/hello.txt sub1')
908
self.assert_(not exists('sub2/hello.txt'))
909
self.assert_(exists('sub1/hello.txt'))
634
assert not exists('sub2/hello.txt')
635
assert exists('sub1/hello.txt')
910
636
runbzr('move sub2 sub1')
911
self.assert_(not exists('sub2'))
912
self.assert_(exists('sub1/sub2'))
637
assert not exists('sub2')
638
assert exists('sub1/sub2')
914
640
runbzr(['commit', '-m', 'rename nested subdirectories'])
916
642
chdir('sub1/sub2')
917
643
self.assertEquals(capture('root')[:-1],
918
pathjoin(self.test_dir, 'branch1'))
644
os.path.join(self.test_dir, 'branch1'))
919
645
runbzr('move ../hello.txt .')
920
self.assert_(exists('./hello.txt'))
646
assert exists('./hello.txt')
921
647
self.assertEquals(capture('relpath hello.txt'),
922
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
923
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
648
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
649
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
924
650
runbzr(['commit', '-m', 'move to parent directory'])
926
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
652
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
928
654
runbzr('move sub2/hello.txt .')
929
self.assert_(exists('hello.txt'))
655
assert exists('hello.txt')
931
657
f = file('hello.txt', 'wt')
932
658
f.write('some nice new content\n')
935
661
f = file('msg.tmp', 'wt')
936
f.write('this is my new commit\nand it has multiple lines, for fun')
662
f.write('this is my new commit\n')
939
665
runbzr('commit -F msg.tmp')
941
self.assertEquals(capture('revno'), '5\n')
667
assert capture('revno') == '5\n'
942
668
runbzr('export -r 5 export-5.tmp')
943
669
runbzr('export export.tmp')
947
673
runbzr('log -v --forward')
948
runbzr('log -m', retcode=3)
674
runbzr('log -m', retcode=1)
949
675
log_out = capture('log -m commit')
950
self.assert_("this is my new commit\n and" in log_out)
951
self.assert_("rename nested" not in log_out)
952
self.assert_('revision-id' not in log_out)
953
self.assert_('revision-id' in capture('log --show-ids -m commit'))
955
log_out = capture('log --line')
956
for line in log_out.splitlines():
957
self.assert_(len(line) <= 79, len(line))
958
self.assert_("this is my new commit and" in log_out)
676
assert "this is my new commit" in log_out
677
assert "rename nested" not in log_out
678
assert 'revision-id' not in log_out
679
assert 'revision-id' in capture('log --show-ids -m commit')
961
682
progress("file with spaces in name")
962
683
mkdir('sub directory')
963
684
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
965
runbzr('diff', retcode=1)
966
687
runbzr('commit -m add-spaces')
979
700
os.symlink("NOWHERE1", "link1")
980
701
runbzr('add link1')
981
self.assertEquals(self.capture('unknowns'), '')
702
assert self.capture('unknowns') == ''
982
703
runbzr(['commit', '-m', '1: added symlink link1'])
986
self.assertEquals(self.capture('unknowns'), '')
707
assert self.capture('unknowns') == ''
987
708
os.symlink("NOWHERE2", "d1/link2")
988
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
709
assert self.capture('unknowns') == 'd1/link2\n'
989
710
# is d1/link2 found when adding d1
991
self.assertEquals(self.capture('unknowns'), '')
712
assert self.capture('unknowns') == ''
992
713
os.symlink("NOWHERE3", "d1/link3")
993
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
714
assert self.capture('unknowns') == 'd1/link3\n'
994
715
runbzr(['commit', '-m', '2: added dir, symlink'])
996
717
runbzr('rename d1 d2')
997
718
runbzr('move d2/link2 .')
998
719
runbzr('move link1 d2')
999
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1000
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
720
assert os.readlink("./link2") == "NOWHERE2"
721
assert os.readlink("d2/link1") == "NOWHERE1"
1001
722
runbzr('add d2/link3')
1002
runbzr('diff', retcode=1)
1003
724
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1005
726
os.unlink("link2")
1006
727
os.symlink("TARGET 2", "link2")
1007
728
os.unlink("d2/link1")
1008
729
os.symlink("TARGET 1", "d2/link1")
1009
runbzr('diff', retcode=1)
1010
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
731
assert self.capture("relpath d2/link1") == "d2/link1\n"
1011
732
runbzr(['commit', '-m', '4: retarget of two links'])
1013
734
runbzr('remove d2/link1')
1014
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
735
assert self.capture('unknowns') == 'd2/link1\n'
1015
736
runbzr(['commit', '-m', '5: remove d2/link1'])
1016
737
# try with the rm alias
1017
738
runbzr('add d2/link1')
1018
739
runbzr(['commit', '-m', '6: add d2/link1'])
1019
740
runbzr('rm d2/link1')
1020
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
741
assert self.capture('unknowns') == 'd2/link1\n'
1021
742
runbzr(['commit', '-m', '7: remove d2/link1'])
1024
745
runbzr('add d1')
1025
746
runbzr('rename d2/link3 d1/link3new')
1026
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
747
assert self.capture('unknowns') == 'd2/link1\n'
1027
748
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1029
750
runbzr(['check'])
1031
752
runbzr(['export', '-r', '1', 'exp1.tmp'])
1032
753
chdir("exp1.tmp")
1033
self.assertEquals(listdir_sorted("."), [ "link1" ])
1034
self.assertEquals(os.readlink("link1"), "NOWHERE1")
754
assert listdir_sorted(".") == [ "link1" ]
755
assert os.readlink("link1") == "NOWHERE1"
1037
758
runbzr(['export', '-r', '2', 'exp2.tmp'])
1038
759
chdir("exp2.tmp")
1039
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
760
assert listdir_sorted(".") == [ "d1", "link1" ]
1042
763
runbzr(['export', '-r', '3', 'exp3.tmp'])
1043
764
chdir("exp3.tmp")
1044
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1045
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1046
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1047
self.assertEquals(os.readlink("link2") , "NOWHERE2")
765
assert listdir_sorted(".") == [ "d2", "link2" ]
766
assert listdir_sorted("d2") == [ "link1", "link3" ]
767
assert os.readlink("d2/link1") == "NOWHERE1"
768
assert os.readlink("link2") == "NOWHERE2"
1050
771
runbzr(['export', '-r', '4', 'exp4.tmp'])
1051
772
chdir("exp4.tmp")
1052
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1053
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1054
self.assertEquals(os.readlink("link2") , "TARGET 2")
1055
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
773
assert listdir_sorted(".") == [ "d2", "link2" ]
774
assert os.readlink("d2/link1") == "TARGET 1"
775
assert os.readlink("link2") == "TARGET 2"
776
assert listdir_sorted("d2") == [ "link1", "link3" ]
1058
779
runbzr(['export', '-r', '5', 'exp5.tmp'])
1059
780
chdir("exp5.tmp")
1060
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1061
self.assert_(os.path.islink("link2"))
1062
self.assert_(listdir_sorted("d2")== [ "link3" ])
781
assert listdir_sorted(".") == [ "d2", "link2" ]
782
assert os.path.islink("link2")
783
assert listdir_sorted("d2")== [ "link3" ]
1065
786
runbzr(['export', '-r', '8', 'exp6.tmp'])
1066
787
chdir("exp6.tmp")
1067
788
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1068
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1069
self.assertEquals(listdir_sorted("d2"), [])
1070
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
789
assert listdir_sorted("d1") == [ "link3new" ]
790
assert listdir_sorted("d2") == []
791
assert os.readlink("d1/link3new") == "NOWHERE3"
1073
794
progress("skipping symlink tests")
1076
class RemoteTests(object):
797
class HttpTests(TestCaseWithWebserver):
1077
798
"""Test bzr ui commands against remote branches."""
1079
800
def test_branch(self):
1080
801
os.mkdir('from')
1081
wt = self.make_branch_and_tree('from')
1083
wt.commit('empty commit for nonsense', allow_pointless=True)
1084
url = self.get_readonly_url('from')
802
branch = Branch.initialize('from')
803
branch.commit('empty commit for nonsense', allow_pointless=True)
804
url = self.get_remote_url('from')
1085
805
self.run_bzr('branch', url, 'to')
1086
806
branch = Branch.open('to')
1087
807
self.assertEqual(1, len(branch.revision_history()))
1088
# the branch should be set in to to from
1089
self.assertEqual(url + '/', branch.get_parent())
1092
self.build_tree(['branch/', 'branch/file'])
1093
self.capture('init branch')
1094
self.capture('add branch/file')
1095
self.capture('commit -m foo branch')
1096
url = self.get_readonly_url('branch/file')
1097
output = self.capture('log %s' % url)
1098
self.assertEqual(8, len(output.split('\n')))
1100
def test_check(self):
1101
self.build_tree(['branch/', 'branch/file'])
1102
self.capture('init branch')
1103
self.capture('add branch/file')
1104
self.capture('commit -m foo branch')
1105
url = self.get_readonly_url('branch/')
1106
self.run_bzr('check', url)
1108
def test_push(self):
1109
# create a source branch
1110
os.mkdir('my-branch')
1111
os.chdir('my-branch')
1112
self.run_bzr('init')
1113
file('hello', 'wt').write('foo')
1114
self.run_bzr('add', 'hello')
1115
self.run_bzr('commit', '-m', 'setup')
1117
# with an explicit target work
1118
self.run_bzr('push', self.get_url('output-branch'))
1121
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1122
"""Test various commands against a HTTP server."""
1125
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1126
"""Test various commands against a SFTP server using abs paths."""
1129
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1130
"""Test various commands against a SFTP server using abs paths."""
1133
super(SFTPTestsAbsoluteSibling, self).setUp()
1134
self._override_home = '/dev/noone/runs/tests/here'
1137
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1138
"""Test various commands against a SFTP server using homedir rel paths."""
1141
super(SFTPTestsRelative, self).setUp()
1142
self._get_remote_is_absolute = False