43
43
from bzrlib.branch import Branch
44
from bzrlib.clone import copy_branch
45
44
from bzrlib.errors import BzrCommandError
46
45
from bzrlib.osutils import has_symlinks, pathjoin
47
46
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
47
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
49
48
from bzrlib.tests.blackbox import ExternalBase
51
51
class TestCommands(ExternalBase):
53
53
def test_help_commands(self):
346
346
zf = ZipFile('../first-zip')
347
347
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
350
self.example_branch()
351
file('hello', 'wt').write('hello world!')
352
self.runbzr('commit -m fixing hello')
353
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
354
self.assert_('\n+hello world!' in output)
355
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
356
self.assert_('\n+baz' in output)
357
file('moo', 'wb').write('moo')
358
self.runbzr('add moo')
362
def test_diff_branches(self):
363
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
364
branch = Branch.initialize('branch1')
365
branch.working_tree().add(['file'])
366
branch.working_tree().commit('add file')
367
copy_branch(branch, 'branch2')
368
print >> open('branch2/file', 'wb'), 'new content'
369
branch2 = Branch.open('branch2')
370
branch2.working_tree().commit('update file')
371
# should open branch1 and diff against branch2,
372
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
375
self.assertEquals(("=== modified file 'file'\n"
380
"+contents of branch1/file\n"
382
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
384
self.assertEqualDiff(("=== modified file 'file'\n"
389
"+contents of branch1/file\n"
393
349
def test_branch(self):
394
350
"""Branch from one branch to another."""
439
395
# Merging a branch pulls its revision into the tree
440
396
a = Branch.open('.')
441
397
b = Branch.open('../b')
442
a.get_revision_xml(b.last_revision())
398
a.repository.get_revision_xml(b.last_revision())
443
399
self.log('pending merges: %s', a.working_tree().pending_merges())
444
400
self.assertEquals(a.working_tree().pending_merges(),
445
401
[b.last_revision()])
559
file("myfile", "wb").write("My contents\n")
561
self.runbzr('commit -m myfile')
562
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
601
564
def test_pull_verbose(self):
602
565
"""Pull changes from one branch to another and watch the output."""
825
788
self.runbzr('commit -m done',)
826
789
self.runbzr('remerge', retcode=3)
791
def test_status(self):
795
self.runbzr('commit --unchanged --message f')
796
self.runbzr('branch . ../branch2')
797
self.runbzr('branch . ../branch3')
798
self.runbzr('commit --unchanged --message peter')
799
os.chdir('../branch2')
800
self.runbzr('merge ../branch1')
801
self.runbzr('commit --unchanged --message pumpkin')
802
os.chdir('../branch3')
803
self.runbzr('merge ../branch2')
804
message = self.capture('status')
829
807
def test_conflicts(self):
830
808
"""Handling of merge conflicts"""
866
844
from bzrlib.testament import Testament
867
845
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
868
846
self.runbzr('re-sign -r revid:A')
869
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
870
branch.revision_store.get('A', 'sig').read())
847
self.assertEqual(Testament.from_revision(branch.repository,
848
'A').as_short_text(),
849
branch.repository.revision_store.get('A',
872
852
bzrlib.gpg.GPGStrategy = oldstrategy
883
863
from bzrlib.testament import Testament
884
864
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
885
865
self.runbzr('re-sign -r 1..')
886
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
887
branch.revision_store.get('A', 'sig').read())
888
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
889
branch.revision_store.get('B', 'sig').read())
890
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
891
branch.revision_store.get('C', 'sig').read())
867
Testament.from_revision(branch.repository,'A').as_short_text(),
868
branch.repository.revision_store.get('A', 'sig').read())
870
Testament.from_revision(branch.repository,'B').as_short_text(),
871
branch.repository.revision_store.get('B', 'sig').read())
872
self.assertEqual(Testament.from_revision(branch.repository,
873
'C').as_short_text(),
874
branch.repository.revision_store.get('C',
893
877
bzrlib.gpg.GPGStrategy = oldstrategy
1287
1271
url = self.get_remote_url('branch/file')
1288
1272
output = self.capture('log %s' % url)
1289
1273
self.assertEqual(8, len(output.split('\n')))
1274
# FIXME: rbc 20051128 what is the remainder of this test testing?
1275
# - it does not seem to be http specific.
1276
copy = branch.clone('branch2')
1277
branch.working_tree().commit(message='empty commit')
1279
self.run_bzr('merge', '../branch')
1280
copy.working_tree().commit(message='merge')
1281
output = self.capture('log')
1291
1283
def test_check(self):
1292
1284
self.build_tree(['branch/', 'branch/file'])