53
54
class TestCommands(ExternalBase):
55
def test_help_commands(self):
58
self.runbzr('help commands')
59
self.runbzr('help help')
60
self.runbzr('commit -h')
62
def test_init_branch(self):
65
# Can it handle subdirectories as well?
66
self.runbzr('init subdir1')
67
self.assert_(os.path.exists('subdir1'))
68
self.assert_(os.path.exists('subdir1/.bzr'))
70
self.runbzr('init subdir2/nothere', retcode=3)
73
self.runbzr('init subdir2')
74
self.runbzr('init subdir2', retcode=3)
76
self.runbzr('init subdir2/subsubdir1')
77
self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
79
56
def test_whoami(self):
80
57
# this should always identify something, if only "john@localhost"
81
58
self.runbzr("whoami")
329
306
self.assertEqual('2', target.open_workingtree().last_revision())
330
307
self.assertTrue(target.open_branch().repository.has_revision('2'))
332
def test_merge(self):
333
from bzrlib.branch import Branch
337
self.example_branch()
339
self.runbzr('branch a b')
341
file('goodbye', 'wt').write('quux')
342
self.runbzr(['commit', '-m', "more u's are always good"])
345
file('hello', 'wt').write('quuux')
346
# We can't merge when there are in-tree changes
347
self.runbzr('merge ../b', retcode=3)
348
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
349
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
351
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
352
self.runbzr('revert --no-backup')
353
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
354
self.runbzr('revert --no-backup')
355
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
356
self.runbzr('revert --no-backup')
357
self.runbzr('merge ../b -r last:1')
358
self.check_file_contents('goodbye', 'quux')
359
# Merging a branch pulls its revision into the tree
360
a = WorkingTree.open('.')
361
b = Branch.open('../b')
362
a.branch.repository.get_revision_xml(b.last_revision())
363
self.log('pending merges: %s', a.pending_merges())
364
self.assertEquals(a.pending_merges(),
366
self.runbzr('commit -m merged')
367
self.runbzr('merge ../b -r last:1')
368
self.assertEqual(a.pending_merges(), [])
370
def test_merge_with_missing_file(self):
371
"""Merge handles missing file conflicts"""
375
print >> file('sub/a.txt', 'wb'), "hello"
376
print >> file('b.txt', 'wb'), "hello"
377
print >> file('sub/c.txt', 'wb'), "hello"
380
self.runbzr(('commit', '-m', 'added a'))
381
self.runbzr('branch . ../b')
382
print >> file('sub/a.txt', 'ab'), "there"
383
print >> file('b.txt', 'ab'), "there"
384
print >> file('sub/c.txt', 'ab'), "there"
385
self.runbzr(('commit', '-m', 'Added there'))
386
os.unlink('sub/a.txt')
387
os.unlink('sub/c.txt')
390
self.runbzr(('commit', '-m', 'Removed a.txt'))
392
print >> file('sub/a.txt', 'ab'), "something"
393
print >> file('b.txt', 'ab'), "something"
394
print >> file('sub/c.txt', 'ab'), "something"
395
self.runbzr(('commit', '-m', 'Modified a.txt'))
396
self.runbzr('merge ../a/', retcode=1)
397
self.assert_(os.path.exists('sub/a.txt.THIS'))
398
self.assert_(os.path.exists('sub/a.txt.BASE'))
400
self.runbzr('merge ../b/', retcode=1)
401
self.assert_(os.path.exists('sub/a.txt.OTHER'))
402
self.assert_(os.path.exists('sub/a.txt.BASE'))
404
309
def test_inventory(self):
405
310
bzr = self.runbzr
406
311
def output_equals(value, *args):
732
637
assert '|||||||' not in conflict_text
733
638
assert 'hi world' not in conflict_text
734
639
os.unlink('hello.OTHER')
640
os.unlink('question.OTHER')
641
self.runbzr('remerge jello --merge-type weave', retcode=3)
735
642
self.runbzr('remerge hello --merge-type weave', retcode=1)
736
643
assert os.path.exists('hello.OTHER')
644
self.assertIs(False, os.path.exists('question.OTHER'))
737
645
file_id = self.runbzr('file-id hello')
738
646
file_id = self.runbzr('file-id hello.THIS', retcode=3)
739
647
self.runbzr('remerge --merge-type weave', retcode=1)
742
650
assert '|||||||' not in conflict_text
743
651
assert 'hi world' not in conflict_text
744
652
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
745
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
746
653
self.runbzr('remerge . --show-base --reprocess', retcode=3)
654
self.runbzr('remerge . --merge-type weave --reprocess', retcode=1)
747
655
self.runbzr('remerge hello --show-base', retcode=1)
748
656
self.runbzr('remerge hello --reprocess', retcode=1)
749
657
self.runbzr('resolve --all')
783
691
self.assert_('|||||||' not in conflict_text)
784
692
self.assert_('hi world' not in conflict_text)
785
693
result = self.runbzr('conflicts', backtick=1)
786
self.assertEquals(result, "hello\nquestion\n")
694
self.assertEquals(result, "Text conflict in hello\nText conflict in"
787
696
result = self.runbzr('status', backtick=1)
788
self.assert_("conflicts:\n hello\n question\n" in result, result)
697
self.assert_("conflicts:\n Text conflict in hello\n"
698
" Text conflict in question\n" in result, result)
789
699
self.runbzr('resolve hello')
790
700
result = self.runbzr('conflicts', backtick=1)
791
self.assertEquals(result, "question\n")
701
self.assertEquals(result, "Text conflict in question\n")
792
702
self.runbzr('commit -m conflicts', retcode=3)
793
703
self.runbzr('resolve --all')
794
704
result = self.runbzr('conflicts', backtick=1)
795
705
self.runbzr('commit -m conflicts')
796
706
self.assertEquals(result, "")
798
def test_resign(self):
799
"""Test re signing of data."""
801
oldstrategy = bzrlib.gpg.GPGStrategy
802
wt = self.make_branch_and_tree('.')
804
wt.commit("base", allow_pointless=True, rev_id='A')
806
# monkey patch gpg signing mechanism
807
from bzrlib.testament import Testament
808
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
809
self.runbzr('re-sign -r revid:A')
810
self.assertEqual(Testament.from_revision(branch.repository,
811
'A').as_short_text(),
812
branch.repository.revision_store.get('A',
815
bzrlib.gpg.GPGStrategy = oldstrategy
817
def test_resign_range(self):
819
oldstrategy = bzrlib.gpg.GPGStrategy
820
wt = self.make_branch_and_tree('.')
822
wt.commit("base", allow_pointless=True, rev_id='A')
823
wt.commit("base", allow_pointless=True, rev_id='B')
824
wt.commit("base", allow_pointless=True, rev_id='C')
826
# monkey patch gpg signing mechanism
827
from bzrlib.testament import Testament
828
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
829
self.runbzr('re-sign -r 1..')
831
Testament.from_revision(branch.repository,'A').as_short_text(),
832
branch.repository.revision_store.get('A', 'sig').read())
834
Testament.from_revision(branch.repository,'B').as_short_text(),
835
branch.repository.revision_store.get('B', 'sig').read())
836
self.assertEqual(Testament.from_revision(branch.repository,
837
'C').as_short_text(),
838
branch.repository.revision_store.get('C',
841
bzrlib.gpg.GPGStrategy = oldstrategy
843
708
def test_push(self):
844
709
# create a source branch
845
710
os.mkdir('my-branch')
886
751
self.runbzr('missing ../missing/new-branch')
888
753
def test_external_command(self):
889
"""test that external commands can be run by setting the path"""
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.
890
760
cmd_name = 'test-command'
891
output = 'Hello from test-command'
892
761
if sys.platform == 'win32':
893
762
cmd_name += '.bat'
898
763
oldpath = os.environ.get('BZRPATH', None)
900
764
bzr = self.capture
903
766
if os.environ.has_key('BZRPATH'):
904
767
del os.environ['BZRPATH']
1247
1105
url = self.get_readonly_url('branch/')
1248
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'))
1251
1121
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1252
1122
"""Test various commands against a HTTP server."""