86
73
f = file('.bzr/email', 'wt')
87
74
f.write('Branch Identity <branch@identi.ty>')
89
bzr_email = os.environ.get('BZREMAIL')
90
if bzr_email is not None:
91
del os.environ['BZREMAIL']
92
76
whoami = self.runbzr("whoami",backtick=True)
93
77
whoami_email = self.runbzr("whoami --email",backtick=True)
94
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
95
79
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
96
# Verify that the environment variable overrides the value
98
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
99
whoami = self.runbzr("whoami",backtick=True)
100
whoami_email = self.runbzr("whoami --email",backtick=True)
101
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
102
self.assertTrue(whoami_email.startswith('other@environ.ment'))
103
if bzr_email is not None:
104
os.environ['BZREMAIL'] = bzr_email
106
def test_nick_command(self):
107
"""bzr nick for viewing, setting nicknames"""
111
nick = self.runbzr("nick",backtick=True)
112
self.assertEqual(nick, 'me.dev\n')
113
nick = self.runbzr("nick moo")
114
nick = self.runbzr("nick",backtick=True)
115
self.assertEqual(nick, 'moo\n')
118
81
def test_invalid_commands(self):
119
self.runbzr("pants", retcode=3)
120
self.runbzr("--pants off", retcode=3)
121
self.runbzr("diff --message foo", retcode=3)
82
self.runbzr("pants", retcode=1)
83
self.runbzr("--pants off", retcode=1)
84
self.runbzr("diff --message foo", retcode=1)
123
86
def test_empty_commit(self):
124
87
self.runbzr("init")
125
88
self.build_tree(['hello.txt'])
126
self.runbzr("commit -m empty", retcode=3)
89
self.runbzr("commit -m empty", retcode=1)
127
90
self.runbzr("add hello.txt")
128
self.runbzr("commit -m added")
130
def test_empty_commit_message(self):
132
file('foo.c', 'wt').write('int main() {}')
133
self.runbzr(['add', 'foo.c'])
134
self.runbzr(["commit", "-m", ""] , retcode=3)
136
def test_remove_deleted(self):
138
self.build_tree(['a'])
139
self.runbzr(['add', 'a'])
140
self.runbzr(['commit', '-m', 'added a'])
142
self.runbzr(['remove', 'a'])
144
def test_other_branch_commit(self):
145
# this branch is to ensure consistent behaviour, whether we're run
146
# inside a branch, or not.
147
os.mkdir('empty_branch')
148
os.chdir('empty_branch')
153
file('foo.c', 'wt').write('int main() {}')
154
file('bar.c', 'wt').write('int main() {}')
156
self.runbzr(['add', 'branch/foo.c'])
157
self.runbzr(['add', 'branch'])
158
# can't commit files in different trees; sane error
159
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
160
self.runbzr('commit -m newstuff branch/foo.c')
161
self.runbzr('commit -m newstuff branch')
162
self.runbzr('commit -m newstuff branch', retcode=3)
91
self.runbzr("commit -m added")
164
93
def test_ignore_patterns(self):
165
94
from bzrlib.branch import Branch
166
Branch.initialize('.')
167
self.assertEquals(self.capture('unknowns'), '')
96
b = Branch('.', init=True)
97
self.assertEquals(list(b.unknowns()), [])
169
99
file('foo.tmp', 'wt').write('tmp files are ignored')
170
self.assertEquals(self.capture('unknowns'), '')
100
self.assertEquals(list(b.unknowns()), [])
101
assert self.backtick('bzr unknowns') == ''
172
103
file('foo.c', 'wt').write('int main() {}')
173
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
104
self.assertEquals(list(b.unknowns()), ['foo.c'])
105
assert self.backtick('bzr unknowns') == 'foo.c\n'
175
107
self.runbzr(['add', 'foo.c'])
176
self.assertEquals(self.capture('unknowns'), '')
108
assert self.backtick('bzr unknowns') == ''
178
110
# 'ignore' works when creating the .bzignore file
179
111
file('foo.blah', 'wt').write('blah')
180
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
112
self.assertEquals(list(b.unknowns()), ['foo.blah'])
181
113
self.runbzr('ignore *.blah')
182
self.assertEquals(self.capture('unknowns'), '')
183
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
114
self.assertEquals(list(b.unknowns()), [])
115
assert file('.bzrignore', 'rb').read() == '*.blah\n'
185
117
# 'ignore' works when then .bzrignore file already exists
186
118
file('garh', 'wt').write('garh')
187
self.assertEquals(self.capture('unknowns'), 'garh\n')
119
self.assertEquals(list(b.unknowns()), ['garh'])
120
assert self.backtick('bzr unknowns') == 'garh\n'
188
121
self.runbzr('ignore garh')
189
self.assertEquals(self.capture('unknowns'), '')
190
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
122
self.assertEquals(list(b.unknowns()), [])
123
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
192
125
def test_revert(self):
193
126
self.runbzr('init')
291
184
test.runbzr('add goodbye')
292
185
test.runbzr('commit -m setup goodbye')
294
def test_export(self):
297
self.example_branch()
298
self.runbzr('export ../latest')
299
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
300
self.runbzr('export ../first -r 1')
301
self.assert_(not os.path.exists('../first/goodbye'))
302
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
303
self.runbzr('export ../first.gz -r 1')
304
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
305
self.runbzr('export ../first.bz2 -r 1')
306
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
308
from tarfile import TarFile
309
self.runbzr('export ../first.tar -r 1')
310
self.assert_(os.path.isfile('../first.tar'))
311
tf = TarFile('../first.tar')
312
self.assert_('first/hello' in tf.getnames(), tf.getnames())
313
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
314
self.runbzr('export ../first.tar.gz -r 1')
315
self.assert_(os.path.isfile('../first.tar.gz'))
316
self.runbzr('export ../first.tbz2 -r 1')
317
self.assert_(os.path.isfile('../first.tbz2'))
318
self.runbzr('export ../first.tar.bz2 -r 1')
319
self.assert_(os.path.isfile('../first.tar.bz2'))
320
self.runbzr('export ../first.tar.tbz2 -r 1')
321
self.assert_(os.path.isfile('../first.tar.tbz2'))
323
from bz2 import BZ2File
324
tf = TarFile('../first.tar.tbz2',
325
fileobj=BZ2File('../first.tar.tbz2', 'r'))
326
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
327
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
328
self.runbzr('export ../first2.tar -r 1 --root pizza')
329
tf = TarFile('../first2.tar')
330
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
332
from zipfile import ZipFile
333
self.runbzr('export ../first.zip -r 1')
334
self.failUnlessExists('../first.zip')
335
zf = ZipFile('../first.zip')
336
self.assert_('first/hello' in zf.namelist(), zf.namelist())
337
self.assertEqual(zf.read('first/hello'), 'foo')
339
self.runbzr('export ../first2.zip -r 1 --root pizza')
340
zf = ZipFile('../first2.zip')
341
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
343
self.runbzr('export ../first-zip --format=zip -r 1')
344
zf = ZipFile('../first-zip')
345
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
348
self.example_branch()
349
file('hello', 'wt').write('hello world!')
350
self.runbzr('commit -m fixing hello')
351
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
352
self.assert_('\n+hello world!' in output)
353
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
354
self.assert_('\n+baz' in output)
355
file('moo', 'wb').write('moo')
356
self.runbzr('add moo')
360
def test_diff_branches(self):
361
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
362
branch = Branch.initialize('branch1')
363
branch.working_tree().add(['file'])
364
branch.working_tree().commit('add file')
365
branch.clone('branch2')
366
print >> open('branch2/file', 'wb'), 'new content'
367
branch2 = Branch.open('branch2')
368
branch2.working_tree().commit('update file')
369
# should open branch1 and diff against branch2,
370
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
373
self.assertEquals(("=== modified file 'file'\n"
378
"+contents of branch1/file\n"
380
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
382
self.assertEqualDiff(("=== modified file 'file'\n"
387
"+contents of branch1/file\n"
391
def test_branch(self):
392
"""Branch from one branch to another."""
395
self.example_branch()
397
self.runbzr('branch a b')
398
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
399
self.runbzr('branch a c -r 1')
401
self.runbzr('commit -m foo --unchanged')
403
# naughty - abstraction violations RBC 20050928
404
print "test_branch used to delete the stores, how is this meant to work ?"
405
#shutil.rmtree('a/.bzr/revision-store')
406
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
407
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
408
self.runbzr('branch a d --basis b')
187
def test_revert(self):
188
self.example_branch()
189
file('hello', 'wt').write('bar')
190
file('goodbye', 'wt').write('qux')
191
self.runbzr('revert hello')
192
self.check_file_contents('hello', 'foo')
193
self.check_file_contents('goodbye', 'qux')
194
self.runbzr('revert')
195
self.check_file_contents('goodbye', 'baz')
410
197
def test_merge(self):
411
198
from bzrlib.branch import Branch
423
210
file('hello', 'wt').write('quuux')
424
211
# We can't merge when there are in-tree changes
425
self.runbzr('merge ../b', retcode=3)
212
self.runbzr('merge ../b', retcode=1)
426
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
427
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
429
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
430
self.runbzr('revert --no-backup')
431
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
432
self.runbzr('revert --no-backup')
433
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
434
self.runbzr('revert --no-backup')
435
self.runbzr('merge ../b -r last:1')
214
self.runbzr('merge ../b')
436
215
self.check_file_contents('goodbye', 'quux')
437
216
# Merging a branch pulls its revision into the tree
439
b = Branch.open('../b')
440
a.repository.get_revision_xml(b.last_revision())
441
self.log('pending merges: %s', a.working_tree().pending_merges())
442
self.assertEquals(a.working_tree().pending_merges(),
444
self.runbzr('commit -m merged')
445
self.runbzr('merge ../b -r last:1')
446
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
448
def test_merge_with_missing_file(self):
449
"""Merge handles missing file conflicts"""
453
print >> file('sub/a.txt', 'wb'), "hello"
454
print >> file('b.txt', 'wb'), "hello"
455
print >> file('sub/c.txt', 'wb'), "hello"
458
self.runbzr(('commit', '-m', 'added a'))
459
self.runbzr('branch . ../b')
460
print >> file('sub/a.txt', 'ab'), "there"
461
print >> file('b.txt', 'ab'), "there"
462
print >> file('sub/c.txt', 'ab'), "there"
463
self.runbzr(('commit', '-m', 'Added there'))
464
os.unlink('sub/a.txt')
465
os.unlink('sub/c.txt')
468
self.runbzr(('commit', '-m', 'Removed a.txt'))
470
print >> file('sub/a.txt', 'ab'), "something"
471
print >> file('b.txt', 'ab'), "something"
472
print >> file('sub/c.txt', 'ab'), "something"
473
self.runbzr(('commit', '-m', 'Modified a.txt'))
474
self.runbzr('merge ../a/', retcode=1)
475
self.assert_(os.path.exists('sub/a.txt.THIS'))
476
self.assert_(os.path.exists('sub/a.txt.BASE'))
478
self.runbzr('merge ../b/', retcode=1)
479
self.assert_(os.path.exists('sub/a.txt.OTHER'))
480
self.assert_(os.path.exists('sub/a.txt.BASE'))
482
def test_inventory(self):
484
def output_equals(value, *args):
485
out = self.runbzr(['inventory'] + list(args), backtick=True)
486
self.assertEquals(out, value)
489
open('a', 'wb').write('hello\n')
495
output_equals('a\n', '--kind', 'file')
496
output_equals('b\n', '--kind', 'directory')
499
"""Test the abilities of 'bzr ls'"""
501
def bzrout(*args, **kwargs):
502
kwargs['backtick'] = True
503
return self.runbzr(*args, **kwargs)
505
def ls_equals(value, *args):
506
out = self.runbzr(['ls'] + list(args), backtick=True)
507
self.assertEquals(out, value)
510
open('a', 'wb').write('hello\n')
513
bzr('ls --verbose --null', retcode=3)
516
ls_equals('? a\n', '--verbose')
517
ls_equals('a\n', '--unknown')
518
ls_equals('', '--ignored')
519
ls_equals('', '--versioned')
520
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
521
ls_equals('', '--ignored', '--versioned')
522
ls_equals('a\0', '--null')
525
ls_equals('V a\n', '--verbose')
532
open('subdir/b', 'wb').write('b\n')
538
bzr('commit -m subdir')
546
, '--verbose', '--non-recursive')
548
# Check what happens in a sub-directory
560
, '--from-root', '--null')
563
, '--from-root', '--non-recursive')
567
# Check what happens when we supply a specific revision
568
ls_equals('a\n', '--revision', '1')
570
, '--verbose', '--revision', '1')
573
ls_equals('', '--revision', '1')
575
# Now try to do ignored files.
577
open('blah.py', 'wb').write('unknown\n')
578
open('blah.pyo', 'wb').write('ignored\n')
590
ls_equals('blah.pyo\n'
592
ls_equals('blah.py\n'
601
file("myfile", "wb").write("My contents\n")
603
self.runbzr('commit -m myfile')
604
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
606
def test_pull_verbose(self):
607
"""Pull changes from one branch to another and watch the output."""
219
a.get_revision_xml(b.last_patch())
220
self.log('pending merges: %s', a.pending_merges())
221
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
222
# % (a.pending_merges(), b.last_patch())
225
"""Pull changes from one branch to another."""
613
229
self.example_branch()
230
self.runbzr('pull', retcode=1)
231
self.runbzr('missing', retcode=1)
232
self.runbzr('missing .')
233
self.runbzr('missing')
235
self.runbzr('pull /', retcode=1)
239
self.runbzr('branch a b')
618
open('b', 'wb').write('else\n')
620
bzr(['commit', '-m', 'added b'])
623
out = bzr('pull --verbose ../b', backtick=True)
624
self.failIfEqual(out.find('Added Revisions:'), -1)
625
self.failIfEqual(out.find('message:\n added b'), -1)
626
self.failIfEqual(out.find('added b'), -1)
628
# Check that --overwrite --verbose prints out the removed entries
629
bzr('commit -m foo --unchanged')
631
bzr('commit -m baz --unchanged')
632
bzr('pull ../a', retcode=3)
633
out = bzr('pull --overwrite --verbose ../a', backtick=1)
635
remove_loc = out.find('Removed Revisions:')
636
self.failIfEqual(remove_loc, -1)
637
added_loc = out.find('Added Revisions:')
638
self.failIfEqual(added_loc, -1)
640
removed_message = out.find('message:\n baz')
641
self.failIfEqual(removed_message, -1)
642
self.failUnless(remove_loc < removed_message < added_loc)
644
added_message = out.find('message:\n foo')
645
self.failIfEqual(added_message, -1)
646
self.failUnless(added_loc < added_message)
648
def test_locations(self):
649
"""Using and remembering different locations"""
653
self.runbzr('commit -m unchanged --unchanged')
654
self.runbzr('pull', retcode=3)
655
self.runbzr('merge', retcode=3)
656
self.runbzr('branch . ../b')
658
241
self.runbzr('pull')
659
self.runbzr('branch . ../c')
660
self.runbzr('pull ../c')
242
self.runbzr('commit -m blah --unchanged')
246
assert a.revision_history() == b.revision_history()[:-1]
663
247
self.runbzr('pull ../b')
665
self.runbzr('pull ../c')
666
self.runbzr('branch ../c ../d')
667
shutil.rmtree('../c')
672
self.runbzr('pull', retcode=3)
673
self.runbzr('pull ../a --remember')
248
assert a.revision_history() == b.revision_history()
249
self.runbzr('commit -m blah2 --unchanged')
251
self.runbzr('commit -m blah3 --unchanged')
252
self.runbzr('pull ../a', retcode=1)
254
self.runbzr('merge ../b')
255
self.runbzr('commit -m blah4 --unchanged')
257
self.runbzr('pull ../a')
258
assert a.revision_history()[-1] == b.revision_history()[-1]
676
261
def test_add_reports(self):
677
262
"""add command prints the names of added files."""
678
b = Branch.initialize('.')
679
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
680
out = self.run_bzr_captured(['add'], retcode=0)[0]
263
b = Branch('.', init=True)
264
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
266
from cStringIO import StringIO
269
ret = self.apply_redirected(None, out, None,
272
self.assertEquals(ret, 0)
681
274
# the ordering is not defined at the moment
682
results = sorted(out.rstrip('\n').split('\n'))
683
self.assertEquals(['If you wish to add some of these files, please'\
684
' add them by name.',
275
results = sorted(out.getvalue().rstrip('\n').split('\n'))
276
self.assertEquals(['added dir',
686
277
'added dir/sub.txt',
688
'ignored 1 file(s) matching "CVS"'],
690
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
691
results = sorted(out.rstrip('\n').split('\n'))
692
self.assertEquals(['If you wish to add some of these files, please'\
693
' add them by name.',
694
'ignored CVS matching "CVS"'],
697
def test_add_quiet_is(self):
698
"""add -q does not print the names of added files."""
699
b = Branch.initialize('.')
700
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
701
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
702
# the ordering is not defined at the moment
703
results = sorted(out.rstrip('\n').split('\n'))
704
self.assertEquals([''], results)
706
def test_add_in_unversioned(self):
707
"""Try to add a file in an unversioned directory.
709
"bzr add" should add the parent(s) as necessary.
711
from bzrlib.branch import Branch
712
Branch.initialize('.')
713
self.build_tree(['inertiatic/', 'inertiatic/esp'])
714
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
715
self.run_bzr('add', 'inertiatic/esp')
716
self.assertEquals(self.capture('unknowns'), '')
718
# Multiple unversioned parents
719
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
720
self.assertEquals(self.capture('unknowns'), 'veil\n')
721
self.run_bzr('add', 'veil/cerpin/taxt')
722
self.assertEquals(self.capture('unknowns'), '')
724
# Check whacky paths work
725
self.build_tree(['cicatriz/', 'cicatriz/esp'])
726
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
727
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
728
self.assertEquals(self.capture('unknowns'), '')
730
def test_add_in_versioned(self):
731
"""Try to add a file in a versioned directory.
733
"bzr add" should do this happily.
735
from bzrlib.branch import Branch
736
Branch.initialize('.')
737
self.build_tree(['inertiatic/', 'inertiatic/esp'])
738
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
739
self.run_bzr('add', '--no-recurse', 'inertiatic')
740
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
741
self.run_bzr('add', 'inertiatic/esp')
742
self.assertEquals(self.capture('unknowns'), '')
744
def test_subdir_add(self):
745
"""Add in subdirectory should add only things from there down"""
746
from bzrlib.branch import Branch
748
eq = self.assertEqual
752
b = Branch.initialize('.')
754
self.build_tree(['src/', 'README'])
756
eq(sorted(t.unknowns()),
759
self.run_bzr('add', 'src')
761
self.build_tree(['src/foo.c'])
766
self.assertEquals(self.capture('unknowns'), 'README\n')
767
eq(len(t.read_working_inventory()), 3)
771
self.assertEquals(self.capture('unknowns'), '')
772
self.run_bzr('check')
774
def test_unknown_command(self):
775
"""Handling of unknown command."""
776
out, err = self.run_bzr_captured(['fluffy-badger'],
778
self.assertEquals(out, '')
779
err.index('unknown command')
781
def create_conflicts(self):
782
"""Create a conflicted tree"""
785
file('hello', 'wb').write("hi world")
786
file('answer', 'wb').write("42")
789
self.runbzr('commit -m base')
790
self.runbzr('branch . ../other')
791
self.runbzr('branch . ../this')
793
file('hello', 'wb').write("Hello.")
794
file('answer', 'wb').write("Is anyone there?")
795
self.runbzr('commit -m other')
797
file('hello', 'wb').write("Hello, world")
798
self.runbzr('mv answer question')
799
file('question', 'wb').write("What do you get when you multiply six"
801
self.runbzr('commit -m this')
803
def test_remerge(self):
804
"""Remerge command works as expected"""
805
self.create_conflicts()
806
self.runbzr('merge ../other --show-base', retcode=1)
807
conflict_text = file('hello').read()
808
assert '|||||||' in conflict_text
809
assert 'hi world' in conflict_text
810
self.runbzr('remerge', retcode=1)
811
conflict_text = file('hello').read()
812
assert '|||||||' not in conflict_text
813
assert 'hi world' not in conflict_text
814
os.unlink('hello.OTHER')
815
self.runbzr('remerge hello --merge-type weave', retcode=1)
816
assert os.path.exists('hello.OTHER')
817
file_id = self.runbzr('file-id hello')
818
file_id = self.runbzr('file-id hello.THIS', retcode=3)
819
self.runbzr('remerge --merge-type weave', retcode=1)
820
assert os.path.exists('hello.OTHER')
821
assert not os.path.exists('hello.BASE')
822
assert '|||||||' not in conflict_text
823
assert 'hi world' not in conflict_text
824
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
825
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
826
self.runbzr('remerge . --show-base --reprocess', retcode=3)
827
self.runbzr('remerge hello --show-base', retcode=1)
828
self.runbzr('remerge hello --reprocess', retcode=1)
829
self.runbzr('resolve --all')
830
self.runbzr('commit -m done',)
831
self.runbzr('remerge', retcode=3)
833
def test_status(self):
837
self.runbzr('commit --unchanged --message f')
838
self.runbzr('branch . ../branch2')
839
self.runbzr('branch . ../branch3')
840
self.runbzr('commit --unchanged --message peter')
841
os.chdir('../branch2')
842
self.runbzr('merge ../branch1')
843
self.runbzr('commit --unchanged --message pumpkin')
844
os.chdir('../branch3')
845
self.runbzr('merge ../branch2')
846
message = self.capture('status')
849
def test_conflicts(self):
850
"""Handling of merge conflicts"""
851
self.create_conflicts()
852
self.runbzr('merge ../other --show-base', retcode=1)
853
conflict_text = file('hello').read()
854
self.assert_('<<<<<<<' in conflict_text)
855
self.assert_('>>>>>>>' in conflict_text)
856
self.assert_('=======' in conflict_text)
857
self.assert_('|||||||' in conflict_text)
858
self.assert_('hi world' in conflict_text)
859
self.runbzr('revert')
860
self.runbzr('resolve --all')
861
self.runbzr('merge ../other', retcode=1)
862
conflict_text = file('hello').read()
863
self.assert_('|||||||' not in conflict_text)
864
self.assert_('hi world' not in conflict_text)
865
result = self.runbzr('conflicts', backtick=1)
866
self.assertEquals(result, "hello\nquestion\n")
867
result = self.runbzr('status', backtick=1)
868
self.assert_("conflicts:\n hello\n question\n" in result, result)
869
self.runbzr('resolve hello')
870
result = self.runbzr('conflicts', backtick=1)
871
self.assertEquals(result, "question\n")
872
self.runbzr('commit -m conflicts', retcode=3)
873
self.runbzr('resolve --all')
874
result = self.runbzr('conflicts', backtick=1)
875
self.runbzr('commit -m conflicts')
876
self.assertEquals(result, "")
878
def test_resign(self):
879
"""Test re signing of data."""
881
oldstrategy = bzrlib.gpg.GPGStrategy
882
branch = Branch.initialize('.')
883
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
885
# monkey patch gpg signing mechanism
886
from bzrlib.testament import Testament
887
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
888
self.runbzr('re-sign -r revid:A')
889
self.assertEqual(Testament.from_revision(branch.repository,
890
'A').as_short_text(),
891
branch.repository.revision_store.get('A',
894
bzrlib.gpg.GPGStrategy = oldstrategy
896
def test_resign_range(self):
898
oldstrategy = bzrlib.gpg.GPGStrategy
899
branch = Branch.initialize('.')
900
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
901
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
902
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
904
# monkey patch gpg signing mechanism
905
from bzrlib.testament import Testament
906
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
907
self.runbzr('re-sign -r 1..')
909
Testament.from_revision(branch.repository,'A').as_short_text(),
910
branch.repository.revision_store.get('A', 'sig').read())
912
Testament.from_revision(branch.repository,'B').as_short_text(),
913
branch.repository.revision_store.get('B', 'sig').read())
914
self.assertEqual(Testament.from_revision(branch.repository,
915
'C').as_short_text(),
916
branch.repository.revision_store.get('C',
919
bzrlib.gpg.GPGStrategy = oldstrategy
922
# create a source branch
923
os.mkdir('my-branch')
924
os.chdir('my-branch')
925
self.example_branch()
927
# with no push target, fail
928
self.runbzr('push', retcode=3)
929
# with an explicit target work
930
self.runbzr('push ../output-branch')
931
# with an implicit target work
934
self.runbzr('missing ../output-branch')
935
# advance this branch
936
self.runbzr('commit --unchanged -m unchanged')
938
os.chdir('../output-branch')
939
# There is no longer a difference as long as we have
940
# access to the working tree
943
# But we should be missing a revision
944
self.runbzr('missing ../my-branch', retcode=1)
946
# diverge the branches
947
self.runbzr('commit --unchanged -m unchanged')
948
os.chdir('../my-branch')
950
self.runbzr('push', retcode=3)
951
# and there are difference
952
self.runbzr('missing ../output-branch', retcode=1)
953
self.runbzr('missing --verbose ../output-branch', retcode=1)
954
# but we can force a push
955
self.runbzr('push --overwrite')
957
self.runbzr('missing ../output-branch')
959
# pushing to a new dir with no parent should fail
960
self.runbzr('push ../missing/new-branch', retcode=3)
961
# unless we provide --create-prefix
962
self.runbzr('push --create-prefix ../missing/new-branch')
964
self.runbzr('missing ../missing/new-branch')
966
def test_external_command(self):
967
"""test that external commands can be run by setting the path"""
968
cmd_name = 'test-command'
969
output = 'Hello from test-command'
970
if sys.platform == 'win32':
976
oldpath = os.environ.get('BZRPATH', None)
981
if os.environ.has_key('BZRPATH'):
982
del os.environ['BZRPATH']
984
f = file(cmd_name, 'wb')
985
if sys.platform == 'win32':
986
f.write('@echo off\n')
988
f.write('#!/bin/sh\n')
989
f.write('echo Hello from test-command')
991
os.chmod(cmd_name, 0755)
993
# It should not find the command in the local
994
# directory by default, since it is not in my path
995
bzr(cmd_name, retcode=3)
997
# Now put it into my path
998
os.environ['BZRPATH'] = '.'
1001
# The test suite does not capture stdout for external commands
1002
# this is because you have to have a real file object
1003
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
1004
# (just replacing sys.stdout does not change a spawned objects stdout)
1005
#self.assertEquals(bzr(cmd_name), output)
1007
# Make sure empty path elements are ignored
1008
os.environ['BZRPATH'] = os.pathsep
1010
bzr(cmd_name, retcode=3)
1014
os.environ['BZRPATH'] = oldpath
1017
def listdir_sorted(dir):
1023
282
class OldTests(ExternalBase):
1045
304
f.write('hello world!\n')
1048
self.assertEquals(capture('unknowns'), 'test.txt\n')
1050
out = capture("status")
1051
self.assertEquals(out, 'unknown:\n test.txt\n')
1053
out = capture("status --all")
1054
self.assertEquals(out, "unknown:\n test.txt\n")
1056
out = capture("status test.txt --all")
1057
self.assertEquals(out, "unknown:\n test.txt\n")
307
out = backtick("bzr unknowns")
308
self.assertEquals(out, 'test.txt\n')
310
out = backtick("bzr status")
311
assert out == 'unknown:\n test.txt\n'
313
out = backtick("bzr status --all")
314
assert out == "unknown:\n test.txt\n"
316
out = backtick("bzr status test.txt --all")
317
assert out == "unknown:\n test.txt\n"
1059
319
f = file('test2.txt', 'wt')
1060
320
f.write('goodbye cruel world...\n')
1063
out = capture("status test.txt")
1064
self.assertEquals(out, "unknown:\n test.txt\n")
323
out = backtick("bzr status test.txt")
324
assert out == "unknown:\n test.txt\n"
1066
out = capture("status")
1067
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
326
out = backtick("bzr status")
327
assert out == ("unknown:\n"
1069
331
os.unlink('test2.txt')
1071
333
progress("command aliases")
1072
out = capture("st --all")
1073
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
334
out = backtick("bzr st --all")
335
assert out == ("unknown:\n"
1075
out = capture("stat")
1076
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
338
out = backtick("bzr stat")
339
assert out == ("unknown:\n"
1078
342
progress("command help")
1079
343
runbzr("help st")
1081
345
runbzr("help commands")
1082
runbzr("help slartibartfast", 3)
346
runbzr("help slartibartfast", 1)
1084
out = capture("help ci")
348
out = backtick("bzr help ci")
1085
349
out.index('aliases: ')
1087
351
progress("can't rename unversioned file")
1088
runbzr("rename test.txt new-test.txt", 3)
352
runbzr("rename test.txt new-test.txt", 1)
1090
354
progress("adding a file")
1092
356
runbzr("add test.txt")
1093
self.assertEquals(capture("unknowns"), '')
1094
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
357
assert backtick("bzr unknowns") == ''
358
assert backtick("bzr status --all") == ("added:\n"
1096
361
progress("rename newly-added file")
1097
362
runbzr("rename test.txt hello.txt")
1098
self.assert_(os.path.exists("hello.txt"))
1099
self.assert_(not os.path.exists("test.txt"))
363
assert os.path.exists("hello.txt")
364
assert not os.path.exists("test.txt")
1101
self.assertEquals(capture("revno"), '0\n')
366
assert backtick("bzr revno") == '0\n'
1103
368
progress("add first revision")
1104
369
runbzr(['commit', '-m', 'add first revision'])
1106
371
progress("more complex renames")
1107
372
os.mkdir("sub1")
1108
runbzr("rename hello.txt sub1", 3)
1109
runbzr("rename hello.txt sub1/hello.txt", 3)
1110
runbzr("move hello.txt sub1", 3)
373
runbzr("rename hello.txt sub1", 1)
374
runbzr("rename hello.txt sub1/hello.txt", 1)
375
runbzr("move hello.txt sub1", 1)
1112
377
runbzr("add sub1")
1113
378
runbzr("rename sub1 sub2")
1114
379
runbzr("move hello.txt sub2")
1115
self.assertEqual(capture("relpath sub2/hello.txt"),
1116
pathjoin("sub2", "hello.txt\n"))
380
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1118
self.assert_(exists("sub2"))
1119
self.assert_(exists("sub2/hello.txt"))
1120
self.assert_(not exists("sub1"))
1121
self.assert_(not exists("hello.txt"))
382
assert exists("sub2")
383
assert exists("sub2/hello.txt")
384
assert not exists("sub1")
385
assert not exists("hello.txt")
1123
387
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1126
390
runbzr('add sub1')
1127
391
runbzr('move sub2/hello.txt sub1')
1128
self.assert_(not exists('sub2/hello.txt'))
1129
self.assert_(exists('sub1/hello.txt'))
392
assert not exists('sub2/hello.txt')
393
assert exists('sub1/hello.txt')
1130
394
runbzr('move sub2 sub1')
1131
self.assert_(not exists('sub2'))
1132
self.assert_(exists('sub1/sub2'))
395
assert not exists('sub2')
396
assert exists('sub1/sub2')
1134
398
runbzr(['commit', '-m', 'rename nested subdirectories'])
1136
400
chdir('sub1/sub2')
1137
self.assertEquals(capture('root')[:-1],
1138
pathjoin(self.test_dir, 'branch1'))
401
self.assertEquals(backtick('bzr root')[:-1],
402
os.path.join(self.test_dir, 'branch1'))
1139
403
runbzr('move ../hello.txt .')
1140
self.assert_(exists('./hello.txt'))
1141
self.assertEquals(capture('relpath hello.txt'),
1142
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
1143
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
404
assert exists('./hello.txt')
405
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
406
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1144
407
runbzr(['commit', '-m', 'move to parent directory'])
1146
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
409
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1148
411
runbzr('move sub2/hello.txt .')
1149
self.assert_(exists('hello.txt'))
412
assert exists('hello.txt')
1151
414
f = file('hello.txt', 'wt')
1152
415
f.write('some nice new content\n')
1155
418
f = file('msg.tmp', 'wt')
1156
f.write('this is my new commit\nand it has multiple lines, for fun')
419
f.write('this is my new commit\n')
1159
422
runbzr('commit -F msg.tmp')
1161
self.assertEquals(capture('revno'), '5\n')
424
assert backtick('bzr revno') == '5\n'
1162
425
runbzr('export -r 5 export-5.tmp')
1163
426
runbzr('export export.tmp')
1166
429
runbzr('log -v')
1167
430
runbzr('log -v --forward')
1168
runbzr('log -m', retcode=3)
1169
log_out = capture('log -m commit')
1170
self.assert_("this is my new commit\n and" in log_out)
1171
self.assert_("rename nested" not in log_out)
1172
self.assert_('revision-id' not in log_out)
1173
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1175
log_out = capture('log --line')
1176
for line in log_out.splitlines():
1177
self.assert_(len(line) <= 79, len(line))
1178
self.assert_("this is my new commit and" in log_out)
431
runbzr('log -m', retcode=1)
432
log_out = backtick('bzr log -m commit')
433
assert "this is my new commit" in log_out
434
assert "rename nested" not in log_out
435
assert 'revision-id' not in log_out
436
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1181
439
progress("file with spaces in name")
1182
440
mkdir('sub directory')
1183
441
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1185
runbzr('diff', retcode=1)
1186
444
runbzr('commit -m add-spaces')
1195
progress("symlinks")
1199
os.symlink("NOWHERE1", "link1")
1201
self.assertEquals(self.capture('unknowns'), '')
1202
runbzr(['commit', '-m', '1: added symlink link1'])
1206
self.assertEquals(self.capture('unknowns'), '')
1207
os.symlink("NOWHERE2", "d1/link2")
1208
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1209
# is d1/link2 found when adding d1
1211
self.assertEquals(self.capture('unknowns'), '')
1212
os.symlink("NOWHERE3", "d1/link3")
1213
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1214
runbzr(['commit', '-m', '2: added dir, symlink'])
1216
runbzr('rename d1 d2')
1217
runbzr('move d2/link2 .')
1218
runbzr('move link1 d2')
1219
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1220
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1221
runbzr('add d2/link3')
1222
runbzr('diff', retcode=1)
1223
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1226
os.symlink("TARGET 2", "link2")
1227
os.unlink("d2/link1")
1228
os.symlink("TARGET 1", "d2/link1")
1229
runbzr('diff', retcode=1)
1230
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1231
runbzr(['commit', '-m', '4: retarget of two links'])
1233
runbzr('remove d2/link1')
1234
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1235
runbzr(['commit', '-m', '5: remove d2/link1'])
1236
# try with the rm alias
1237
runbzr('add d2/link1')
1238
runbzr(['commit', '-m', '6: add d2/link1'])
1239
runbzr('rm d2/link1')
1240
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1241
runbzr(['commit', '-m', '7: remove d2/link1'])
1245
runbzr('rename d2/link3 d1/link3new')
1246
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1247
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1251
runbzr(['export', '-r', '1', 'exp1.tmp'])
1253
self.assertEquals(listdir_sorted("."), [ "link1" ])
1254
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1257
runbzr(['export', '-r', '2', 'exp2.tmp'])
1259
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1262
runbzr(['export', '-r', '3', 'exp3.tmp'])
1264
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1265
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1266
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1267
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1270
runbzr(['export', '-r', '4', 'exp4.tmp'])
1272
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1273
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1274
self.assertEquals(os.readlink("link2") , "TARGET 2")
1275
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1278
runbzr(['export', '-r', '5', 'exp5.tmp'])
1280
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1281
self.assert_(os.path.islink("link2"))
1282
self.assert_(listdir_sorted("d2")== [ "link3" ])
1285
runbzr(['export', '-r', '8', 'exp6.tmp'])
1287
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1288
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1289
self.assertEquals(listdir_sorted("d2"), [])
1290
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1293
progress("skipping symlink tests")
1296
class HttpTests(TestCaseWithWebserver):
1297
"""Test bzr ui commands against remote branches."""
1299
def test_branch(self):
1301
branch = Branch.initialize('from')
1302
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1303
url = self.get_remote_url('from')
1304
self.run_bzr('branch', url, 'to')
1305
branch = Branch.open('to')
1306
self.assertEqual(1, len(branch.revision_history()))
1309
self.build_tree(['branch/', 'branch/file'])
1310
branch = Branch.initialize('branch')
1311
branch.working_tree().add(['file'])
1312
branch.working_tree().commit('add file', rev_id='A')
1313
url = self.get_remote_url('branch/file')
1314
output = self.capture('log %s' % url)
1315
self.assertEqual(8, len(output.split('\n')))
1316
# FIXME: rbc 20051128 what is the remainder of this test testing?
1317
# - it does not seem to be http specific.
1318
copy = branch.clone('branch2')
1319
branch.working_tree().commit(message='empty commit')
1321
self.run_bzr('merge', '../branch')
1322
copy.working_tree().commit(message='merge')
1323
output = self.capture('log')
1325
def test_check(self):
1326
self.build_tree(['branch/', 'branch/file'])
1327
branch = Branch.initialize('branch')
1328
branch.working_tree().add(['file'])
1329
branch.working_tree().commit('add file', rev_id='A')
1330
url = self.get_remote_url('branch/')
1331
self.run_bzr('check', url)