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
47
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
48
48
from bzrlib.tests.blackbox import ExternalBase
49
from bzrlib.workingtree import WorkingTree
50
52
class TestCommands(ExternalBase):
345
345
zf = ZipFile('../first-zip')
346
346
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
349
self.example_branch()
350
file('hello', 'wt').write('hello world!')
351
self.runbzr('commit -m fixing hello')
352
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
353
self.assert_('\n+hello world!' in output)
354
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
355
self.assert_('\n+baz' in output)
356
file('moo', 'wb').write('moo')
357
self.runbzr('add moo')
361
def test_diff_branches(self):
362
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
363
branch = Branch.initialize('branch1')
364
branch.working_tree().add(['file'])
365
branch.working_tree().commit('add file')
366
copy_branch(branch, 'branch2')
367
print >> open('branch2/file', 'wb'), 'new content'
368
branch2 = Branch.open('branch2')
369
branch2.working_tree().commit('update file')
370
# should open branch1 and diff against branch2,
371
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
374
self.assertEquals(("=== modified file 'file'\n"
379
"+contents of branch1/file\n"
381
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
383
self.assertEqualDiff(("=== modified file 'file'\n"
388
"+contents of branch1/file\n"
392
348
def test_branch(self):
393
349
"""Branch from one branch to another."""
824
785
self.runbzr('commit -m done',)
825
786
self.runbzr('remerge', retcode=3)
788
def test_status(self):
792
self.runbzr('commit --unchanged --message f')
793
self.runbzr('branch . ../branch2')
794
self.runbzr('branch . ../branch3')
795
self.runbzr('commit --unchanged --message peter')
796
os.chdir('../branch2')
797
self.runbzr('merge ../branch1')
798
self.runbzr('commit --unchanged --message pumpkin')
799
os.chdir('../branch3')
800
self.runbzr('merge ../branch2')
801
message = self.capture('status')
828
804
def test_conflicts(self):
829
805
"""Handling of merge conflicts"""
858
834
"""Test re signing of data."""
859
835
import bzrlib.gpg
860
836
oldstrategy = bzrlib.gpg.GPGStrategy
861
branch = Branch.initialize('.')
862
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
837
wt = WorkingTree.create_standalone('.')
839
wt.commit("base", allow_pointless=True, rev_id='A')
864
841
# monkey patch gpg signing mechanism
865
842
from bzrlib.testament import Testament
866
843
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
867
844
self.runbzr('re-sign -r revid:A')
868
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
869
branch.revision_store.get('A', 'sig').read())
845
self.assertEqual(Testament.from_revision(branch.repository,
846
'A').as_short_text(),
847
branch.repository.revision_store.get('A',
871
850
bzrlib.gpg.GPGStrategy = oldstrategy
873
852
def test_resign_range(self):
874
853
import bzrlib.gpg
875
854
oldstrategy = bzrlib.gpg.GPGStrategy
876
branch = Branch.initialize('.')
877
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
878
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
879
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
855
wt = WorkingTree.create_standalone('.')
857
wt.commit("base", allow_pointless=True, rev_id='A')
858
wt.commit("base", allow_pointless=True, rev_id='B')
859
wt.commit("base", allow_pointless=True, rev_id='C')
881
861
# monkey patch gpg signing mechanism
882
862
from bzrlib.testament import Testament
883
863
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
884
864
self.runbzr('re-sign -r 1..')
885
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
886
branch.revision_store.get('A', 'sig').read())
887
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
888
branch.revision_store.get('B', 'sig').read())
889
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
890
branch.revision_store.get('C', 'sig').read())
866
Testament.from_revision(branch.repository,'A').as_short_text(),
867
branch.repository.revision_store.get('A', 'sig').read())
869
Testament.from_revision(branch.repository,'B').as_short_text(),
870
branch.repository.revision_store.get('B', 'sig').read())
871
self.assertEqual(Testament.from_revision(branch.repository,
872
'C').as_short_text(),
873
branch.repository.revision_store.get('C',
892
876
bzrlib.gpg.GPGStrategy = oldstrategy
1266
1250
progress("skipping symlink tests")
1269
class HttpTests(TestCaseWithWebserver):
1253
class RemoteTests(object):
1270
1254
"""Test bzr ui commands against remote branches."""
1272
1256
def test_branch(self):
1273
1257
os.mkdir('from')
1274
branch = Branch.initialize('from')
1275
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1258
wt = WorkingTree.create_standalone('from')
1260
wt.commit('empty commit for nonsense', allow_pointless=True)
1276
1261
url = self.get_remote_url('from')
1277
1262
self.run_bzr('branch', url, 'to')
1278
1263
branch = Branch.open('to')
1281
1266
def test_log(self):
1282
1267
self.build_tree(['branch/', 'branch/file'])
1283
branch = Branch.initialize('branch')
1284
branch.working_tree().add(['file'])
1285
branch.working_tree().commit('add file', rev_id='A')
1268
self.capture('init branch')
1269
self.capture('add branch/file')
1270
self.capture('commit -m foo branch')
1286
1271
url = self.get_remote_url('branch/file')
1287
1272
output = self.capture('log %s' % url)
1288
1273
self.assertEqual(8, len(output.split('\n')))
1290
1275
def test_check(self):
1291
1276
self.build_tree(['branch/', 'branch/file'])
1292
branch = Branch.initialize('branch')
1293
branch.working_tree().add(['file'])
1294
branch.working_tree().commit('add file', rev_id='A')
1277
self.capture('init branch')
1278
self.capture('add branch/file')
1279
self.capture('commit -m foo branch')
1295
1280
url = self.get_remote_url('branch/')
1296
1281
self.run_bzr('check', url)
1284
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1285
"""Test various commands against a HTTP server."""
1288
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1289
"""Test various commands against a SFTP server using abs paths."""
1292
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1293
"""Test various commands against a SFTP server using abs paths."""
1296
super(SFTPTestsAbsoluteSibling, self).setUp()
1297
self._override_home = '/dev/noone/runs/tests/here'
1300
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1301
"""Test various commands against a SFTP server using homedir rel paths."""
1304
super(SFTPTestsRelative, self).setUp()
1305
self._get_remote_is_absolute = False