279
267
self.example_branch()
281
269
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
270
self.runbzr('branch a c -r 1')
286
272
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')
274
# naughty - abstraction violations RBC 20050928
275
print "test_branch used to delete the stores, how is this meant to work ?"
276
#shutil.rmtree('a/.bzr/revision-store')
277
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
278
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
279
self.runbzr('branch a d --basis b')
281
def test_merge(self):
282
from bzrlib.branch import Branch
286
self.example_branch()
288
self.runbzr('branch a b')
290
file('goodbye', 'wt').write('quux')
291
self.runbzr(['commit', '-m', "more u's are always good"])
294
file('hello', 'wt').write('quuux')
295
# We can't merge when there are in-tree changes
296
self.runbzr('merge ../b', retcode=1)
297
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
298
self.runbzr('merge ../b')
299
self.check_file_contents('goodbye', 'quux')
300
# Merging a branch pulls its revision into the tree
302
b = Branch.open('../b')
303
a.get_revision_xml(b.last_revision())
304
self.log('pending merges: %s', a.pending_merges())
305
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
306
# % (a.pending_merges(), b.last_revision())
308
def test_merge_with_missing_file(self):
309
"""Merge handles missing file conflicts"""
313
print >> file('sub/a.txt', 'wb'), "hello"
314
print >> file('b.txt', 'wb'), "hello"
315
print >> file('sub/c.txt', 'wb'), "hello"
318
self.runbzr(('commit', '-m', 'added a'))
319
self.runbzr('branch . ../b')
320
print >> file('sub/a.txt', 'ab'), "there"
321
print >> file('b.txt', 'ab'), "there"
322
print >> file('sub/c.txt', 'ab'), "there"
323
self.runbzr(('commit', '-m', 'Added there'))
324
os.unlink('sub/a.txt')
325
os.unlink('sub/c.txt')
328
self.runbzr(('commit', '-m', 'Removed a.txt'))
330
print >> file('sub/a.txt', 'ab'), "something"
331
print >> file('b.txt', 'ab'), "something"
332
print >> file('sub/c.txt', 'ab'), "something"
333
self.runbzr(('commit', '-m', 'Modified a.txt'))
334
self.runbzr('merge ../a/')
335
assert os.path.exists('sub/a.txt.THIS')
336
assert os.path.exists('sub/a.txt.BASE')
338
self.runbzr('merge ../b/')
339
assert os.path.exists('sub/a.txt.OTHER')
340
assert os.path.exists('sub/a.txt.BASE')
343
"""Pull changes from one branch to another."""
347
self.example_branch()
348
self.runbzr('pull', retcode=1)
349
self.runbzr('missing', retcode=1)
350
self.runbzr('missing .')
351
self.runbzr('missing')
353
self.runbzr('pull /', retcode=1)
357
self.runbzr('branch a b')
355
360
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'])
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')
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)
475
def test_locations(self):
476
"""Using and remembering different locations"""
480
self.runbzr('commit -m unchanged --unchanged')
481
self.runbzr('pull', retcode=3)
482
self.runbzr('merge', retcode=3)
483
self.runbzr('branch . ../b')
486
self.runbzr('branch . ../c')
487
self.runbzr('pull ../c')
490
self.runbzr('pull ../b')
492
self.runbzr('pull ../c')
493
self.runbzr('branch ../c ../d')
494
shutil.rmtree('../c')
499
self.runbzr('pull', retcode=3)
500
self.runbzr('pull ../a --remember')
361
self.runbzr('add subdir')
362
self.runbzr('commit -m blah --unchanged')
365
b = Branch.open('../b')
366
assert a.revision_history() == b.revision_history()[:-1]
367
self.runbzr('pull ../b')
368
assert a.revision_history() == b.revision_history()
369
self.runbzr('commit -m blah2 --unchanged')
371
self.runbzr('commit -m blah3 --unchanged')
372
self.runbzr('pull ../a', retcode=1)
373
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
376
self.runbzr('merge ../b')
377
self.runbzr('commit -m blah4 --unchanged')
378
os.chdir('../b/subdir')
379
self.runbzr('pull ../../a')
380
assert a.revision_history()[-1] == b.revision_history()[-1]
381
self.runbzr('commit -m blah5 --unchanged')
382
self.runbzr('commit -m blah6 --unchanged')
384
self.runbzr('pull ../a')
386
self.runbzr('commit -m blah7 --unchanged')
387
self.runbzr('merge ../b')
388
self.runbzr('commit -m blah8 --unchanged')
389
self.runbzr('pull ../b')
390
self.runbzr('pull ../b')
503
392
def test_add_reports(self):
504
393
"""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]
508
# the ordering is not defined at the moment
509
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"'],
524
def test_add_quiet_is(self):
525
"""add -q does not print the names of added files."""
394
b = Branch.initialize('.')
527
395
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
528
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
396
out = self.run_bzr_captured(['add'], retcode = 0)[0]
529
397
# the ordering is not defined at the moment
530
398
results = sorted(out.rstrip('\n').split('\n'))
531
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')
399
self.assertEquals(['added dir',
400
'added dir'+os.sep+'sub.txt',
599
404
def test_unknown_command(self):
600
405
"""Handling of unknown command."""
601
406
out, err = self.run_bzr_captured(['fluffy-badger'],
603
408
self.assertEquals(out, '')
604
409
err.index('unknown command')
606
def create_conflicts(self):
607
"""Create a conflicted tree"""
610
file('hello', 'wb').write("hi world")
611
file('answer', 'wb').write("42")
614
self.runbzr('commit -m base')
615
self.runbzr('branch . ../other')
616
self.runbzr('branch . ../this')
618
file('hello', 'wb').write("Hello.")
619
file('answer', 'wb').write("Is anyone there?")
620
self.runbzr('commit -m other')
622
file('hello', 'wb').write("Hello, world")
623
self.runbzr('mv answer question')
624
file('question', 'wb').write("What do you get when you multiply six"
626
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)
693
result = self.runbzr('conflicts', backtick=1)
694
self.assertEquals(result, "Text conflict in hello\nText conflict in"
696
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)
699
self.runbzr('resolve hello')
700
result = self.runbzr('conflicts', backtick=1)
701
self.assertEquals(result, "Text conflict in question\n")
702
self.runbzr('commit -m conflicts', retcode=3)
703
self.runbzr('resolve --all')
704
result = self.runbzr('conflicts', backtick=1)
705
self.runbzr('commit -m conflicts')
706
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
412
def listdir_sorted(dir):
798
413
L = os.listdir(dir)
828
443
self.assertEquals(capture('unknowns'), 'test.txt\n')
830
445
out = capture("status")
831
self.assertEquals(out, 'unknown:\n test.txt\n')
446
assert out == 'unknown:\n test.txt\n'
833
448
out = capture("status --all")
834
self.assertEquals(out, "unknown:\n test.txt\n")
449
assert out == "unknown:\n test.txt\n"
836
451
out = capture("status test.txt --all")
837
self.assertEquals(out, "unknown:\n test.txt\n")
452
assert out == "unknown:\n test.txt\n"
839
454
f = file('test2.txt', 'wt')
840
455
f.write('goodbye cruel world...\n')
843
458
out = capture("status test.txt")
844
self.assertEquals(out, "unknown:\n test.txt\n")
459
assert out == "unknown:\n test.txt\n"
846
461
out = capture("status")
847
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
462
assert out == ("unknown:\n"
849
466
os.unlink('test2.txt')
851
468
progress("command aliases")
852
469
out = capture("st --all")
853
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
470
assert out == ("unknown:\n"
855
473
out = capture("stat")
856
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
474
assert out == ("unknown:\n"
858
477
progress("command help")
859
478
runbzr("help st")
861
480
runbzr("help commands")
862
runbzr("help slartibartfast", 3)
481
runbzr("help slartibartfast", 1)
864
483
out = capture("help ci")
865
484
out.index('aliases: ')
867
486
progress("can't rename unversioned file")
868
runbzr("rename test.txt new-test.txt", 3)
487
runbzr("rename test.txt new-test.txt", 1)
870
489
progress("adding a file")
872
491
runbzr("add test.txt")
873
self.assertEquals(capture("unknowns"), '')
874
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
492
assert capture("unknowns") == ''
493
assert capture("status --all") == ("added:\n"
876
496
progress("rename newly-added file")
877
497
runbzr("rename test.txt hello.txt")
878
self.assert_(os.path.exists("hello.txt"))
879
self.assert_(not os.path.exists("test.txt"))
498
assert os.path.exists("hello.txt")
499
assert not os.path.exists("test.txt")
881
self.assertEquals(capture("revno"), '0\n')
501
assert capture("revno") == '0\n'
883
503
progress("add first revision")
884
504
runbzr(['commit', '-m', 'add first revision'])
886
506
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)
508
runbzr("rename hello.txt sub1", 1)
509
runbzr("rename hello.txt sub1/hello.txt", 1)
510
runbzr("move hello.txt sub1", 1)
892
512
runbzr("add sub1")
893
513
runbzr("rename sub1 sub2")
894
514
runbzr("move hello.txt sub2")
895
self.assertEqual(capture("relpath sub2/hello.txt"),
896
pathjoin("sub2", "hello.txt\n"))
515
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"))
517
assert exists("sub2")
518
assert exists("sub2/hello.txt")
519
assert not exists("sub1")
520
assert not exists("hello.txt")
903
522
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
906
525
runbzr('add sub1')
907
526
runbzr('move sub2/hello.txt sub1')
908
self.assert_(not exists('sub2/hello.txt'))
909
self.assert_(exists('sub1/hello.txt'))
527
assert not exists('sub2/hello.txt')
528
assert exists('sub1/hello.txt')
910
529
runbzr('move sub2 sub1')
911
self.assert_(not exists('sub2'))
912
self.assert_(exists('sub1/sub2'))
530
assert not exists('sub2')
531
assert exists('sub1/sub2')
914
533
runbzr(['commit', '-m', 'rename nested subdirectories'])
916
535
chdir('sub1/sub2')
917
536
self.assertEquals(capture('root')[:-1],
918
pathjoin(self.test_dir, 'branch1'))
537
os.path.join(self.test_dir, 'branch1'))
919
538
runbzr('move ../hello.txt .')
920
self.assert_(exists('./hello.txt'))
539
assert exists('./hello.txt')
921
540
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'))
541
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
542
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
924
543
runbzr(['commit', '-m', 'move to parent directory'])
926
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
545
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
928
547
runbzr('move sub2/hello.txt .')
929
self.assert_(exists('hello.txt'))
548
assert exists('hello.txt')
931
550
f = file('hello.txt', 'wt')
932
551
f.write('some nice new content\n')
935
554
f = file('msg.tmp', 'wt')
936
f.write('this is my new commit\nand it has multiple lines, for fun')
555
f.write('this is my new commit\n')
939
558
runbzr('commit -F msg.tmp')
941
self.assertEquals(capture('revno'), '5\n')
560
assert capture('revno') == '5\n'
942
561
runbzr('export -r 5 export-5.tmp')
943
562
runbzr('export export.tmp')
947
566
runbzr('log -v --forward')
948
runbzr('log -m', retcode=3)
567
runbzr('log -m', retcode=1)
949
568
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)
569
assert "this is my new commit" in log_out
570
assert "rename nested" not in log_out
571
assert 'revision-id' not in log_out
572
assert 'revision-id' in capture('log --show-ids -m commit')
961
575
progress("file with spaces in name")
962
576
mkdir('sub directory')
963
577
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
965
runbzr('diff', retcode=1)
966
580
runbzr('commit -m add-spaces')
979
593
os.symlink("NOWHERE1", "link1")
980
594
runbzr('add link1')
981
self.assertEquals(self.capture('unknowns'), '')
595
assert self.capture('unknowns') == ''
982
596
runbzr(['commit', '-m', '1: added symlink link1'])
986
self.assertEquals(self.capture('unknowns'), '')
600
assert self.capture('unknowns') == ''
987
601
os.symlink("NOWHERE2", "d1/link2")
988
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
602
assert self.capture('unknowns') == 'd1/link2\n'
989
603
# is d1/link2 found when adding d1
991
self.assertEquals(self.capture('unknowns'), '')
605
assert self.capture('unknowns') == ''
992
606
os.symlink("NOWHERE3", "d1/link3")
993
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
607
assert self.capture('unknowns') == 'd1/link3\n'
994
608
runbzr(['commit', '-m', '2: added dir, symlink'])
996
610
runbzr('rename d1 d2')
997
611
runbzr('move d2/link2 .')
998
612
runbzr('move link1 d2')
999
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1000
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
613
assert os.readlink("./link2") == "NOWHERE2"
614
assert os.readlink("d2/link1") == "NOWHERE1"
1001
615
runbzr('add d2/link3')
1002
runbzr('diff', retcode=1)
1003
617
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1005
619
os.unlink("link2")
1006
620
os.symlink("TARGET 2", "link2")
1007
621
os.unlink("d2/link1")
1008
622
os.symlink("TARGET 1", "d2/link1")
1009
runbzr('diff', retcode=1)
1010
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
624
assert self.capture("relpath d2/link1") == "d2/link1\n"
1011
625
runbzr(['commit', '-m', '4: retarget of two links'])
1013
627
runbzr('remove d2/link1')
1014
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
628
assert self.capture('unknowns') == 'd2/link1\n'
1015
629
runbzr(['commit', '-m', '5: remove d2/link1'])
1016
# try with the rm alias
1017
runbzr('add d2/link1')
1018
runbzr(['commit', '-m', '6: add d2/link1'])
1019
runbzr('rm d2/link1')
1020
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1021
runbzr(['commit', '-m', '7: remove d2/link1'])
1024
632
runbzr('add d1')
1025
633
runbzr('rename d2/link3 d1/link3new')
1026
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1027
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
634
assert self.capture('unknowns') == 'd2/link1\n'
635
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
1029
637
runbzr(['check'])
1031
639
runbzr(['export', '-r', '1', 'exp1.tmp'])
1032
640
chdir("exp1.tmp")
1033
self.assertEquals(listdir_sorted("."), [ "link1" ])
1034
self.assertEquals(os.readlink("link1"), "NOWHERE1")
641
assert listdir_sorted(".") == [ "link1" ]
642
assert os.readlink("link1") == "NOWHERE1"
1037
645
runbzr(['export', '-r', '2', 'exp2.tmp'])
1038
646
chdir("exp2.tmp")
1039
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
647
assert listdir_sorted(".") == [ "d1", "link1" ]
1042
650
runbzr(['export', '-r', '3', 'exp3.tmp'])
1043
651
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")
652
assert listdir_sorted(".") == [ "d2", "link2" ]
653
assert listdir_sorted("d2") == [ "link1", "link3" ]
654
assert os.readlink("d2/link1") == "NOWHERE1"
655
assert os.readlink("link2") == "NOWHERE2"
1050
658
runbzr(['export', '-r', '4', 'exp4.tmp'])
1051
659
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" ])
660
assert listdir_sorted(".") == [ "d2", "link2" ]
661
assert os.readlink("d2/link1") == "TARGET 1"
662
assert os.readlink("link2") == "TARGET 2"
663
assert listdir_sorted("d2") == [ "link1", "link3" ]
1058
666
runbzr(['export', '-r', '5', 'exp5.tmp'])
1059
667
chdir("exp5.tmp")
1060
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1061
self.assert_(os.path.islink("link2"))
1062
self.assert_(listdir_sorted("d2")== [ "link3" ])
668
assert listdir_sorted(".") == [ "d2", "link2" ]
669
assert os.path.islink("link2")
670
assert listdir_sorted("d2")== [ "link3" ]
1065
runbzr(['export', '-r', '8', 'exp6.tmp'])
673
runbzr(['export', '-r', '6', 'exp6.tmp'])
1066
674
chdir("exp6.tmp")
1067
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")
675
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
676
assert listdir_sorted("d1") == [ "link3new" ]
677
assert listdir_sorted("d2") == []
678
assert os.readlink("d1/link3new") == "NOWHERE3"
1073
681
progress("skipping symlink tests")
1076
class RemoteTests(object):
1077
"""Test bzr ui commands against remote branches."""
1079
def test_branch(self):
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')
1085
self.run_bzr('branch', url, 'to')
1086
branch = Branch.open('to')
1087
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