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
234
self.runbzr('export ../latest')
227
235
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
228
236
self.runbzr('export ../first -r 1')
229
self.assert_(not os.path.exists('../first/goodbye'))
237
assert not os.path.exists('../first/goodbye')
230
238
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
231
239
self.runbzr('export ../first.gz -r 1')
232
240
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
233
241
self.runbzr('export ../first.bz2 -r 1')
234
242
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
243
self.runbzr('export ../first.tar -r 1')
244
assert os.path.isfile('../first.tar')
236
245
from tarfile import TarFile
237
self.runbzr('export ../first.tar -r 1')
238
self.assert_(os.path.isfile('../first.tar'))
239
246
tf = TarFile('../first.tar')
240
self.assert_('first/hello' in tf.getnames(), tf.getnames())
247
assert 'first/hello' in tf.getnames(), tf.getnames()
241
248
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
249
self.runbzr('export ../first.tar.gz -r 1')
243
self.assert_(os.path.isfile('../first.tar.gz'))
250
assert os.path.isfile('../first.tar.gz')
244
251
self.runbzr('export ../first.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tbz2'))
252
assert os.path.isfile('../first.tbz2')
246
253
self.runbzr('export ../first.tar.bz2 -r 1')
247
self.assert_(os.path.isfile('../first.tar.bz2'))
254
assert os.path.isfile('../first.tar.bz2')
248
255
self.runbzr('export ../first.tar.tbz2 -r 1')
249
self.assert_(os.path.isfile('../first.tar.tbz2'))
256
assert os.path.isfile('../first.tar.tbz2')
251
257
from bz2 import BZ2File
252
258
tf = TarFile('../first.tar.tbz2',
253
259
fileobj=BZ2File('../first.tar.tbz2', 'r'))
254
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
260
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
255
261
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
256
262
self.runbzr('export ../first2.tar -r 1 --root pizza')
257
263
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())
264
assert 'pizza/hello' in tf.getnames(), tf.getnames()
267
self.example_branch()
268
file('hello', 'wt').write('hello world!')
269
self.runbzr('commit -m fixing hello')
270
output = self.runbzr('diff -r 2..3', backtick=1)
271
self.assert_('\n+hello world!' in output)
272
output = self.runbzr('diff -r last:3..last:1', backtick=1)
273
self.assert_('\n+baz' in output)
275
def test_diff_branches(self):
276
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
277
branch = Branch.initialize('branch1')
279
branch.commit('add file')
280
copy_branch(branch, 'branch2')
281
print >> open('branch2/file', 'w'), 'new content'
282
branch2 = Branch.open('branch2')
283
branch2.commit('update file')
284
# should open branch1 and diff against branch2,
285
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
286
self.assertEquals(("=== modified file 'file'\n"
291
"+contents of branch1/file\n"
275
294
def test_branch(self):
276
295
"""Branch from one branch to another."""
279
298
self.example_branch()
281
300
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
301
self.runbzr('branch a c -r 1')
286
303
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')
305
# naughty - abstraction violations RBC 20050928
306
print "test_branch used to delete the stores, how is this meant to work ?"
307
#shutil.rmtree('a/.bzr/revision-store')
308
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
309
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
310
self.runbzr('branch a d --basis b')
312
def test_merge(self):
313
from bzrlib.branch import Branch
317
self.example_branch()
319
self.runbzr('branch a b')
321
file('goodbye', 'wt').write('quux')
322
self.runbzr(['commit', '-m', "more u's are always good"])
325
file('hello', 'wt').write('quuux')
326
# We can't merge when there are in-tree changes
327
self.runbzr('merge ../b', retcode=1)
328
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
329
self.runbzr('merge ../b')
330
self.check_file_contents('goodbye', 'quux')
331
# Merging a branch pulls its revision into the tree
333
b = Branch.open('../b')
334
a.get_revision_xml(b.last_revision())
335
self.log('pending merges: %s', a.pending_merges())
336
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
337
# % (a.pending_merges(), b.last_patch())
339
def test_merge_with_missing_file(self):
340
"""Merge handles missing file conflicts"""
344
print >> file('sub/a.txt', 'wb'), "hello"
345
print >> file('b.txt', 'wb'), "hello"
346
print >> file('sub/c.txt', 'wb'), "hello"
349
self.runbzr(('commit', '-m', 'added a'))
350
self.runbzr('branch . ../b')
351
print >> file('sub/a.txt', 'ab'), "there"
352
print >> file('b.txt', 'ab'), "there"
353
print >> file('sub/c.txt', 'ab'), "there"
354
self.runbzr(('commit', '-m', 'Added there'))
355
os.unlink('sub/a.txt')
356
os.unlink('sub/c.txt')
359
self.runbzr(('commit', '-m', 'Removed a.txt'))
361
print >> file('sub/a.txt', 'ab'), "something"
362
print >> file('b.txt', 'ab'), "something"
363
print >> file('sub/c.txt', 'ab'), "something"
364
self.runbzr(('commit', '-m', 'Modified a.txt'))
365
self.runbzr('merge ../a/')
366
assert os.path.exists('sub/a.txt.THIS')
367
assert os.path.exists('sub/a.txt.BASE')
369
self.runbzr('merge ../b/')
370
assert os.path.exists('sub/a.txt.OTHER')
371
assert os.path.exists('sub/a.txt.BASE')
374
"""Pull changes from one branch to another."""
378
self.example_branch()
379
self.runbzr('pull', retcode=1)
380
self.runbzr('missing', retcode=1)
381
self.runbzr('missing .')
382
self.runbzr('missing')
384
self.runbzr('pull /', retcode=1)
388
self.runbzr('branch a b')
355
391
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'])
392
self.runbzr('add subdir')
393
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')
396
b = Branch.open('../b')
397
assert a.revision_history() == b.revision_history()[:-1]
398
self.runbzr('pull ../b')
399
assert a.revision_history() == b.revision_history()
400
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)
402
self.runbzr('commit -m blah3 --unchanged')
403
self.runbzr('pull ../a', retcode=1)
405
self.runbzr('merge ../b')
406
self.runbzr('commit -m blah4 --unchanged')
407
os.chdir('../b/subdir')
408
self.runbzr('pull ../../a')
409
assert a.revision_history()[-1] == b.revision_history()[-1]
410
self.runbzr('commit -m blah5 --unchanged')
411
self.runbzr('commit -m blah6 --unchanged')
413
self.runbzr('pull ../a')
415
self.runbzr('commit -m blah7 --unchanged')
416
self.runbzr('merge ../b')
417
self.runbzr('commit -m blah8 --unchanged')
418
self.runbzr('pull ../b')
419
self.runbzr('pull ../b')
475
421
def test_locations(self):
476
422
"""Using and remembering different locations"""
479
425
self.runbzr('init')
480
426
self.runbzr('commit -m unchanged --unchanged')
481
self.runbzr('pull', retcode=3)
482
self.runbzr('merge', retcode=3)
427
self.runbzr('pull', retcode=1)
428
self.runbzr('merge', retcode=1)
483
429
self.runbzr('branch . ../b')
485
431
self.runbzr('pull')
497
443
self.runbzr('pull')
499
self.runbzr('pull', retcode=3)
445
self.runbzr('pull', retcode=1)
500
446
self.runbzr('pull ../a --remember')
501
447
self.runbzr('pull')
503
449
def test_add_reports(self):
504
450
"""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]
451
b = Branch.initialize('.')
452
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
453
out = self.run_bzr_captured(['add'], retcode = 0)[0]
508
454
# the ordering is not defined at the moment
509
455
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"'],
456
self.assertEquals(['added dir',
457
'added dir'+os.sep+'sub.txt',
524
461
def test_add_quiet_is(self):
525
462
"""add -q does not print the names of added files."""
463
b = Branch.initialize('.')
527
464
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
528
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
465
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
529
466
# the ordering is not defined at the moment
530
467
results = sorted(out.rstrip('\n').split('\n'))
531
468
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
470
def test_unknown_command(self):
600
471
"""Handling of unknown command."""
601
472
out, err = self.run_bzr_captured(['fluffy-badger'],
603
474
self.assertEquals(out, '')
604
475
err.index('unknown command')
606
def create_conflicts(self):
607
"""Create a conflicted tree"""
477
def test_conflicts(self):
478
"""Handling of merge conflicts"""
610
481
file('hello', 'wb').write("hi world")
624
495
file('question', 'wb').write("What do you get when you multiply six"
626
497
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)
498
self.runbzr('merge ../other')
693
499
result = self.runbzr('conflicts', backtick=1)
694
self.assertEquals(result, "Text conflict in hello\nText conflict in"
500
self.assertEquals(result, "hello\nquestion\n")
696
501
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)
502
assert "conflicts:\n hello\n question\n" in result, result
699
503
self.runbzr('resolve hello')
700
504
result = self.runbzr('conflicts', backtick=1)
701
self.assertEquals(result, "Text conflict in question\n")
702
self.runbzr('commit -m conflicts', retcode=3)
505
self.assertEquals(result, "question\n")
506
self.runbzr('commit -m conflicts', retcode=1)
703
507
self.runbzr('resolve --all')
704
508
result = self.runbzr('conflicts', backtick=1)
705
509
self.runbzr('commit -m conflicts')
706
510
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)
512
def test_resign(self):
513
"""Test re signing of data."""
515
oldstrategy = bzrlib.gpg.GPGStrategy
516
branch = Branch.initialize('.')
517
branch.commit("base", allow_pointless=True, rev_id='A')
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)
519
# monkey patch gpg signing mechanism
520
from bzrlib.testament import Testament
521
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
522
self.runbzr('re-sign -r revid:A')
523
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
524
branch.revision_store.get('A', 'sig').read())
794
os.environ['BZRPATH'] = oldpath
526
bzrlib.gpg.GPGStrategy = oldstrategy
797
528
def listdir_sorted(dir):
798
529
L = os.listdir(dir)
828
559
self.assertEquals(capture('unknowns'), 'test.txt\n')
830
561
out = capture("status")
831
self.assertEquals(out, 'unknown:\n test.txt\n')
562
assert out == 'unknown:\n test.txt\n'
833
564
out = capture("status --all")
834
self.assertEquals(out, "unknown:\n test.txt\n")
565
assert out == "unknown:\n test.txt\n"
836
567
out = capture("status test.txt --all")
837
self.assertEquals(out, "unknown:\n test.txt\n")
568
assert out == "unknown:\n test.txt\n"
839
570
f = file('test2.txt', 'wt')
840
571
f.write('goodbye cruel world...\n')
843
574
out = capture("status test.txt")
844
self.assertEquals(out, "unknown:\n test.txt\n")
575
assert out == "unknown:\n test.txt\n"
846
577
out = capture("status")
847
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
578
assert out == ("unknown:\n"
849
582
os.unlink('test2.txt')
851
584
progress("command aliases")
852
585
out = capture("st --all")
853
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
586
assert out == ("unknown:\n"
855
589
out = capture("stat")
856
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
590
assert out == ("unknown:\n"
858
593
progress("command help")
859
594
runbzr("help st")
861
596
runbzr("help commands")
862
runbzr("help slartibartfast", 3)
597
runbzr("help slartibartfast", 1)
864
599
out = capture("help ci")
865
600
out.index('aliases: ')
867
602
progress("can't rename unversioned file")
868
runbzr("rename test.txt new-test.txt", 3)
603
runbzr("rename test.txt new-test.txt", 1)
870
605
progress("adding a file")
872
607
runbzr("add test.txt")
873
self.assertEquals(capture("unknowns"), '')
874
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
608
assert capture("unknowns") == ''
609
assert capture("status --all") == ("added:\n"
876
612
progress("rename newly-added file")
877
613
runbzr("rename test.txt hello.txt")
878
self.assert_(os.path.exists("hello.txt"))
879
self.assert_(not os.path.exists("test.txt"))
614
assert os.path.exists("hello.txt")
615
assert not os.path.exists("test.txt")
881
self.assertEquals(capture("revno"), '0\n')
617
assert capture("revno") == '0\n'
883
619
progress("add first revision")
884
620
runbzr(['commit', '-m', 'add first revision'])
886
622
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)
624
runbzr("rename hello.txt sub1", 1)
625
runbzr("rename hello.txt sub1/hello.txt", 1)
626
runbzr("move hello.txt sub1", 1)
892
628
runbzr("add sub1")
893
629
runbzr("rename sub1 sub2")
894
630
runbzr("move hello.txt sub2")
895
631
self.assertEqual(capture("relpath sub2/hello.txt"),
896
pathjoin("sub2", "hello.txt\n"))
632
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"))
634
assert exists("sub2")
635
assert exists("sub2/hello.txt")
636
assert not exists("sub1")
637
assert not exists("hello.txt")
903
639
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
906
642
runbzr('add sub1')
907
643
runbzr('move sub2/hello.txt sub1')
908
self.assert_(not exists('sub2/hello.txt'))
909
self.assert_(exists('sub1/hello.txt'))
644
assert not exists('sub2/hello.txt')
645
assert exists('sub1/hello.txt')
910
646
runbzr('move sub2 sub1')
911
self.assert_(not exists('sub2'))
912
self.assert_(exists('sub1/sub2'))
647
assert not exists('sub2')
648
assert exists('sub1/sub2')
914
650
runbzr(['commit', '-m', 'rename nested subdirectories'])
916
652
chdir('sub1/sub2')
917
653
self.assertEquals(capture('root')[:-1],
918
pathjoin(self.test_dir, 'branch1'))
654
os.path.join(self.test_dir, 'branch1'))
919
655
runbzr('move ../hello.txt .')
920
self.assert_(exists('./hello.txt'))
656
assert exists('./hello.txt')
921
657
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'))
658
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
659
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
924
660
runbzr(['commit', '-m', 'move to parent directory'])
926
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
662
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
928
664
runbzr('move sub2/hello.txt .')
929
self.assert_(exists('hello.txt'))
665
assert exists('hello.txt')
931
667
f = file('hello.txt', 'wt')
932
668
f.write('some nice new content\n')
979
715
os.symlink("NOWHERE1", "link1")
980
716
runbzr('add link1')
981
self.assertEquals(self.capture('unknowns'), '')
717
assert self.capture('unknowns') == ''
982
718
runbzr(['commit', '-m', '1: added symlink link1'])
986
self.assertEquals(self.capture('unknowns'), '')
722
assert self.capture('unknowns') == ''
987
723
os.symlink("NOWHERE2", "d1/link2")
988
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
724
assert self.capture('unknowns') == 'd1/link2\n'
989
725
# is d1/link2 found when adding d1
991
self.assertEquals(self.capture('unknowns'), '')
727
assert self.capture('unknowns') == ''
992
728
os.symlink("NOWHERE3", "d1/link3")
993
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
729
assert self.capture('unknowns') == 'd1/link3\n'
994
730
runbzr(['commit', '-m', '2: added dir, symlink'])
996
732
runbzr('rename d1 d2')
997
733
runbzr('move d2/link2 .')
998
734
runbzr('move link1 d2')
999
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1000
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
735
assert os.readlink("./link2") == "NOWHERE2"
736
assert os.readlink("d2/link1") == "NOWHERE1"
1001
737
runbzr('add d2/link3')
1002
runbzr('diff', retcode=1)
1003
739
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1005
741
os.unlink("link2")
1006
742
os.symlink("TARGET 2", "link2")
1007
743
os.unlink("d2/link1")
1008
744
os.symlink("TARGET 1", "d2/link1")
1009
runbzr('diff', retcode=1)
1010
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
746
assert self.capture("relpath d2/link1") == "d2/link1\n"
1011
747
runbzr(['commit', '-m', '4: retarget of two links'])
1013
749
runbzr('remove d2/link1')
1014
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
750
assert self.capture('unknowns') == 'd2/link1\n'
1015
751
runbzr(['commit', '-m', '5: remove d2/link1'])
1016
752
# try with the rm alias
1017
753
runbzr('add d2/link1')
1018
754
runbzr(['commit', '-m', '6: add d2/link1'])
1019
755
runbzr('rm d2/link1')
1020
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
756
assert self.capture('unknowns') == 'd2/link1\n'
1021
757
runbzr(['commit', '-m', '7: remove d2/link1'])
1024
760
runbzr('add d1')
1025
761
runbzr('rename d2/link3 d1/link3new')
1026
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
762
assert self.capture('unknowns') == 'd2/link1\n'
1027
763
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1029
765
runbzr(['check'])
1031
767
runbzr(['export', '-r', '1', 'exp1.tmp'])
1032
768
chdir("exp1.tmp")
1033
self.assertEquals(listdir_sorted("."), [ "link1" ])
1034
self.assertEquals(os.readlink("link1"), "NOWHERE1")
769
assert listdir_sorted(".") == [ "link1" ]
770
assert os.readlink("link1") == "NOWHERE1"
1037
773
runbzr(['export', '-r', '2', 'exp2.tmp'])
1038
774
chdir("exp2.tmp")
1039
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
775
assert listdir_sorted(".") == [ "d1", "link1" ]
1042
778
runbzr(['export', '-r', '3', 'exp3.tmp'])
1043
779
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")
780
assert listdir_sorted(".") == [ "d2", "link2" ]
781
assert listdir_sorted("d2") == [ "link1", "link3" ]
782
assert os.readlink("d2/link1") == "NOWHERE1"
783
assert os.readlink("link2") == "NOWHERE2"
1050
786
runbzr(['export', '-r', '4', 'exp4.tmp'])
1051
787
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" ])
788
assert listdir_sorted(".") == [ "d2", "link2" ]
789
assert os.readlink("d2/link1") == "TARGET 1"
790
assert os.readlink("link2") == "TARGET 2"
791
assert listdir_sorted("d2") == [ "link1", "link3" ]
1058
794
runbzr(['export', '-r', '5', 'exp5.tmp'])
1059
795
chdir("exp5.tmp")
1060
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1061
self.assert_(os.path.islink("link2"))
1062
self.assert_(listdir_sorted("d2")== [ "link3" ])
796
assert listdir_sorted(".") == [ "d2", "link2" ]
797
assert os.path.islink("link2")
798
assert listdir_sorted("d2")== [ "link3" ]
1065
801
runbzr(['export', '-r', '8', 'exp6.tmp'])
1066
802
chdir("exp6.tmp")
1067
803
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")
804
assert listdir_sorted("d1") == [ "link3new" ]
805
assert listdir_sorted("d2") == []
806
assert os.readlink("d1/link3new") == "NOWHERE3"
1073
809
progress("skipping symlink tests")
1076
class RemoteTests(object):
812
class HttpTests(TestCaseWithWebserver):
1077
813
"""Test bzr ui commands against remote branches."""
1079
815
def test_branch(self):
1080
816
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')
817
branch = Branch.initialize('from')
818
branch.commit('empty commit for nonsense', allow_pointless=True)
819
url = self.get_remote_url('from')
1085
820
self.run_bzr('branch', url, 'to')
1086
821
branch = Branch.open('to')
1087
822
self.assertEqual(1, len(branch.revision_history()))
1088
# the branch should be set in to to from
1089
self.assertEqual(url + '/', branch.get_parent())
1091
824
def test_log(self):
1092
825
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')
826
branch = Branch.initialize('branch')
828
branch.commit('add file', rev_id='A')
829
url = self.get_remote_url('branch/file')
1097
830
output = self.capture('log %s' % url)
1098
self.assertEqual(8, len(output.split('\n')))
831
self.assertEqual(7, 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