43
43
from bzrlib.branch import Branch
44
44
from bzrlib.clone import copy_branch
45
45
from bzrlib.errors import BzrCommandError
46
from bzrlib.osutils import has_symlinks
46
from bzrlib.osutils import has_symlinks, pathjoin
47
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
48
49
from bzrlib.tests.blackbox import ExternalBase
50
51
class TestCommands(ExternalBase):
215
216
os.rmdir('revertdir')
216
217
self.runbzr('revert')
218
os.symlink('/unlikely/to/exist', 'symlink')
219
self.runbzr('add symlink')
220
self.runbzr('commit -m f')
222
self.runbzr('revert')
223
self.failUnlessExists('symlink')
225
os.symlink('a-different-path', 'symlink')
226
self.runbzr('revert')
227
self.assertEqual('/unlikely/to/exist',
228
os.readlink('symlink'))
220
os.symlink('/unlikely/to/exist', 'symlink')
221
self.runbzr('add symlink')
222
self.runbzr('commit -m f')
224
self.runbzr('revert')
225
self.failUnlessExists('symlink')
227
os.symlink('a-different-path', 'symlink')
228
self.runbzr('revert')
229
self.assertEqual('/unlikely/to/exist',
230
os.readlink('symlink'))
232
self.log("skipping revert symlink tests")
230
234
file('hello', 'wt').write('xyz')
231
235
self.runbzr('commit -m xyz hello')
342
346
zf = ZipFile('../first-zip')
343
347
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
346
self.example_branch()
347
file('hello', 'wt').write('hello world!')
348
self.runbzr('commit -m fixing hello')
349
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
350
self.assert_('\n+hello world!' in output)
351
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
352
self.assert_('\n+baz' in output)
353
file('moo', 'wb').write('moo')
354
self.runbzr('add moo')
358
def test_diff_branches(self):
359
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
360
branch = Branch.initialize('branch1')
361
branch.working_tree().add(['file'])
362
branch.working_tree().commit('add file')
363
copy_branch(branch, 'branch2')
364
print >> open('branch2/file', 'wb'), 'new content'
365
branch2 = Branch.open('branch2')
366
branch2.working_tree().commit('update file')
367
# should open branch1 and diff against branch2,
368
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
371
self.assertEquals(("=== modified file 'file'\n"
376
"+contents of branch1/file\n"
378
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
380
self.assertEqualDiff(("=== modified file 'file'\n"
385
"+contents of branch1/file\n"
389
349
def test_branch(self):
390
350
"""Branch from one branch to another."""
674
634
self.assertEquals(['If you wish to add some of these files, please'\
675
635
' add them by name.',
677
'added dir'+os.sep+'sub.txt',
679
639
'ignored 1 file(s) matching "CVS"'],
728
688
self.build_tree(['inertiatic/', 'inertiatic/esp'])
729
689
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
730
690
self.run_bzr('add', '--no-recurse', 'inertiatic')
731
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
691
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
732
692
self.run_bzr('add', 'inertiatic/esp')
733
693
self.assertEquals(self.capture('unknowns'), '')
1009
969
self.assertEquals(capture('root').rstrip(),
1010
os.path.join(self.test_dir, 'branch1'))
970
pathjoin(self.test_dir, 'branch1'))
1012
972
progress("status of new file")
1083
1043
runbzr("rename sub1 sub2")
1084
1044
runbzr("move hello.txt sub2")
1085
1045
self.assertEqual(capture("relpath sub2/hello.txt"),
1086
os.path.join("sub2", "hello.txt\n"))
1046
pathjoin("sub2", "hello.txt\n"))
1088
1048
self.assert_(exists("sub2"))
1089
1049
self.assert_(exists("sub2/hello.txt"))
1106
1066
chdir('sub1/sub2')
1107
1067
self.assertEquals(capture('root')[:-1],
1108
os.path.join(self.test_dir, 'branch1'))
1068
pathjoin(self.test_dir, 'branch1'))
1109
1069
runbzr('move ../hello.txt .')
1110
1070
self.assert_(exists('./hello.txt'))
1111
1071
self.assertEquals(capture('relpath hello.txt'),
1112
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1113
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
1072
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
1073
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
1114
1074
runbzr(['commit', '-m', 'move to parent directory'])
1116
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
1076
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
1118
1078
runbzr('move sub2/hello.txt .')
1119
1079
self.assert_(exists('hello.txt'))
1291
1251
branch.working_tree().commit('add file', rev_id='A')
1292
1252
url = self.get_remote_url('branch/')
1293
1253
self.run_bzr('check', url)
1256
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1257
"""Test various commands against a HTTP server."""
1260
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1261
"""Test various commands against a SFTP server using abs paths."""
1264
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1265
"""Test various commands against a SFTP server using abs paths."""
1268
super(SFTPTestsAbsoluteSibling, self).setUp()
1269
self._override_home = '/dev/noone/runs/tests/here'
1272
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1273
"""Test various commands against a SFTP server using homedir rel paths."""
1276
super(SFTPTestsRelative, self).setUp()
1277
self._get_remote_is_absolute = False