222
219
self.runbzr('export ../latest')
223
220
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
224
221
self.runbzr('export ../first -r 1')
225
self.assert_(not os.path.exists('../first/goodbye'))
222
assert not os.path.exists('../first/goodbye')
226
223
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
227
224
self.runbzr('export ../first.gz -r 1')
228
225
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
229
226
self.runbzr('export ../first.bz2 -r 1')
230
227
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
228
self.runbzr('export ../first.tar -r 1')
229
assert os.path.isfile('../first.tar')
232
230
from tarfile import TarFile
233
self.runbzr('export ../first.tar -r 1')
234
self.assert_(os.path.isfile('../first.tar'))
235
231
tf = TarFile('../first.tar')
236
self.assert_('first/hello' in tf.getnames(), tf.getnames())
232
assert 'first/hello' in tf.getnames(), tf.getnames()
237
233
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
238
234
self.runbzr('export ../first.tar.gz -r 1')
239
self.assert_(os.path.isfile('../first.tar.gz'))
235
assert os.path.isfile('../first.tar.gz')
240
236
self.runbzr('export ../first.tbz2 -r 1')
241
self.assert_(os.path.isfile('../first.tbz2'))
237
assert os.path.isfile('../first.tbz2')
242
238
self.runbzr('export ../first.tar.bz2 -r 1')
243
self.assert_(os.path.isfile('../first.tar.bz2'))
239
assert os.path.isfile('../first.tar.bz2')
244
240
self.runbzr('export ../first.tar.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tar.tbz2'))
241
assert os.path.isfile('../first.tar.tbz2')
247
242
from bz2 import BZ2File
248
243
tf = TarFile('../first.tar.tbz2',
249
244
fileobj=BZ2File('../first.tar.tbz2', 'r'))
250
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
245
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
251
246
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
252
247
self.runbzr('export ../first2.tar -r 1 --root pizza')
253
248
tf = TarFile('../first2.tar')
254
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
256
from zipfile import ZipFile
257
self.runbzr('export ../first.zip -r 1')
258
self.failUnlessExists('../first.zip')
259
zf = ZipFile('../first.zip')
260
self.assert_('first/hello' in zf.namelist(), zf.namelist())
261
self.assertEqual(zf.read('first/hello'), 'foo')
263
self.runbzr('export ../first2.zip -r 1 --root pizza')
264
zf = ZipFile('../first2.zip')
265
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
267
self.runbzr('export ../first-zip --format=zip -r 1')
268
zf = ZipFile('../first-zip')
269
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
271
def test_inventory(self):
273
def output_equals(value, *args):
274
out = self.runbzr(['inventory'] + list(args), backtick=True)
275
self.assertEquals(out, value)
278
open('a', 'wb').write('hello\n')
284
output_equals('a\n', '--kind', 'file')
285
output_equals('b\n', '--kind', 'directory')
288
"""Test the abilities of 'bzr ls'"""
290
def bzrout(*args, **kwargs):
291
kwargs['backtick'] = True
292
return self.runbzr(*args, **kwargs)
294
def ls_equals(value, *args):
295
out = self.runbzr(['ls'] + list(args), backtick=True)
296
self.assertEquals(out, value)
299
open('a', 'wb').write('hello\n')
302
bzr('ls --verbose --null', retcode=3)
305
ls_equals('? a\n', '--verbose')
306
ls_equals('a\n', '--unknown')
307
ls_equals('', '--ignored')
308
ls_equals('', '--versioned')
309
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
310
ls_equals('', '--ignored', '--versioned')
311
ls_equals('a\0', '--null')
314
ls_equals('V a\n', '--verbose')
249
assert 'pizza/hello' in tf.getnames(), tf.getnames()
252
self.example_branch()
253
file('hello', 'wt').write('hello world!')
254
self.runbzr('commit -m fixing hello')
255
output = self.runbzr('diff -r 2..3', backtick=1)
256
self.assert_('\n+hello world!' in output)
257
output = self.runbzr('diff -r last:3..last:1', backtick=1)
258
self.assert_('\n+baz' in output)
260
def test_branch(self):
261
"""Branch from one branch to another."""
264
self.example_branch()
266
self.runbzr('branch a b')
267
self.runbzr('branch a c -r 1')
269
self.runbzr('commit -m foo --unchanged')
271
# naughty - abstraction violations RBC 20050928
272
print "test_branch used to delete the stores, how is this meant to work ?"
273
#shutil.rmtree('a/.bzr/revision-store')
274
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
275
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
276
self.runbzr('branch a d --basis b')
278
def test_merge(self):
279
from bzrlib.branch import Branch
283
self.example_branch()
285
self.runbzr('branch a b')
287
file('goodbye', 'wt').write('quux')
288
self.runbzr(['commit', '-m', "more u's are always good"])
291
file('hello', 'wt').write('quuux')
292
# We can't merge when there are in-tree changes
293
self.runbzr('merge ../b', retcode=1)
294
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
295
self.runbzr('merge ../b')
296
self.check_file_contents('goodbye', 'quux')
297
# Merging a branch pulls its revision into the tree
299
b = Branch.open('../b')
300
a.get_revision_xml(b.last_revision())
301
self.log('pending merges: %s', a.pending_merges())
302
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
303
# % (a.pending_merges(), b.last_revision())
305
def test_merge_with_missing_file(self):
306
"""Merge handles missing file conflicts"""
310
print >> file('sub/a.txt', 'wb'), "hello"
311
print >> file('b.txt', 'wb'), "hello"
312
print >> file('sub/c.txt', 'wb'), "hello"
315
self.runbzr(('commit', '-m', 'added a'))
316
self.runbzr('branch . ../b')
317
print >> file('sub/a.txt', 'ab'), "there"
318
print >> file('b.txt', 'ab'), "there"
319
print >> file('sub/c.txt', 'ab'), "there"
320
self.runbzr(('commit', '-m', 'Added there'))
321
os.unlink('sub/a.txt')
322
os.unlink('sub/c.txt')
325
self.runbzr(('commit', '-m', 'Removed a.txt'))
327
print >> file('sub/a.txt', 'ab'), "something"
328
print >> file('b.txt', 'ab'), "something"
329
print >> file('sub/c.txt', 'ab'), "something"
330
self.runbzr(('commit', '-m', 'Modified a.txt'))
331
self.runbzr('merge ../a/')
332
assert os.path.exists('sub/a.txt.THIS')
333
assert os.path.exists('sub/a.txt.BASE')
335
self.runbzr('merge ../b/')
336
assert os.path.exists('sub/a.txt.OTHER')
337
assert os.path.exists('sub/a.txt.BASE')
340
"""Pull changes from one branch to another."""
344
self.example_branch()
345
self.runbzr('pull', retcode=1)
346
self.runbzr('missing', retcode=1)
347
self.runbzr('missing .')
348
self.runbzr('missing')
350
self.runbzr('pull /', retcode=1)
354
self.runbzr('branch a b')
317
357
os.mkdir('subdir')
321
open('subdir/b', 'wb').write('b\n')
327
bzr('commit -m subdir')
335
, '--verbose', '--non-recursive')
337
# Check what happens in a sub-directory
349
, '--from-root', '--null')
352
, '--from-root', '--non-recursive')
356
# Check what happens when we supply a specific revision
357
ls_equals('a\n', '--revision', '1')
359
, '--verbose', '--revision', '1')
362
ls_equals('', '--revision', '1')
364
# Now try to do ignored files.
366
open('blah.py', 'wb').write('unknown\n')
367
open('blah.pyo', 'wb').write('ignored\n')
379
ls_equals('blah.pyo\n'
381
ls_equals('blah.py\n'
390
file("myfile", "wb").write("My contents\n")
392
self.runbzr('commit -m myfile')
393
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
395
def test_pull_verbose(self):
396
"""Pull changes from one branch to another and watch the output."""
402
self.example_branch()
407
open('b', 'wb').write('else\n')
409
bzr(['commit', '-m', 'added b'])
412
out = bzr('pull --verbose ../b', backtick=True)
413
self.failIfEqual(out.find('Added Revisions:'), -1)
414
self.failIfEqual(out.find('message:\n added b'), -1)
415
self.failIfEqual(out.find('added b'), -1)
417
# Check that --overwrite --verbose prints out the removed entries
418
bzr('commit -m foo --unchanged')
420
bzr('commit -m baz --unchanged')
421
bzr('pull ../a', retcode=3)
422
out = bzr('pull --overwrite --verbose ../a', backtick=1)
424
remove_loc = out.find('Removed Revisions:')
425
self.failIfEqual(remove_loc, -1)
426
added_loc = out.find('Added Revisions:')
427
self.failIfEqual(added_loc, -1)
429
removed_message = out.find('message:\n baz')
430
self.failIfEqual(removed_message, -1)
431
self.failUnless(remove_loc < removed_message < added_loc)
433
added_message = out.find('message:\n foo')
434
self.failIfEqual(added_message, -1)
435
self.failUnless(added_loc < added_message)
437
def test_locations(self):
438
"""Using and remembering different locations"""
442
self.runbzr('commit -m unchanged --unchanged')
443
self.runbzr('pull', retcode=3)
444
self.runbzr('merge', retcode=3)
445
self.runbzr('branch . ../b')
448
self.runbzr('branch . ../c')
449
self.runbzr('pull ../c')
452
self.runbzr('pull ../b')
454
self.runbzr('pull ../c')
455
self.runbzr('branch ../c ../d')
461
self.runbzr('pull', retcode=3)
462
self.runbzr('pull ../a --remember')
358
self.runbzr('add subdir')
359
self.runbzr('commit -m blah --unchanged')
362
b = Branch.open('../b')
363
assert a.revision_history() == b.revision_history()[:-1]
364
self.runbzr('pull ../b')
365
assert a.revision_history() == b.revision_history()
366
self.runbzr('commit -m blah2 --unchanged')
368
self.runbzr('commit -m blah3 --unchanged')
369
self.runbzr('pull ../a', retcode=1)
370
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
373
self.runbzr('merge ../b')
374
self.runbzr('commit -m blah4 --unchanged')
375
os.chdir('../b/subdir')
376
self.runbzr('pull ../../a')
377
assert a.revision_history()[-1] == b.revision_history()[-1]
378
self.runbzr('commit -m blah5 --unchanged')
379
self.runbzr('commit -m blah6 --unchanged')
381
self.runbzr('pull ../a')
383
self.runbzr('commit -m blah7 --unchanged')
384
self.runbzr('merge ../b')
385
self.runbzr('commit -m blah8 --unchanged')
386
self.runbzr('pull ../b')
387
self.runbzr('pull ../b')
389
def test_add_reports(self):
390
"""add command prints the names of added files."""
391
b = Branch.initialize('.')
392
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
393
out = self.run_bzr_captured(['add'], retcode = 0)[0]
394
# the ordering is not defined at the moment
395
results = sorted(out.rstrip('\n').split('\n'))
396
self.assertEquals(['added dir',
397
'added dir'+os.sep+'sub.txt',
465
401
def test_unknown_command(self):
466
402
"""Handling of unknown command."""
467
403
out, err = self.run_bzr_captured(['fluffy-badger'],
469
405
self.assertEquals(out, '')
470
406
err.index('unknown command')
472
def create_conflicts(self):
473
"""Create a conflicted tree"""
476
file('hello', 'wb').write("hi world")
477
file('answer', 'wb').write("42")
480
self.runbzr('commit -m base')
481
self.runbzr('branch . ../other')
482
self.runbzr('branch . ../this')
484
file('hello', 'wb').write("Hello.")
485
file('answer', 'wb').write("Is anyone there?")
486
self.runbzr('commit -m other')
488
file('hello', 'wb').write("Hello, world")
489
self.runbzr('mv answer question')
490
file('question', 'wb').write("What do you get when you multiply six"
492
self.runbzr('commit -m this')
494
def test_remerge(self):
495
"""Remerge command works as expected"""
496
self.create_conflicts()
497
self.runbzr('merge ../other --show-base', retcode=1)
498
conflict_text = file('hello').read()
499
assert '|||||||' in conflict_text
500
assert 'hi world' in conflict_text
501
self.runbzr('remerge', retcode=1)
502
conflict_text = file('hello').read()
503
assert '|||||||' not in conflict_text
504
assert 'hi world' not in conflict_text
505
os.unlink('hello.OTHER')
506
os.unlink('question.OTHER')
507
self.runbzr('remerge jello --merge-type weave', retcode=3)
508
self.runbzr('remerge hello --merge-type weave', retcode=1)
509
assert os.path.exists('hello.OTHER')
510
self.assertIs(False, os.path.exists('question.OTHER'))
511
file_id = self.runbzr('file-id hello')
512
file_id = self.runbzr('file-id hello.THIS', retcode=3)
513
self.runbzr('remerge --merge-type weave', retcode=1)
514
assert os.path.exists('hello.OTHER')
515
assert not os.path.exists('hello.BASE')
516
assert '|||||||' not in conflict_text
517
assert 'hi world' not in conflict_text
518
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
519
self.runbzr('remerge . --show-base --reprocess', retcode=3)
520
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
521
self.runbzr('remerge hello --show-base', retcode=1)
522
self.runbzr('remerge hello --reprocess', retcode=1)
523
self.runbzr('resolve --all')
524
self.runbzr('commit -m done',)
525
self.runbzr('remerge', retcode=3)
527
def test_status(self):
531
self.runbzr('commit --unchanged --message f')
532
self.runbzr('branch . ../branch2')
533
self.runbzr('branch . ../branch3')
534
self.runbzr('commit --unchanged --message peter')
535
os.chdir('../branch2')
536
self.runbzr('merge ../branch1')
537
self.runbzr('commit --unchanged --message pumpkin')
538
os.chdir('../branch3')
539
self.runbzr('merge ../branch2')
540
message = self.capture('status')
543
def test_conflicts(self):
544
"""Handling of merge conflicts"""
545
self.create_conflicts()
546
self.runbzr('merge ../other --show-base', retcode=1)
547
conflict_text = file('hello').read()
548
self.assert_('<<<<<<<' in conflict_text)
549
self.assert_('>>>>>>>' in conflict_text)
550
self.assert_('=======' in conflict_text)
551
self.assert_('|||||||' in conflict_text)
552
self.assert_('hi world' in conflict_text)
553
self.runbzr('revert')
554
self.runbzr('resolve --all')
555
self.runbzr('merge ../other', retcode=1)
556
conflict_text = file('hello').read()
557
self.assert_('|||||||' not in conflict_text)
558
self.assert_('hi world' not in conflict_text)
559
result = self.runbzr('conflicts', backtick=1)
560
self.assertEquals(result, "Text conflict in hello\nText conflict in"
562
result = self.runbzr('status', backtick=1)
563
self.assert_("conflicts:\n Text conflict in hello\n"
564
" Text conflict in question\n" in result, result)
565
self.runbzr('resolve hello')
566
result = self.runbzr('conflicts', backtick=1)
567
self.assertEquals(result, "Text conflict in question\n")
568
self.runbzr('commit -m conflicts', retcode=3)
569
self.runbzr('resolve --all')
570
result = self.runbzr('conflicts', backtick=1)
571
self.runbzr('commit -m conflicts')
572
self.assertEquals(result, "")
575
# create a source branch
576
os.mkdir('my-branch')
577
os.chdir('my-branch')
578
self.example_branch()
580
# with no push target, fail
581
self.runbzr('push', retcode=3)
582
# with an explicit target work
583
self.runbzr('push ../output-branch')
584
# with an implicit target work
587
self.runbzr('missing ../output-branch')
588
# advance this branch
589
self.runbzr('commit --unchanged -m unchanged')
591
os.chdir('../output-branch')
592
# There is no longer a difference as long as we have
593
# access to the working tree
596
# But we should be missing a revision
597
self.runbzr('missing ../my-branch', retcode=1)
599
# diverge the branches
600
self.runbzr('commit --unchanged -m unchanged')
601
os.chdir('../my-branch')
603
self.runbzr('push', retcode=3)
604
# and there are difference
605
self.runbzr('missing ../output-branch', retcode=1)
606
self.runbzr('missing --verbose ../output-branch', retcode=1)
607
# but we can force a push
608
self.runbzr('push --overwrite')
610
self.runbzr('missing ../output-branch')
612
# pushing to a new dir with no parent should fail
613
self.runbzr('push ../missing/new-branch', retcode=3)
614
# unless we provide --create-prefix
615
self.runbzr('push --create-prefix ../missing/new-branch')
617
self.runbzr('missing ../missing/new-branch')
619
def test_external_command(self):
620
"""Test that external commands can be run by setting the path
622
# We don't at present run bzr in a subprocess for blackbox tests, and so
623
# don't really capture stdout, only the internal python stream.
624
# Therefore we don't use a subcommand that produces any output or does
625
# anything -- we just check that it can be run successfully.
626
cmd_name = 'test-command'
627
if sys.platform == 'win32':
629
oldpath = os.environ.get('BZRPATH', None)
632
if os.environ.has_key('BZRPATH'):
633
del os.environ['BZRPATH']
635
f = file(cmd_name, 'wb')
636
if sys.platform == 'win32':
637
f.write('@echo off\n')
639
f.write('#!/bin/sh\n')
640
# f.write('echo Hello from test-command')
642
os.chmod(cmd_name, 0755)
644
# It should not find the command in the local
645
# directory by default, since it is not in my path
646
bzr(cmd_name, retcode=3)
648
# Now put it into my path
649
os.environ['BZRPATH'] = '.'
653
# Make sure empty path elements are ignored
654
os.environ['BZRPATH'] = os.pathsep
656
bzr(cmd_name, retcode=3)
660
os.environ['BZRPATH'] = oldpath
663
409
def listdir_sorted(dir):
664
410
L = os.listdir(dir)
694
440
self.assertEquals(capture('unknowns'), 'test.txt\n')
696
442
out = capture("status")
697
self.assertEquals(out, 'unknown:\n test.txt\n')
443
assert out == 'unknown:\n test.txt\n'
699
445
out = capture("status --all")
700
self.assertEquals(out, "unknown:\n test.txt\n")
446
assert out == "unknown:\n test.txt\n"
702
448
out = capture("status test.txt --all")
703
self.assertEquals(out, "unknown:\n test.txt\n")
449
assert out == "unknown:\n test.txt\n"
705
451
f = file('test2.txt', 'wt')
706
452
f.write('goodbye cruel world...\n')
709
455
out = capture("status test.txt")
710
self.assertEquals(out, "unknown:\n test.txt\n")
456
assert out == "unknown:\n test.txt\n"
712
458
out = capture("status")
713
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
459
assert out == ("unknown:\n"
715
463
os.unlink('test2.txt')
717
465
progress("command aliases")
718
466
out = capture("st --all")
719
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
467
assert out == ("unknown:\n"
721
470
out = capture("stat")
722
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
471
assert out == ("unknown:\n"
724
474
progress("command help")
725
475
runbzr("help st")
727
477
runbzr("help commands")
728
runbzr("help slartibartfast", 3)
478
runbzr("help slartibartfast", 1)
730
480
out = capture("help ci")
731
481
out.index('aliases: ')
733
483
progress("can't rename unversioned file")
734
runbzr("rename test.txt new-test.txt", 3)
484
runbzr("rename test.txt new-test.txt", 1)
736
486
progress("adding a file")
738
488
runbzr("add test.txt")
739
self.assertEquals(capture("unknowns"), '')
740
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
489
assert capture("unknowns") == ''
490
assert capture("status --all") == ("added:\n"
742
493
progress("rename newly-added file")
743
494
runbzr("rename test.txt hello.txt")
744
self.assert_(os.path.exists("hello.txt"))
745
self.assert_(not os.path.exists("test.txt"))
495
assert os.path.exists("hello.txt")
496
assert not os.path.exists("test.txt")
747
self.assertEquals(capture("revno"), '0\n')
498
assert capture("revno") == '0\n'
749
500
progress("add first revision")
750
501
runbzr(['commit', '-m', 'add first revision'])
752
503
progress("more complex renames")
754
runbzr("rename hello.txt sub1", 3)
755
runbzr("rename hello.txt sub1/hello.txt", 3)
756
runbzr("move hello.txt sub1", 3)
505
runbzr("rename hello.txt sub1", 1)
506
runbzr("rename hello.txt sub1/hello.txt", 1)
507
runbzr("move hello.txt sub1", 1)
758
509
runbzr("add sub1")
759
510
runbzr("rename sub1 sub2")
760
511
runbzr("move hello.txt sub2")
761
self.assertEqual(capture("relpath sub2/hello.txt"),
762
pathjoin("sub2", "hello.txt\n"))
512
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
764
self.assert_(exists("sub2"))
765
self.assert_(exists("sub2/hello.txt"))
766
self.assert_(not exists("sub1"))
767
self.assert_(not exists("hello.txt"))
514
assert exists("sub2")
515
assert exists("sub2/hello.txt")
516
assert not exists("sub1")
517
assert not exists("hello.txt")
769
519
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
772
522
runbzr('add sub1')
773
523
runbzr('move sub2/hello.txt sub1')
774
self.assert_(not exists('sub2/hello.txt'))
775
self.assert_(exists('sub1/hello.txt'))
524
assert not exists('sub2/hello.txt')
525
assert exists('sub1/hello.txt')
776
526
runbzr('move sub2 sub1')
777
self.assert_(not exists('sub2'))
778
self.assert_(exists('sub1/sub2'))
527
assert not exists('sub2')
528
assert exists('sub1/sub2')
780
530
runbzr(['commit', '-m', 'rename nested subdirectories'])
782
532
chdir('sub1/sub2')
783
533
self.assertEquals(capture('root')[:-1],
784
pathjoin(self.test_dir, 'branch1'))
534
os.path.join(self.test_dir, 'branch1'))
785
535
runbzr('move ../hello.txt .')
786
self.assert_(exists('./hello.txt'))
536
assert exists('./hello.txt')
787
537
self.assertEquals(capture('relpath hello.txt'),
788
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
789
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
538
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
539
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
790
540
runbzr(['commit', '-m', 'move to parent directory'])
792
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
542
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
794
544
runbzr('move sub2/hello.txt .')
795
self.assert_(exists('hello.txt'))
545
assert exists('hello.txt')
797
547
f = file('hello.txt', 'wt')
798
548
f.write('some nice new content\n')
801
551
f = file('msg.tmp', 'wt')
802
f.write('this is my new commit\nand it has multiple lines, for fun')
552
f.write('this is my new commit\n')
805
555
runbzr('commit -F msg.tmp')
807
self.assertEquals(capture('revno'), '5\n')
557
assert capture('revno') == '5\n'
808
558
runbzr('export -r 5 export-5.tmp')
809
559
runbzr('export export.tmp')
813
563
runbzr('log -v --forward')
814
runbzr('log -m', retcode=3)
564
runbzr('log -m', retcode=1)
815
565
log_out = capture('log -m commit')
816
self.assert_("this is my new commit\n and" in log_out)
817
self.assert_("rename nested" not in log_out)
818
self.assert_('revision-id' not in log_out)
819
self.assert_('revision-id' in capture('log --show-ids -m commit'))
566
assert "this is my new commit" in log_out
567
assert "rename nested" not in log_out
568
assert 'revision-id' not in log_out
569
assert 'revision-id' in capture('log --show-ids -m commit')
821
log_out = capture('log --line')
822
# determine the widest line we want
823
max_width = terminal_width() - 1
824
for line in log_out.splitlines():
825
self.assert_(len(line) <= max_width, len(line))
826
self.assert_("this is my new commit and" not in log_out)
827
self.assert_("this is my new commit" in log_out)
829
572
progress("file with spaces in name")
830
573
mkdir('sub directory')
831
574
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
833
runbzr('diff', retcode=1)
834
577
runbzr('commit -m add-spaces')
847
590
os.symlink("NOWHERE1", "link1")
848
591
runbzr('add link1')
849
self.assertEquals(self.capture('unknowns'), '')
592
assert self.capture('unknowns') == ''
850
593
runbzr(['commit', '-m', '1: added symlink link1'])
854
self.assertEquals(self.capture('unknowns'), '')
597
assert self.capture('unknowns') == ''
855
598
os.symlink("NOWHERE2", "d1/link2")
856
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
599
assert self.capture('unknowns') == 'd1/link2\n'
857
600
# is d1/link2 found when adding d1
859
self.assertEquals(self.capture('unknowns'), '')
602
assert self.capture('unknowns') == ''
860
603
os.symlink("NOWHERE3", "d1/link3")
861
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
604
assert self.capture('unknowns') == 'd1/link3\n'
862
605
runbzr(['commit', '-m', '2: added dir, symlink'])
864
607
runbzr('rename d1 d2')
865
608
runbzr('move d2/link2 .')
866
609
runbzr('move link1 d2')
867
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
868
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
610
assert os.readlink("./link2") == "NOWHERE2"
611
assert os.readlink("d2/link1") == "NOWHERE1"
869
612
runbzr('add d2/link3')
870
runbzr('diff', retcode=1)
871
614
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
873
616
os.unlink("link2")
874
617
os.symlink("TARGET 2", "link2")
875
618
os.unlink("d2/link1")
876
619
os.symlink("TARGET 1", "d2/link1")
877
runbzr('diff', retcode=1)
878
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
621
assert self.capture("relpath d2/link1") == "d2/link1\n"
879
622
runbzr(['commit', '-m', '4: retarget of two links'])
881
624
runbzr('remove d2/link1')
882
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
625
assert self.capture('unknowns') == 'd2/link1\n'
883
626
runbzr(['commit', '-m', '5: remove d2/link1'])
884
# try with the rm alias
885
runbzr('add d2/link1')
886
runbzr(['commit', '-m', '6: add d2/link1'])
887
runbzr('rm d2/link1')
888
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
889
runbzr(['commit', '-m', '7: remove d2/link1'])
893
630
runbzr('rename d2/link3 d1/link3new')
894
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
895
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
631
assert self.capture('unknowns') == 'd2/link1\n'
632
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
897
634
runbzr(['check'])
899
636
runbzr(['export', '-r', '1', 'exp1.tmp'])
900
637
chdir("exp1.tmp")
901
self.assertEquals(listdir_sorted("."), [ "link1" ])
902
self.assertEquals(os.readlink("link1"), "NOWHERE1")
638
assert listdir_sorted(".") == [ "link1" ]
639
assert os.readlink("link1") == "NOWHERE1"
905
642
runbzr(['export', '-r', '2', 'exp2.tmp'])
906
643
chdir("exp2.tmp")
907
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
644
assert listdir_sorted(".") == [ "d1", "link1" ]
910
647
runbzr(['export', '-r', '3', 'exp3.tmp'])
911
648
chdir("exp3.tmp")
912
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
913
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
914
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
915
self.assertEquals(os.readlink("link2") , "NOWHERE2")
649
assert listdir_sorted(".") == [ "d2", "link2" ]
650
assert listdir_sorted("d2") == [ "link1", "link3" ]
651
assert os.readlink("d2/link1") == "NOWHERE1"
652
assert os.readlink("link2") == "NOWHERE2"
918
655
runbzr(['export', '-r', '4', 'exp4.tmp'])
919
656
chdir("exp4.tmp")
920
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
921
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
922
self.assertEquals(os.readlink("link2") , "TARGET 2")
923
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
657
assert listdir_sorted(".") == [ "d2", "link2" ]
658
assert os.readlink("d2/link1") == "TARGET 1"
659
assert os.readlink("link2") == "TARGET 2"
660
assert listdir_sorted("d2") == [ "link1", "link3" ]
926
663
runbzr(['export', '-r', '5', 'exp5.tmp'])
927
664
chdir("exp5.tmp")
928
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
929
self.assert_(os.path.islink("link2"))
930
self.assert_(listdir_sorted("d2")== [ "link3" ])
665
assert listdir_sorted(".") == [ "d2", "link2" ]
666
assert os.path.islink("link2")
667
assert listdir_sorted("d2")== [ "link3" ]
933
runbzr(['export', '-r', '8', 'exp6.tmp'])
670
runbzr(['export', '-r', '6', 'exp6.tmp'])
934
671
chdir("exp6.tmp")
935
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
936
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
937
self.assertEquals(listdir_sorted("d2"), [])
938
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
672
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
673
assert listdir_sorted("d1") == [ "link3new" ]
674
assert listdir_sorted("d2") == []
675
assert os.readlink("d1/link3new") == "NOWHERE3"
941
678
progress("skipping symlink tests")
944
class RemoteTests(object):
945
"""Test bzr ui commands against remote branches."""
947
def test_branch(self):
949
wt = self.make_branch_and_tree('from')
951
wt.commit('empty commit for nonsense', allow_pointless=True)
952
url = self.get_readonly_url('from')
953
self.run_bzr('branch', url, 'to')
954
branch = Branch.open('to')
955
self.assertEqual(1, len(branch.revision_history()))
956
# the branch should be set in to to from
957
self.assertEqual(url + '/', branch.get_parent())
960
self.build_tree(['branch/', 'branch/file'])
961
self.capture('init branch')
962
self.capture('add branch/file')
963
self.capture('commit -m foo branch')
964
url = self.get_readonly_url('branch/file')
965
output = self.capture('log %s' % url)
966
self.assertEqual(8, len(output.split('\n')))
968
def test_check(self):
969
self.build_tree(['branch/', 'branch/file'])
970
self.capture('init branch')
971
self.capture('add branch/file')
972
self.capture('commit -m foo branch')
973
url = self.get_readonly_url('branch/')
974
self.run_bzr('check', url)
977
# create a source branch
978
os.mkdir('my-branch')
979
os.chdir('my-branch')
981
file('hello', 'wt').write('foo')
982
self.run_bzr('add', 'hello')
983
self.run_bzr('commit', '-m', 'setup')
985
# with an explicit target work
986
self.run_bzr('push', self.get_url('output-branch'))
989
class HTTPTests(TestCaseWithWebserver, RemoteTests):
990
"""Test various commands against a HTTP server."""
993
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
994
"""Test various commands against a SFTP server using abs paths."""
997
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
998
"""Test various commands against a SFTP server using abs paths."""
1001
super(SFTPTestsAbsoluteSibling, self).setUp()
1002
self._override_home = '/dev/noone/runs/tests/here'
1005
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1006
"""Test various commands against a SFTP server using homedir rel paths."""
1009
super(SFTPTestsRelative, self).setUp()
1010
self._get_remote_is_absolute = False