43
43
from bzrlib.branch import Branch
44
import bzrlib.bzrdir as bzrdir
44
45
from bzrlib.errors import BzrCommandError
45
46
from bzrlib.osutils import has_symlinks, pathjoin
46
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
117
111
nick = self.runbzr("nick",backtick=True)
118
112
self.assertEqual(nick, 'moo\n')
121
114
def test_invalid_commands(self):
122
115
self.runbzr("pants", retcode=3)
123
116
self.runbzr("--pants off", retcode=3)
124
117
self.runbzr("diff --message foo", retcode=3)
126
def test_empty_commit(self):
128
self.build_tree(['hello.txt'])
129
self.runbzr("commit -m empty", retcode=3)
130
self.runbzr("add hello.txt")
131
self.runbzr("commit -m added")
133
def test_empty_commit_message(self):
135
file('foo.c', 'wt').write('int main() {}')
136
self.runbzr(['add', 'foo.c'])
137
self.runbzr(["commit", "-m", ""] , retcode=3)
139
119
def test_remove_deleted(self):
140
120
self.runbzr("init")
141
121
self.build_tree(['a'])
145
125
self.runbzr(['remove', 'a'])
147
def test_other_branch_commit(self):
148
# this branch is to ensure consistent behaviour, whether we're run
149
# inside a branch, or not.
150
os.mkdir('empty_branch')
151
os.chdir('empty_branch')
156
file('foo.c', 'wt').write('int main() {}')
157
file('bar.c', 'wt').write('int main() {}')
159
self.runbzr(['add', 'branch/foo.c'])
160
self.runbzr(['add', 'branch'])
161
# can't commit files in different trees; sane error
162
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
163
self.runbzr('commit -m newstuff branch/foo.c')
164
self.runbzr('commit -m newstuff branch')
165
self.runbzr('commit -m newstuff branch', retcode=3)
167
127
def test_ignore_patterns(self):
168
128
self.runbzr('init')
169
129
self.assertEquals(self.capture('unknowns'), '')
342
302
self.runbzr('commit -m foo --unchanged')
344
# naughty - abstraction violations RBC 20050928
345
print "test_branch used to delete the stores, how is this meant to work ?"
346
#shutil.rmtree('a/.bzr/revision-store')
347
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
348
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
349
self.runbzr('branch a d --basis b')
305
def test_branch_basis(self):
306
# ensure that basis really does grab from the basis by having incomplete source
307
tree = self.make_branch_and_tree('commit_tree')
308
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
310
tree.commit('revision 1', rev_id='1')
311
source = self.make_branch_and_tree('source')
312
# this gives us an incomplete repository
313
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
314
tree.commit('revision 2', rev_id='2', allow_pointless=True)
315
tree.bzrdir.open_branch().copy_content_into(source.branch)
316
tree.copy_content_into(source)
317
self.assertFalse(source.branch.repository.has_revision('2'))
319
self.runbzr('branch source target --basis commit_tree')
320
target = bzrdir.BzrDir.open('target')
321
self.assertEqual('2', target.open_branch().last_revision())
322
self.assertEqual('2', target.open_workingtree().last_revision())
323
self.assertTrue(target.open_branch().repository.has_revision('2'))
351
325
def test_merge(self):
352
326
from bzrlib.branch import Branch
376
350
self.runbzr('merge ../b -r last:1')
377
351
self.check_file_contents('goodbye', 'quux')
378
352
# Merging a branch pulls its revision into the tree
353
a = WorkingTree.open('.')
380
354
b = Branch.open('../b')
381
a.repository.get_revision_xml(b.last_revision())
382
self.log('pending merges: %s', a.working_tree().pending_merges())
383
self.assertEquals(a.working_tree().pending_merges(),
355
a.branch.repository.get_revision_xml(b.last_revision())
356
self.log('pending merges: %s', a.pending_merges())
357
self.assertEquals(a.pending_merges(),
384
358
[b.last_revision()])
385
359
self.runbzr('commit -m merged')
386
360
self.runbzr('merge ../b -r last:1')
387
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
361
self.assertEqual(a.pending_merges(), [])
389
363
def test_merge_with_missing_file(self):
390
364
"""Merge handles missing file conflicts"""
751
725
assert '|||||||' not in conflict_text
752
726
assert 'hi world' not in conflict_text
753
727
os.unlink('hello.OTHER')
728
os.unlink('question.OTHER')
729
self.runbzr('remerge jello --merge-type weave', retcode=3)
754
730
self.runbzr('remerge hello --merge-type weave', retcode=1)
755
731
assert os.path.exists('hello.OTHER')
732
self.assertIs(False, os.path.exists('question.OTHER'))
756
733
file_id = self.runbzr('file-id hello')
757
734
file_id = self.runbzr('file-id hello.THIS', retcode=3)
758
735
self.runbzr('remerge --merge-type weave', retcode=1)
814
791
self.runbzr('commit -m conflicts')
815
792
self.assertEquals(result, "")
817
def test_resign(self):
818
"""Test re signing of data."""
820
oldstrategy = bzrlib.gpg.GPGStrategy
821
wt = WorkingTree.create_standalone('.')
823
wt.commit("base", allow_pointless=True, rev_id='A')
825
# monkey patch gpg signing mechanism
826
from bzrlib.testament import Testament
827
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
828
self.runbzr('re-sign -r revid:A')
829
self.assertEqual(Testament.from_revision(branch.repository,
830
'A').as_short_text(),
831
branch.repository.revision_store.get('A',
834
bzrlib.gpg.GPGStrategy = oldstrategy
836
def test_resign_range(self):
838
oldstrategy = bzrlib.gpg.GPGStrategy
839
wt = WorkingTree.create_standalone('.')
841
wt.commit("base", allow_pointless=True, rev_id='A')
842
wt.commit("base", allow_pointless=True, rev_id='B')
843
wt.commit("base", allow_pointless=True, rev_id='C')
845
# monkey patch gpg signing mechanism
846
from bzrlib.testament import Testament
847
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
848
self.runbzr('re-sign -r 1..')
850
Testament.from_revision(branch.repository,'A').as_short_text(),
851
branch.repository.revision_store.get('A', 'sig').read())
853
Testament.from_revision(branch.repository,'B').as_short_text(),
854
branch.repository.revision_store.get('B', 'sig').read())
855
self.assertEqual(Testament.from_revision(branch.repository,
856
'C').as_short_text(),
857
branch.repository.revision_store.get('C',
860
bzrlib.gpg.GPGStrategy = oldstrategy
862
794
def test_push(self):
863
795
# create a source branch
864
796
os.mkdir('my-branch')
905
837
self.runbzr('missing ../missing/new-branch')
907
839
def test_external_command(self):
908
"""test that external commands can be run by setting the path"""
840
"""Test that external commands can be run by setting the path
842
# We don't at present run bzr in a subprocess for blackbox tests, and so
843
# don't really capture stdout, only the internal python stream.
844
# Therefore we don't use a subcommand that produces any output or does
845
# anything -- we just check that it can be run successfully.
909
846
cmd_name = 'test-command'
910
output = 'Hello from test-command'
911
847
if sys.platform == 'win32':
912
848
cmd_name += '.bat'
917
849
oldpath = os.environ.get('BZRPATH', None)
919
850
bzr = self.capture
922
852
if os.environ.has_key('BZRPATH'):
923
853
del os.environ['BZRPATH']
939
869
os.environ['BZRPATH'] = '.'
942
# The test suite does not capture stdout for external commands
943
# this is because you have to have a real file object
944
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
945
# (just replacing sys.stdout does not change a spawned objects stdout)
946
#self.assertEquals(bzr(cmd_name), output)
948
873
# Make sure empty path elements are ignored
949
874
os.environ['BZRPATH'] = os.pathsep
1240
1165
def test_branch(self):
1241
1166
os.mkdir('from')
1242
wt = WorkingTree.create_standalone('from')
1167
wt = self.make_branch_and_tree('from')
1243
1168
branch = wt.branch
1244
1169
wt.commit('empty commit for nonsense', allow_pointless=True)
1245
url = self.get_remote_url('from')
1170
url = self.get_readonly_url('from')
1246
1171
self.run_bzr('branch', url, 'to')
1247
1172
branch = Branch.open('to')
1248
1173
self.assertEqual(1, len(branch.revision_history()))
1174
# the branch should be set in to to from
1175
self.assertEqual(url + '/', branch.get_parent())
1250
1177
def test_log(self):
1251
1178
self.build_tree(['branch/', 'branch/file'])
1252
1179
self.capture('init branch')
1253
1180
self.capture('add branch/file')
1254
1181
self.capture('commit -m foo branch')
1255
url = self.get_remote_url('branch/file')
1182
url = self.get_readonly_url('branch/file')
1256
1183
output = self.capture('log %s' % url)
1257
1184
self.assertEqual(8, len(output.split('\n')))
1261
1188
self.capture('init branch')
1262
1189
self.capture('add branch/file')
1263
1190
self.capture('commit -m foo branch')
1264
url = self.get_remote_url('branch/')
1191
url = self.get_readonly_url('branch/')
1265
1192
self.run_bzr('check', url)
1194
def test_push(self):
1195
# create a source branch
1196
os.mkdir('my-branch')
1197
os.chdir('my-branch')
1198
self.run_bzr('init')
1199
file('hello', 'wt').write('foo')
1200
self.run_bzr('add', 'hello')
1201
self.run_bzr('commit', '-m', 'setup')
1203
# with an explicit target work
1204
self.run_bzr('push', self.get_url('output-branch'))
1268
1207
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1269
1208
"""Test various commands against a HTTP server."""