105
92
def test_ignore_patterns(self):
106
93
from bzrlib.branch import Branch
108
b = Branch.initialize('.')
95
b = Branch('.', init=True)
109
96
self.assertEquals(list(b.unknowns()), [])
111
98
file('foo.tmp', 'wt').write('tmp files are ignored')
112
99
self.assertEquals(list(b.unknowns()), [])
113
assert self.capture('unknowns') == ''
100
assert self.backtick('bzr unknowns') == ''
115
102
file('foo.c', 'wt').write('int main() {}')
116
103
self.assertEquals(list(b.unknowns()), ['foo.c'])
117
assert self.capture('unknowns') == 'foo.c\n'
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
119
106
self.runbzr(['add', 'foo.c'])
120
assert self.capture('unknowns') == ''
107
assert self.backtick('bzr unknowns') == ''
122
109
# 'ignore' works when creating the .bzignore file
123
110
file('foo.blah', 'wt').write('blah')
124
111
self.assertEquals(list(b.unknowns()), ['foo.blah'])
125
112
self.runbzr('ignore *.blah')
126
113
self.assertEquals(list(b.unknowns()), [])
127
assert file('.bzrignore', 'rU').read() == '*.blah\n'
114
assert file('.bzrignore', 'rb').read() == '*.blah\n'
129
116
# 'ignore' works when then .bzrignore file already exists
130
117
file('garh', 'wt').write('garh')
131
118
self.assertEquals(list(b.unknowns()), ['garh'])
132
assert self.capture('unknowns') == 'garh\n'
119
assert self.backtick('bzr unknowns') == 'garh\n'
133
120
self.runbzr('ignore garh')
134
121
self.assertEquals(list(b.unknowns()), [])
135
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
122
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
137
124
def test_revert(self):
138
126
self.runbzr('init')
140
128
file('hello', 'wt').write('foo')
159
147
os.rmdir('revertdir')
160
148
self.runbzr('revert')
162
os.symlink('/unlikely/to/exist', 'symlink')
163
self.runbzr('add symlink')
164
self.runbzr('commit -m f')
166
self.runbzr('revert')
168
file('hello', 'wt').write('xyz')
169
self.runbzr('commit -m xyz hello')
170
self.runbzr('revert -r 1 hello')
171
self.check_file_contents('hello', 'foo')
172
self.runbzr('revert hello')
173
self.check_file_contents('hello', 'xyz')
174
os.chdir('revertdir')
175
self.runbzr('revert')
179
def test_mv_modes(self):
150
def skipped_test_mv_modes(self):
180
151
"""Test two modes of operation for mv"""
181
152
from bzrlib.branch import Branch
182
b = Branch.initialize('.')
153
b = Branch('.', init=True)
183
154
self.build_tree(['a', 'c', 'subdir/'])
184
self.run_bzr_captured(['add', self.test_dir])
185
self.run_bzr_captured(['mv', 'a', 'b'])
186
self.run_bzr_captured(['mv', 'b', 'subdir'])
187
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
188
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
189
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
155
self.run_bzr('mv', 'a', 'b')
156
self.run_bzr('mv', 'b', 'subdir')
157
self.run_bzr('mv', 'subdir/b', 'a')
158
self.run_bzr('mv', 'a', 'b', 'subdir')
159
self.run_bzr('mv', 'subdir/a', 'subdir/newa')
191
161
def test_main_version(self):
192
162
"""Check output from version command and master option is reasonable"""
212
182
test.runbzr('add goodbye')
213
183
test.runbzr('commit -m setup goodbye')
215
def test_export(self):
218
self.example_branch()
219
self.runbzr('export ../latest')
220
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
221
self.runbzr('export ../first -r 1')
222
assert not os.path.exists('../first/goodbye')
223
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
224
self.runbzr('export ../first.gz -r 1')
225
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
226
self.runbzr('export ../first.bz2 -r 1')
227
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
228
self.runbzr('export ../first.tar -r 1')
229
assert os.path.isfile('../first.tar')
230
from tarfile import TarFile
231
tf = TarFile('../first.tar')
232
assert 'first/hello' in tf.getnames(), tf.getnames()
233
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
234
self.runbzr('export ../first.tar.gz -r 1')
235
assert os.path.isfile('../first.tar.gz')
236
self.runbzr('export ../first.tbz2 -r 1')
237
assert os.path.isfile('../first.tbz2')
238
self.runbzr('export ../first.tar.bz2 -r 1')
239
assert os.path.isfile('../first.tar.bz2')
240
self.runbzr('export ../first.tar.tbz2 -r 1')
241
assert os.path.isfile('../first.tar.tbz2')
242
from bz2 import BZ2File
243
tf = TarFile('../first.tar.tbz2',
244
fileobj=BZ2File('../first.tar.tbz2', 'r'))
245
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
246
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
247
self.runbzr('export ../first2.tar -r 1 --root pizza')
248
tf = TarFile('../first2.tar')
249
assert 'pizza/hello' in tf.getnames(), tf.getnames()
252
self.example_branch()
253
file('hello', 'wt').write('hello world!')
254
self.runbzr('commit -m fixing hello')
255
output = self.runbzr('diff -r 2..3', backtick=1)
256
self.assert_('\n+hello world!' in output)
257
output = self.runbzr('diff -r last:3..last:1', backtick=1)
258
self.assert_('\n+baz' in output)
260
def test_branch(self):
261
"""Branch from one branch to another."""
264
self.example_branch()
266
self.runbzr('branch a b')
267
self.runbzr('branch a c -r 1')
269
self.runbzr('commit -m foo --unchanged')
271
# naughty - abstraction violations RBC 20050928
272
print "test_branch used to delete the stores, how is this meant to work ?"
273
#shutil.rmtree('a/.bzr/revision-store')
274
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
275
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
276
self.runbzr('branch a d --basis b')
185
def test_revert(self):
186
self.example_branch()
187
file('hello', 'wt').write('bar')
188
file('goodbye', 'wt').write('qux')
189
self.runbzr('revert hello')
190
self.check_file_contents('hello', 'foo')
191
self.check_file_contents('goodbye', 'qux')
192
self.runbzr('revert')
193
self.check_file_contents('goodbye', 'baz')
278
195
def test_merge(self):
279
196
from bzrlib.branch import Branch
283
202
self.example_branch()
285
204
self.runbzr('branch a b')
295
214
self.runbzr('merge ../b')
296
215
self.check_file_contents('goodbye', 'quux')
297
216
# Merging a branch pulls its revision into the tree
299
b = Branch.open('../b')
300
a.get_revision_xml(b.last_revision())
219
a.get_revision_xml(b.last_patch())
301
221
self.log('pending merges: %s', a.pending_merges())
302
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
222
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
303
223
# % (a.pending_merges(), b.last_patch())
305
def test_merge_with_missing_file(self):
306
"""Merge handles missing file conflicts"""
310
print >> file('sub/a.txt', 'wb'), "hello"
311
print >> file('b.txt', 'wb'), "hello"
312
print >> file('sub/c.txt', 'wb'), "hello"
315
self.runbzr(('commit', '-m', 'added a'))
316
self.runbzr('branch . ../b')
317
print >> file('sub/a.txt', 'ab'), "there"
318
print >> file('b.txt', 'ab'), "there"
319
print >> file('sub/c.txt', 'ab'), "there"
320
self.runbzr(('commit', '-m', 'Added there'))
321
os.unlink('sub/a.txt')
322
os.unlink('sub/c.txt')
325
self.runbzr(('commit', '-m', 'Removed a.txt'))
327
print >> file('sub/a.txt', 'ab'), "something"
328
print >> file('b.txt', 'ab'), "something"
329
print >> file('sub/c.txt', 'ab'), "something"
330
self.runbzr(('commit', '-m', 'Modified a.txt'))
331
self.runbzr('merge ../a/')
332
assert os.path.exists('sub/a.txt.THIS')
333
assert os.path.exists('sub/a.txt.BASE')
335
self.runbzr('merge ../b/')
336
assert os.path.exists('sub/a.txt.OTHER')
337
assert os.path.exists('sub/a.txt.BASE')
339
def test_merge_with_missing_file(self):
340
"""Merge handles missing file conflicts"""
344
print >> file('sub/a.txt', 'wb'), "hello"
345
print >> file('b.txt', 'wb'), "hello"
346
print >> file('sub/c.txt', 'wb'), "hello"
349
self.runbzr(('commit', '-m', 'added a'))
350
self.runbzr('branch . ../b')
351
print >> file('sub/a.txt', 'ab'), "there"
352
print >> file('b.txt', 'ab'), "there"
353
print >> file('sub/c.txt', 'ab'), "there"
354
self.runbzr(('commit', '-m', 'Added there'))
355
os.unlink('sub/a.txt')
356
os.unlink('sub/c.txt')
359
self.runbzr(('commit', '-m', 'Removed a.txt'))
361
print >> file('sub/a.txt', 'ab'), "something"
362
print >> file('b.txt', 'ab'), "something"
363
print >> file('sub/c.txt', 'ab'), "something"
364
self.runbzr(('commit', '-m', 'Modified a.txt'))
365
self.runbzr('merge ../a/')
366
assert os.path.exists('sub/a.txt.THIS')
367
assert os.path.exists('sub/a.txt.BASE')
369
self.runbzr('merge ../b/')
370
assert os.path.exists('sub/a.txt.OTHER')
371
assert os.path.exists('sub/a.txt.BASE')
374
"""Pull changes from one branch to another."""
378
self.example_branch()
379
self.runbzr('pull', retcode=1)
380
self.runbzr('missing', retcode=1)
381
self.runbzr('missing .')
382
self.runbzr('missing')
384
self.runbzr('pull /', retcode=1)
388
self.runbzr('branch a b')
392
self.runbzr('add subdir')
393
self.runbzr('commit -m blah --unchanged')
396
b = Branch.open('../b')
397
assert a.revision_history() == b.revision_history()[:-1]
398
self.runbzr('pull ../b')
399
assert a.revision_history() == b.revision_history()
400
self.runbzr('commit -m blah2 --unchanged')
402
self.runbzr('commit -m blah3 --unchanged')
403
self.runbzr('pull ../a', retcode=1)
404
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
407
self.runbzr('merge ../b')
408
self.runbzr('commit -m blah4 --unchanged')
409
os.chdir('../b/subdir')
410
self.runbzr('pull ../../a')
411
assert a.revision_history()[-1] == b.revision_history()[-1]
412
self.runbzr('commit -m blah5 --unchanged')
413
self.runbzr('commit -m blah6 --unchanged')
415
self.runbzr('pull ../a')
417
self.runbzr('commit -m blah7 --unchanged')
418
self.runbzr('merge ../b')
419
self.runbzr('commit -m blah8 --unchanged')
420
self.runbzr('pull ../b')
421
self.runbzr('pull ../b')
423
def test_locations(self):
424
"""Using and remembering different locations"""
428
self.runbzr('commit -m unchanged --unchanged')
429
self.runbzr('pull', retcode=1)
430
self.runbzr('merge', retcode=1)
431
self.runbzr('branch . ../b')
434
self.runbzr('branch . ../c')
435
self.runbzr('pull ../c')
438
self.runbzr('pull ../b')
440
self.runbzr('pull ../c')
441
self.runbzr('branch ../c ../d')
442
shutil.rmtree('../c')
447
self.runbzr('pull', retcode=1)
448
self.runbzr('pull ../a --remember')
451
226
def test_add_reports(self):
452
227
"""add command prints the names of added files."""
453
b = Branch.initialize('.')
228
b = Branch('.', init=True)
454
229
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
455
out = self.run_bzr_captured(['add'], retcode = 0)[0]
231
from cStringIO import StringIO
234
ret = self.apply_redirected(None, out, None,
237
self.assertEquals(ret, 0)
456
239
# the ordering is not defined at the moment
457
results = sorted(out.rstrip('\n').split('\n'))
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
458
241
self.assertEquals(['added dir',
459
'added dir'+os.sep+'sub.txt',
460
243
'added top.txt',],
463
def test_unknown_command(self):
464
"""Handling of unknown command."""
465
out, err = self.run_bzr_captured(['fluffy-badger'],
467
self.assertEquals(out, '')
468
err.index('unknown command')
470
def test_conflicts(self):
471
"""Handling of merge conflicts"""
474
file('hello', 'wb').write("hi world")
475
file('answer', 'wb').write("42")
478
self.runbzr('commit -m base')
479
self.runbzr('branch . ../other')
480
self.runbzr('branch . ../this')
482
file('hello', 'wb').write("Hello.")
483
file('answer', 'wb').write("Is anyone there?")
484
self.runbzr('commit -m other')
486
file('hello', 'wb').write("Hello, world")
487
self.runbzr('mv answer question')
488
file('question', 'wb').write("What do you get when you multiply six"
490
self.runbzr('commit -m this')
491
self.runbzr('merge ../other')
492
result = self.runbzr('conflicts', backtick=1)
493
self.assertEquals(result, "hello\nquestion\n")
494
result = self.runbzr('status', backtick=1)
495
assert "conflicts:\n hello\n question\n" in result, result
496
self.runbzr('resolve hello')
497
result = self.runbzr('conflicts', backtick=1)
498
self.assertEquals(result, "question\n")
499
self.runbzr('commit -m conflicts', retcode=1)
500
self.runbzr('resolve --all')
501
result = self.runbzr('conflicts', backtick=1)
502
self.runbzr('commit -m conflicts')
503
self.assertEquals(result, "")
505
def listdir_sorted(dir):
511
247
class OldTests(ExternalBase):
512
248
"""old tests moved from ./testbzr."""
686
os.symlink("NOWHERE1", "link1")
688
assert self.capture('unknowns') == ''
689
runbzr(['commit', '-m', '1: added symlink link1'])
693
assert self.capture('unknowns') == ''
694
os.symlink("NOWHERE2", "d1/link2")
695
assert self.capture('unknowns') == 'd1/link2\n'
696
# is d1/link2 found when adding d1
698
assert self.capture('unknowns') == ''
699
os.symlink("NOWHERE3", "d1/link3")
700
assert self.capture('unknowns') == 'd1/link3\n'
701
runbzr(['commit', '-m', '2: added dir, symlink'])
703
runbzr('rename d1 d2')
704
runbzr('move d2/link2 .')
705
runbzr('move link1 d2')
706
assert os.readlink("./link2") == "NOWHERE2"
707
assert os.readlink("d2/link1") == "NOWHERE1"
708
runbzr('add d2/link3')
710
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
713
os.symlink("TARGET 2", "link2")
714
os.unlink("d2/link1")
715
os.symlink("TARGET 1", "d2/link1")
717
assert self.capture("relpath d2/link1") == "d2/link1\n"
718
runbzr(['commit', '-m', '4: retarget of two links'])
720
runbzr('remove d2/link1')
721
assert self.capture('unknowns') == 'd2/link1\n'
722
runbzr(['commit', '-m', '5: remove d2/link1'])
726
runbzr('rename d2/link3 d1/link3new')
727
assert self.capture('unknowns') == 'd2/link1\n'
728
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
732
runbzr(['export', '-r', '1', 'exp1.tmp'])
734
assert listdir_sorted(".") == [ "link1" ]
735
assert os.readlink("link1") == "NOWHERE1"
738
runbzr(['export', '-r', '2', 'exp2.tmp'])
740
assert listdir_sorted(".") == [ "d1", "link1" ]
743
runbzr(['export', '-r', '3', 'exp3.tmp'])
745
assert listdir_sorted(".") == [ "d2", "link2" ]
746
assert listdir_sorted("d2") == [ "link1", "link3" ]
747
assert os.readlink("d2/link1") == "NOWHERE1"
748
assert os.readlink("link2") == "NOWHERE2"
751
runbzr(['export', '-r', '4', 'exp4.tmp'])
753
assert listdir_sorted(".") == [ "d2", "link2" ]
754
assert os.readlink("d2/link1") == "TARGET 1"
755
assert os.readlink("link2") == "TARGET 2"
756
assert listdir_sorted("d2") == [ "link1", "link3" ]
759
runbzr(['export', '-r', '5', 'exp5.tmp'])
761
assert listdir_sorted(".") == [ "d2", "link2" ]
762
assert os.path.islink("link2")
763
assert listdir_sorted("d2")== [ "link3" ]
766
runbzr(['export', '-r', '6', 'exp6.tmp'])
768
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
769
assert listdir_sorted("d1") == [ "link3new" ]
770
assert listdir_sorted("d2") == []
771
assert os.readlink("d1/link3new") == "NOWHERE3"
774
progress("skipping symlink tests")