83
77
f = file('.bzr/email', 'wt')
84
78
f.write('Branch Identity <branch@identi.ty>')
86
bzr_email = os.environ.get('BZREMAIL')
87
if bzr_email is not None:
88
del os.environ['BZREMAIL']
89
80
whoami = self.runbzr("whoami",backtick=True)
90
81
whoami_email = self.runbzr("whoami --email",backtick=True)
91
82
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
92
83
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
93
# Verify that the environment variable overrides the value
95
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
96
whoami = self.runbzr("whoami",backtick=True)
97
whoami_email = self.runbzr("whoami --email",backtick=True)
98
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
99
self.assertTrue(whoami_email.startswith('other@environ.ment'))
100
if bzr_email is not None:
101
os.environ['BZREMAIL'] = bzr_email
103
def test_nick_command(self):
104
"""bzr nick for viewing, setting nicknames"""
108
nick = self.runbzr("nick",backtick=True)
109
self.assertEqual(nick, 'me.dev\n')
110
nick = self.runbzr("nick moo")
111
nick = self.runbzr("nick",backtick=True)
112
self.assertEqual(nick, 'moo\n')
115
85
def test_invalid_commands(self):
116
self.runbzr("pants", retcode=3)
117
self.runbzr("--pants off", retcode=3)
118
self.runbzr("diff --message foo", retcode=3)
86
self.runbzr("pants", retcode=1)
87
self.runbzr("--pants off", retcode=1)
88
self.runbzr("diff --message foo", retcode=1)
120
90
def test_empty_commit(self):
121
91
self.runbzr("init")
122
92
self.build_tree(['hello.txt'])
123
self.runbzr("commit -m empty", retcode=3)
93
self.runbzr("commit -m empty", retcode=1)
124
94
self.runbzr("add hello.txt")
125
self.runbzr("commit -m added")
127
def test_empty_commit_message(self):
129
file('foo.c', 'wt').write('int main() {}')
130
self.runbzr(['add', 'foo.c'])
131
self.runbzr(["commit", "-m", ""] , retcode=3)
133
def test_remove_deleted(self):
135
self.build_tree(['a'])
136
self.runbzr(['add', 'a'])
137
self.runbzr(['commit', '-m', 'added a'])
139
self.runbzr(['remove', 'a'])
141
def test_other_branch_commit(self):
142
# this branch is to ensure consistent behaviour, whether we're run
143
# inside a branch, or not.
144
os.mkdir('empty_branch')
145
os.chdir('empty_branch')
150
file('foo.c', 'wt').write('int main() {}')
151
file('bar.c', 'wt').write('int main() {}')
153
self.runbzr(['add', 'branch/foo.c'])
154
self.runbzr(['add', 'branch'])
155
# can't commit files in different trees; sane error
156
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
157
self.runbzr('commit -m newstuff branch/foo.c')
158
self.runbzr('commit -m newstuff branch')
159
self.runbzr('commit -m newstuff branch', retcode=3)
95
self.runbzr("commit -m added")
161
97
def test_ignore_patterns(self):
162
98
from bzrlib.branch import Branch
163
Branch.initialize('.')
164
self.assertEquals(self.capture('unknowns'), '')
100
b = Branch('.', init=True)
101
self.assertEquals(list(b.unknowns()), [])
166
103
file('foo.tmp', 'wt').write('tmp files are ignored')
167
self.assertEquals(self.capture('unknowns'), '')
104
self.assertEquals(list(b.unknowns()), [])
105
assert self.backtick('bzr unknowns') == ''
169
107
file('foo.c', 'wt').write('int main() {}')
170
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
108
self.assertEquals(list(b.unknowns()), ['foo.c'])
109
assert self.backtick('bzr unknowns') == 'foo.c\n'
172
111
self.runbzr(['add', 'foo.c'])
173
self.assertEquals(self.capture('unknowns'), '')
112
assert self.backtick('bzr unknowns') == ''
175
114
# 'ignore' works when creating the .bzignore file
176
115
file('foo.blah', 'wt').write('blah')
177
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
116
self.assertEquals(list(b.unknowns()), ['foo.blah'])
178
117
self.runbzr('ignore *.blah')
179
self.assertEquals(self.capture('unknowns'), '')
180
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
118
self.assertEquals(list(b.unknowns()), [])
119
assert file('.bzrignore', 'rb').read() == '*.blah\n'
182
121
# 'ignore' works when then .bzrignore file already exists
183
122
file('garh', 'wt').write('garh')
184
self.assertEquals(self.capture('unknowns'), 'garh\n')
123
self.assertEquals(list(b.unknowns()), ['garh'])
124
assert self.backtick('bzr unknowns') == 'garh\n'
185
125
self.runbzr('ignore garh')
186
self.assertEquals(self.capture('unknowns'), '')
187
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
126
self.assertEquals(list(b.unknowns()), [])
127
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
189
129
def test_revert(self):
190
131
self.runbzr('init')
192
133
file('hello', 'wt').write('foo')
276
178
self.log(tmp_output)
277
179
self.assertEquals(output, tmp_output)
279
def example_branch(test):
281
file('hello', 'wt').write('foo')
282
test.runbzr('add hello')
283
test.runbzr('commit -m setup hello')
284
file('goodbye', 'wt').write('baz')
285
test.runbzr('add goodbye')
286
test.runbzr('commit -m setup goodbye')
288
def test_export(self):
291
self.example_branch()
292
self.runbzr('export ../latest')
293
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
294
self.runbzr('export ../first -r 1')
295
self.assert_(not os.path.exists('../first/goodbye'))
296
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
297
self.runbzr('export ../first.gz -r 1')
298
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
299
self.runbzr('export ../first.bz2 -r 1')
300
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
302
from tarfile import TarFile
303
self.runbzr('export ../first.tar -r 1')
304
self.assert_(os.path.isfile('../first.tar'))
305
tf = TarFile('../first.tar')
306
self.assert_('first/hello' in tf.getnames(), tf.getnames())
307
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
308
self.runbzr('export ../first.tar.gz -r 1')
309
self.assert_(os.path.isfile('../first.tar.gz'))
310
self.runbzr('export ../first.tbz2 -r 1')
311
self.assert_(os.path.isfile('../first.tbz2'))
312
self.runbzr('export ../first.tar.bz2 -r 1')
313
self.assert_(os.path.isfile('../first.tar.bz2'))
314
self.runbzr('export ../first.tar.tbz2 -r 1')
315
self.assert_(os.path.isfile('../first.tar.tbz2'))
317
from bz2 import BZ2File
318
tf = TarFile('../first.tar.tbz2',
319
fileobj=BZ2File('../first.tar.tbz2', 'r'))
320
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
321
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
322
self.runbzr('export ../first2.tar -r 1 --root pizza')
323
tf = TarFile('../first2.tar')
324
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
326
from zipfile import ZipFile
327
self.runbzr('export ../first.zip -r 1')
328
self.failUnlessExists('../first.zip')
329
zf = ZipFile('../first.zip')
330
self.assert_('first/hello' in zf.namelist(), zf.namelist())
331
self.assertEqual(zf.read('first/hello'), 'foo')
333
self.runbzr('export ../first2.zip -r 1 --root pizza')
334
zf = ZipFile('../first2.zip')
335
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
337
self.runbzr('export ../first-zip --format=zip -r 1')
338
zf = ZipFile('../first-zip')
339
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
342
self.example_branch()
343
file('hello', 'wt').write('hello world!')
344
self.runbzr('commit -m fixing hello')
345
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
346
self.assert_('\n+hello world!' in output)
347
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
348
self.assert_('\n+baz' in output)
349
file('moo', 'wb').write('moo')
350
self.runbzr('add moo')
354
def test_diff_branches(self):
355
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
356
branch = Branch.initialize('branch1')
357
branch.working_tree().add(['file'])
358
branch.working_tree().commit('add file')
359
copy_branch(branch, 'branch2')
360
print >> open('branch2/file', 'wb'), 'new content'
361
branch2 = Branch.open('branch2')
362
branch2.working_tree().commit('update file')
363
# should open branch1 and diff against branch2,
364
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
367
self.assertEquals(("=== modified file 'file'\n"
372
"+contents of branch1/file\n"
374
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
376
self.assertEqualDiff(("=== modified file 'file'\n"
381
"+contents of branch1/file\n"
385
def test_branch(self):
386
"""Branch from one branch to another."""
389
self.example_branch()
391
self.runbzr('branch a b')
392
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
393
self.runbzr('branch a c -r 1')
395
self.runbzr('commit -m foo --unchanged')
397
# naughty - abstraction violations RBC 20050928
398
print "test_branch used to delete the stores, how is this meant to work ?"
399
#shutil.rmtree('a/.bzr/revision-store')
400
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
401
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
402
self.runbzr('branch a d --basis b')
404
def test_merge(self):
405
from bzrlib.branch import Branch
409
self.example_branch()
411
self.runbzr('branch a b')
413
file('goodbye', 'wt').write('quux')
414
self.runbzr(['commit', '-m', "more u's are always good"])
417
file('hello', 'wt').write('quuux')
418
# We can't merge when there are in-tree changes
419
self.runbzr('merge ../b', retcode=3)
420
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
421
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
423
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
424
self.runbzr('revert --no-backup')
425
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
426
self.runbzr('revert --no-backup')
427
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
428
self.runbzr('revert --no-backup')
429
self.runbzr('merge ../b -r last:1')
430
self.check_file_contents('goodbye', 'quux')
431
# Merging a branch pulls its revision into the tree
433
b = Branch.open('../b')
434
a.get_revision_xml(b.last_revision())
435
self.log('pending merges: %s', a.working_tree().pending_merges())
436
self.assertEquals(a.working_tree().pending_merges(),
438
self.runbzr('commit -m merged')
439
self.runbzr('merge ../b -r last:1')
440
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
442
def test_merge_with_missing_file(self):
443
"""Merge handles missing file conflicts"""
447
print >> file('sub/a.txt', 'wb'), "hello"
448
print >> file('b.txt', 'wb'), "hello"
449
print >> file('sub/c.txt', 'wb'), "hello"
452
self.runbzr(('commit', '-m', 'added a'))
453
self.runbzr('branch . ../b')
454
print >> file('sub/a.txt', 'ab'), "there"
455
print >> file('b.txt', 'ab'), "there"
456
print >> file('sub/c.txt', 'ab'), "there"
457
self.runbzr(('commit', '-m', 'Added there'))
458
os.unlink('sub/a.txt')
459
os.unlink('sub/c.txt')
462
self.runbzr(('commit', '-m', 'Removed a.txt'))
464
print >> file('sub/a.txt', 'ab'), "something"
465
print >> file('b.txt', 'ab'), "something"
466
print >> file('sub/c.txt', 'ab'), "something"
467
self.runbzr(('commit', '-m', 'Modified a.txt'))
468
self.runbzr('merge ../a/', retcode=1)
469
self.assert_(os.path.exists('sub/a.txt.THIS'))
470
self.assert_(os.path.exists('sub/a.txt.BASE'))
472
self.runbzr('merge ../b/', retcode=1)
473
self.assert_(os.path.exists('sub/a.txt.OTHER'))
474
self.assert_(os.path.exists('sub/a.txt.BASE'))
476
def test_inventory(self):
478
def output_equals(value, *args):
479
out = self.runbzr(['inventory'] + list(args), backtick=True)
480
self.assertEquals(out, value)
483
open('a', 'wb').write('hello\n')
489
output_equals('a\n', '--kind', 'file')
490
output_equals('b\n', '--kind', 'directory')
493
"""Test the abilities of 'bzr ls'"""
495
def bzrout(*args, **kwargs):
496
kwargs['backtick'] = True
497
return self.runbzr(*args, **kwargs)
499
def ls_equals(value, *args):
500
out = self.runbzr(['ls'] + list(args), backtick=True)
501
self.assertEquals(out, value)
504
open('a', 'wb').write('hello\n')
507
bzr('ls --verbose --null', retcode=3)
510
ls_equals('? a\n', '--verbose')
511
ls_equals('a\n', '--unknown')
512
ls_equals('', '--ignored')
513
ls_equals('', '--versioned')
514
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
515
ls_equals('', '--ignored', '--versioned')
516
ls_equals('a\0', '--null')
519
ls_equals('V a\n', '--verbose')
526
open('subdir/b', 'wb').write('b\n')
532
bzr('commit -m subdir')
540
, '--verbose', '--non-recursive')
542
# Check what happens in a sub-directory
554
, '--from-root', '--null')
557
, '--from-root', '--non-recursive')
561
# Check what happens when we supply a specific revision
562
ls_equals('a\n', '--revision', '1')
564
, '--verbose', '--revision', '1')
567
ls_equals('', '--revision', '1')
569
# Now try to do ignored files.
571
open('blah.py', 'wb').write('unknown\n')
572
open('blah.pyo', 'wb').write('ignored\n')
584
ls_equals('blah.pyo\n'
586
ls_equals('blah.py\n'
593
def test_pull_verbose(self):
594
"""Pull changes from one branch to another and watch the output."""
600
self.example_branch()
605
open('b', 'wb').write('else\n')
607
bzr(['commit', '-m', 'added b'])
610
out = bzr('pull --verbose ../b', backtick=True)
611
self.failIfEqual(out.find('Added Revisions:'), -1)
612
self.failIfEqual(out.find('message:\n added b'), -1)
613
self.failIfEqual(out.find('added b'), -1)
615
# Check that --overwrite --verbose prints out the removed entries
616
bzr('commit -m foo --unchanged')
618
bzr('commit -m baz --unchanged')
619
bzr('pull ../a', retcode=3)
620
out = bzr('pull --overwrite --verbose ../a', backtick=1)
622
remove_loc = out.find('Removed Revisions:')
623
self.failIfEqual(remove_loc, -1)
624
added_loc = out.find('Added Revisions:')
625
self.failIfEqual(added_loc, -1)
627
removed_message = out.find('message:\n baz')
628
self.failIfEqual(removed_message, -1)
629
self.failUnless(remove_loc < removed_message < added_loc)
631
added_message = out.find('message:\n foo')
632
self.failIfEqual(added_message, -1)
633
self.failUnless(added_loc < added_message)
635
def test_locations(self):
636
"""Using and remembering different locations"""
640
self.runbzr('commit -m unchanged --unchanged')
641
self.runbzr('pull', retcode=3)
642
self.runbzr('merge', retcode=3)
643
self.runbzr('branch . ../b')
646
self.runbzr('branch . ../c')
647
self.runbzr('pull ../c')
650
self.runbzr('pull ../b')
652
self.runbzr('pull ../c')
653
self.runbzr('branch ../c ../d')
654
shutil.rmtree('../c')
659
self.runbzr('pull', retcode=3)
660
self.runbzr('pull ../a --remember')
663
def test_add_reports(self):
664
"""add command prints the names of added files."""
665
b = Branch.initialize('.')
666
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
667
out = self.run_bzr_captured(['add'], retcode=0)[0]
668
# the ordering is not defined at the moment
669
results = sorted(out.rstrip('\n').split('\n'))
670
self.assertEquals(['added dir',
671
'added dir'+os.sep+'sub.txt',
675
def test_add_quiet_is(self):
676
"""add -q does not print the names of added files."""
677
b = Branch.initialize('.')
678
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
679
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
680
# the ordering is not defined at the moment
681
results = sorted(out.rstrip('\n').split('\n'))
682
self.assertEquals([''], results)
684
def test_add_in_unversioned(self):
685
"""Try to add a file in an unversioned directory.
687
"bzr add" should add the parent(s) as necessary.
689
from bzrlib.branch import Branch
690
Branch.initialize('.')
691
self.build_tree(['inertiatic/', 'inertiatic/esp'])
692
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
693
self.run_bzr('add', 'inertiatic/esp')
694
self.assertEquals(self.capture('unknowns'), '')
696
# Multiple unversioned parents
697
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
698
self.assertEquals(self.capture('unknowns'), 'veil\n')
699
self.run_bzr('add', 'veil/cerpin/taxt')
700
self.assertEquals(self.capture('unknowns'), '')
702
# Check whacky paths work
703
self.build_tree(['cicatriz/', 'cicatriz/esp'])
704
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
705
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
706
self.assertEquals(self.capture('unknowns'), '')
708
def test_add_in_versioned(self):
709
"""Try to add a file in a versioned directory.
711
"bzr add" should do this happily.
713
from bzrlib.branch import Branch
714
Branch.initialize('.')
715
self.build_tree(['inertiatic/', 'inertiatic/esp'])
716
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
717
self.run_bzr('add', '--no-recurse', 'inertiatic')
718
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
719
self.run_bzr('add', 'inertiatic/esp')
720
self.assertEquals(self.capture('unknowns'), '')
722
def test_subdir_add(self):
723
"""Add in subdirectory should add only things from there down"""
724
from bzrlib.branch import Branch
726
eq = self.assertEqual
730
b = Branch.initialize('.')
732
self.build_tree(['src/', 'README'])
734
eq(sorted(t.unknowns()),
737
self.run_bzr('add', 'src')
739
self.build_tree(['src/foo.c'])
744
self.assertEquals(self.capture('unknowns'), 'README\n')
745
eq(len(t.read_working_inventory()), 3)
749
self.assertEquals(self.capture('unknowns'), '')
750
self.run_bzr('check')
752
def test_unknown_command(self):
753
"""Handling of unknown command."""
754
out, err = self.run_bzr_captured(['fluffy-badger'],
756
self.assertEquals(out, '')
757
err.index('unknown command')
759
def create_conflicts(self):
760
"""Create a conflicted tree"""
763
file('hello', 'wb').write("hi world")
764
file('answer', 'wb').write("42")
767
self.runbzr('commit -m base')
768
self.runbzr('branch . ../other')
769
self.runbzr('branch . ../this')
771
file('hello', 'wb').write("Hello.")
772
file('answer', 'wb').write("Is anyone there?")
773
self.runbzr('commit -m other')
775
file('hello', 'wb').write("Hello, world")
776
self.runbzr('mv answer question')
777
file('question', 'wb').write("What do you get when you multiply six"
779
self.runbzr('commit -m this')
781
def test_remerge(self):
782
"""Remerge command works as expected"""
783
self.create_conflicts()
784
self.runbzr('merge ../other --show-base', retcode=1)
785
conflict_text = file('hello').read()
786
assert '|||||||' in conflict_text
787
assert 'hi world' in conflict_text
788
self.runbzr('remerge', retcode=1)
789
conflict_text = file('hello').read()
790
assert '|||||||' not in conflict_text
791
assert 'hi world' not in conflict_text
792
os.unlink('hello.OTHER')
793
self.runbzr('remerge hello --merge-type weave', retcode=1)
794
assert os.path.exists('hello.OTHER')
795
file_id = self.runbzr('file-id hello')
796
file_id = self.runbzr('file-id hello.THIS', retcode=3)
797
self.runbzr('remerge --merge-type weave', retcode=1)
798
assert os.path.exists('hello.OTHER')
799
assert not os.path.exists('hello.BASE')
800
assert '|||||||' not in conflict_text
801
assert 'hi world' not in conflict_text
802
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
803
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
804
self.runbzr('remerge . --show-base --reprocess', retcode=3)
805
self.runbzr('remerge hello --show-base', retcode=1)
806
self.runbzr('remerge hello --reprocess', retcode=1)
807
self.runbzr('resolve --all')
808
self.runbzr('commit -m done',)
809
self.runbzr('remerge', retcode=3)
812
def test_conflicts(self):
813
"""Handling of merge conflicts"""
814
self.create_conflicts()
815
self.runbzr('merge ../other --show-base', retcode=1)
816
conflict_text = file('hello').read()
817
self.assert_('<<<<<<<' in conflict_text)
818
self.assert_('>>>>>>>' in conflict_text)
819
self.assert_('=======' in conflict_text)
820
self.assert_('|||||||' in conflict_text)
821
self.assert_('hi world' in conflict_text)
822
self.runbzr('revert')
823
self.runbzr('resolve --all')
824
self.runbzr('merge ../other', retcode=1)
825
conflict_text = file('hello').read()
826
self.assert_('|||||||' not in conflict_text)
827
self.assert_('hi world' not in conflict_text)
828
result = self.runbzr('conflicts', backtick=1)
829
self.assertEquals(result, "hello\nquestion\n")
830
result = self.runbzr('status', backtick=1)
831
self.assert_("conflicts:\n hello\n question\n" in result, result)
832
self.runbzr('resolve hello')
833
result = self.runbzr('conflicts', backtick=1)
834
self.assertEquals(result, "question\n")
835
self.runbzr('commit -m conflicts', retcode=3)
836
self.runbzr('resolve --all')
837
result = self.runbzr('conflicts', backtick=1)
838
self.runbzr('commit -m conflicts')
839
self.assertEquals(result, "")
841
def test_resign(self):
842
"""Test re signing of data."""
844
oldstrategy = bzrlib.gpg.GPGStrategy
845
branch = Branch.initialize('.')
846
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
848
# monkey patch gpg signing mechanism
849
from bzrlib.testament import Testament
850
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
851
self.runbzr('re-sign -r revid:A')
852
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
853
branch.revision_store.get('A', 'sig').read())
855
bzrlib.gpg.GPGStrategy = oldstrategy
857
def test_resign_range(self):
859
oldstrategy = bzrlib.gpg.GPGStrategy
860
branch = Branch.initialize('.')
861
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
862
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
863
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
865
# monkey patch gpg signing mechanism
866
from bzrlib.testament import Testament
867
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
868
self.runbzr('re-sign -r 1..')
869
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
870
branch.revision_store.get('A', 'sig').read())
871
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
872
branch.revision_store.get('B', 'sig').read())
873
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
874
branch.revision_store.get('C', 'sig').read())
876
bzrlib.gpg.GPGStrategy = oldstrategy
879
# create a source branch
880
os.mkdir('my-branch')
881
os.chdir('my-branch')
882
self.example_branch()
884
# with no push target, fail
885
self.runbzr('push', retcode=3)
886
# with an explicit target work
887
self.runbzr('push ../output-branch')
888
# with an implicit target work
891
self.runbzr('missing ../output-branch')
892
# advance this branch
893
self.runbzr('commit --unchanged -m unchanged')
895
os.chdir('../output-branch')
896
# There is no longer a difference as long as we have
897
# access to the working tree
900
# But we should be missing a revision
901
self.runbzr('missing ../my-branch', retcode=1)
903
# diverge the branches
904
self.runbzr('commit --unchanged -m unchanged')
905
os.chdir('../my-branch')
907
self.runbzr('push', retcode=3)
908
# and there are difference
909
self.runbzr('missing ../output-branch', retcode=1)
910
self.runbzr('missing --verbose ../output-branch', retcode=1)
911
# but we can force a push
912
self.runbzr('push --overwrite')
914
self.runbzr('missing ../output-branch')
916
# pushing to a new dir with no parent should fail
917
self.runbzr('push ../missing/new-branch', retcode=3)
918
# unless we provide --create-prefix
919
self.runbzr('push --create-prefix ../missing/new-branch')
921
self.runbzr('missing ../missing/new-branch')
923
def test_external_command(self):
924
"""test that external commands can be run by setting the path"""
925
cmd_name = 'test-command'
926
output = 'Hello from test-command'
927
if sys.platform == 'win32':
933
oldpath = os.environ.get('BZRPATH', None)
938
if os.environ.has_key('BZRPATH'):
939
del os.environ['BZRPATH']
941
f = file(cmd_name, 'wb')
942
if sys.platform == 'win32':
943
f.write('@echo off\n')
945
f.write('#!/bin/sh\n')
946
f.write('echo Hello from test-command')
948
os.chmod(cmd_name, 0755)
950
# It should not find the command in the local
951
# directory by default, since it is not in my path
952
bzr(cmd_name, retcode=3)
954
# Now put it into my path
955
os.environ['BZRPATH'] = '.'
958
# The test suite does not capture stdout for external commands
959
# this is because you have to have a real file object
960
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
961
# (just replacing sys.stdout does not change a spawned objects stdout)
962
#self.assertEquals(bzr(cmd_name), output)
964
# Make sure empty path elements are ignored
965
os.environ['BZRPATH'] = os.pathsep
967
bzr(cmd_name, retcode=3)
971
os.environ['BZRPATH'] = oldpath
974
def listdir_sorted(dir):
980
181
class OldTests(ExternalBase):
981
"""old tests moved from ./testbzr."""
182
# old tests moved from ./testbzr
983
183
def test_bzr(self):
984
184
from os import chdir, mkdir
985
185
from os.path import exists
987
188
runbzr = self.runbzr
988
capture = self.capture
189
backtick = self.backtick
989
190
progress = self.log
991
192
progress("basic branch creation")
1002
203
f.write('hello world!\n')
1005
self.assertEquals(capture('unknowns'), 'test.txt\n')
1007
out = capture("status")
1008
self.assertEquals(out, 'unknown:\n test.txt\n')
1010
out = capture("status --all")
1011
self.assertEquals(out, "unknown:\n test.txt\n")
1013
out = capture("status test.txt --all")
1014
self.assertEquals(out, "unknown:\n test.txt\n")
206
out = backtick("bzr unknowns")
207
self.assertEquals(out, 'test.txt\n')
209
out = backtick("bzr status")
210
assert out == 'unknown:\n test.txt\n'
212
out = backtick("bzr status --all")
213
assert out == "unknown:\n test.txt\n"
215
out = backtick("bzr status test.txt --all")
216
assert out == "unknown:\n test.txt\n"
1016
218
f = file('test2.txt', 'wt')
1017
219
f.write('goodbye cruel world...\n')
1020
out = capture("status test.txt")
1021
self.assertEquals(out, "unknown:\n test.txt\n")
222
out = backtick("bzr status test.txt")
223
assert out == "unknown:\n test.txt\n"
1023
out = capture("status")
1024
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
225
out = backtick("bzr status")
226
assert out == ("unknown:\n"
1026
230
os.unlink('test2.txt')
1028
232
progress("command aliases")
1029
out = capture("st --all")
1030
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
233
out = backtick("bzr st --all")
234
assert out == ("unknown:\n"
1032
out = capture("stat")
1033
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
237
out = backtick("bzr stat")
238
assert out == ("unknown:\n"
1035
241
progress("command help")
1036
242
runbzr("help st")
1038
244
runbzr("help commands")
1039
runbzr("help slartibartfast", 3)
245
runbzr("help slartibartfast", 1)
1041
out = capture("help ci")
247
out = backtick("bzr help ci")
1042
248
out.index('aliases: ')
1044
250
progress("can't rename unversioned file")
1045
runbzr("rename test.txt new-test.txt", 3)
251
runbzr("rename test.txt new-test.txt", 1)
1047
253
progress("adding a file")
1049
255
runbzr("add test.txt")
1050
self.assertEquals(capture("unknowns"), '')
1051
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
256
assert backtick("bzr unknowns") == ''
257
assert backtick("bzr status --all") == ("added:\n"
1053
260
progress("rename newly-added file")
1054
261
runbzr("rename test.txt hello.txt")
1055
self.assert_(os.path.exists("hello.txt"))
1056
self.assert_(not os.path.exists("test.txt"))
262
assert os.path.exists("hello.txt")
263
assert not os.path.exists("test.txt")
1058
self.assertEquals(capture("revno"), '0\n')
265
assert backtick("bzr revno") == '0\n'
1060
267
progress("add first revision")
1061
268
runbzr(['commit', '-m', 'add first revision'])
1063
270
progress("more complex renames")
1064
271
os.mkdir("sub1")
1065
runbzr("rename hello.txt sub1", 3)
1066
runbzr("rename hello.txt sub1/hello.txt", 3)
1067
runbzr("move hello.txt sub1", 3)
272
runbzr("rename hello.txt sub1", 1)
273
runbzr("rename hello.txt sub1/hello.txt", 1)
274
runbzr("move hello.txt sub1", 1)
1069
276
runbzr("add sub1")
1070
277
runbzr("rename sub1 sub2")
1071
278
runbzr("move hello.txt sub2")
1072
self.assertEqual(capture("relpath sub2/hello.txt"),
1073
os.path.join("sub2", "hello.txt\n"))
279
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1075
self.assert_(exists("sub2"))
1076
self.assert_(exists("sub2/hello.txt"))
1077
self.assert_(not exists("sub1"))
1078
self.assert_(not exists("hello.txt"))
281
assert exists("sub2")
282
assert exists("sub2/hello.txt")
283
assert not exists("sub1")
284
assert not exists("hello.txt")
1080
286
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1083
289
runbzr('add sub1')
1084
290
runbzr('move sub2/hello.txt sub1')
1085
self.assert_(not exists('sub2/hello.txt'))
1086
self.assert_(exists('sub1/hello.txt'))
291
assert not exists('sub2/hello.txt')
292
assert exists('sub1/hello.txt')
1087
293
runbzr('move sub2 sub1')
1088
self.assert_(not exists('sub2'))
1089
self.assert_(exists('sub1/sub2'))
294
assert not exists('sub2')
295
assert exists('sub1/sub2')
1091
297
runbzr(['commit', '-m', 'rename nested subdirectories'])
1093
299
chdir('sub1/sub2')
1094
self.assertEquals(capture('root')[:-1],
300
self.assertEquals(backtick('bzr root')[:-1],
1095
301
os.path.join(self.test_dir, 'branch1'))
1096
302
runbzr('move ../hello.txt .')
1097
self.assert_(exists('./hello.txt'))
1098
self.assertEquals(capture('relpath hello.txt'),
1099
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1100
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
303
assert exists('./hello.txt')
304
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
305
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1101
306
runbzr(['commit', '-m', 'move to parent directory'])
1103
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
308
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1105
310
runbzr('move sub2/hello.txt .')
1106
self.assert_(exists('hello.txt'))
311
assert exists('hello.txt')
1108
313
f = file('hello.txt', 'wt')
1109
314
f.write('some nice new content\n')
1112
317
f = file('msg.tmp', 'wt')
1113
f.write('this is my new commit\nand it has multiple lines, for fun')
318
f.write('this is my new commit\n')
1116
321
runbzr('commit -F msg.tmp')
1118
self.assertEquals(capture('revno'), '5\n')
323
assert backtick('bzr revno') == '5\n'
1119
324
runbzr('export -r 5 export-5.tmp')
1120
325
runbzr('export export.tmp')
1123
328
runbzr('log -v')
1124
329
runbzr('log -v --forward')
1125
runbzr('log -m', retcode=3)
1126
log_out = capture('log -m commit')
1127
self.assert_("this is my new commit\n and" in log_out)
1128
self.assert_("rename nested" not in log_out)
1129
self.assert_('revision-id' not in log_out)
1130
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1132
log_out = capture('log --line')
1133
for line in log_out.splitlines():
1134
self.assert_(len(line) <= 79, len(line))
1135
self.assert_("this is my new commit and" in log_out)
330
runbzr('log -m', retcode=1)
331
log_out = backtick('bzr log -m commit')
332
assert "this is my new commit" in log_out
333
assert "rename nested" not in log_out
334
assert 'revision-id' not in log_out
335
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1138
338
progress("file with spaces in name")
1139
339
mkdir('sub directory')
1140
340
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1142
runbzr('diff', retcode=1)
1143
343
runbzr('commit -m add-spaces')
1152
progress("symlinks")
1156
os.symlink("NOWHERE1", "link1")
1158
self.assertEquals(self.capture('unknowns'), '')
1159
runbzr(['commit', '-m', '1: added symlink link1'])
1163
self.assertEquals(self.capture('unknowns'), '')
1164
os.symlink("NOWHERE2", "d1/link2")
1165
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1166
# is d1/link2 found when adding d1
1168
self.assertEquals(self.capture('unknowns'), '')
1169
os.symlink("NOWHERE3", "d1/link3")
1170
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1171
runbzr(['commit', '-m', '2: added dir, symlink'])
1173
runbzr('rename d1 d2')
1174
runbzr('move d2/link2 .')
1175
runbzr('move link1 d2')
1176
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1177
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1178
runbzr('add d2/link3')
1179
runbzr('diff', retcode=1)
1180
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1183
os.symlink("TARGET 2", "link2")
1184
os.unlink("d2/link1")
1185
os.symlink("TARGET 1", "d2/link1")
1186
runbzr('diff', retcode=1)
1187
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1188
runbzr(['commit', '-m', '4: retarget of two links'])
1190
runbzr('remove d2/link1')
1191
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1192
runbzr(['commit', '-m', '5: remove d2/link1'])
1193
# try with the rm alias
1194
runbzr('add d2/link1')
1195
runbzr(['commit', '-m', '6: add d2/link1'])
1196
runbzr('rm d2/link1')
1197
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1198
runbzr(['commit', '-m', '7: remove d2/link1'])
1202
runbzr('rename d2/link3 d1/link3new')
1203
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1204
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1208
runbzr(['export', '-r', '1', 'exp1.tmp'])
1210
self.assertEquals(listdir_sorted("."), [ "link1" ])
1211
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1214
runbzr(['export', '-r', '2', 'exp2.tmp'])
1216
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1219
runbzr(['export', '-r', '3', 'exp3.tmp'])
1221
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1222
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1223
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1224
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1227
runbzr(['export', '-r', '4', 'exp4.tmp'])
1229
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1230
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1231
self.assertEquals(os.readlink("link2") , "TARGET 2")
1232
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1235
runbzr(['export', '-r', '5', 'exp5.tmp'])
1237
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1238
self.assert_(os.path.islink("link2"))
1239
self.assert_(listdir_sorted("d2")== [ "link3" ])
1242
runbzr(['export', '-r', '8', 'exp6.tmp'])
1244
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1245
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1246
self.assertEquals(listdir_sorted("d2"), [])
1247
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1250
progress("skipping symlink tests")
1253
class HttpTests(TestCaseWithWebserver):
1254
"""Test bzr ui commands against remote branches."""
1256
def test_branch(self):
1258
branch = Branch.initialize('from')
1259
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1260
url = self.get_remote_url('from')
1261
self.run_bzr('branch', url, 'to')
1262
branch = Branch.open('to')
1263
self.assertEqual(1, len(branch.revision_history()))
1266
self.build_tree(['branch/', 'branch/file'])
1267
branch = Branch.initialize('branch')
1268
branch.working_tree().add(['file'])
1269
branch.working_tree().commit('add file', rev_id='A')
1270
url = self.get_remote_url('branch/file')
1271
output = self.capture('log %s' % url)
1272
self.assertEqual(8, len(output.split('\n')))
1274
def test_check(self):
1275
self.build_tree(['branch/', 'branch/file'])
1276
branch = Branch.initialize('branch')
1277
branch.working_tree().add(['file'])
1278
branch.working_tree().commit('add file', rev_id='A')
1279
url = self.get_remote_url('branch/')
1280
self.run_bzr('check', url)
353
def example_branch(test):
356
file('hello', 'wt').write('foo')
357
test.runbzr('add hello')
358
test.runbzr('commit -m setup hello')
360
file('goodbye', 'wt').write('baz')
361
test.runbzr('add goodbye')
362
test.runbzr('commit -m setup goodbye')
365
class RevertCommand(ExternalBase):
368
file('hello', 'wt').write('bar')
369
file('goodbye', 'wt').write('qux')
370
self.runbzr('revert hello')
371
self.check_file_contents('hello', 'foo')
372
self.check_file_contents('goodbye', 'qux')
373
self.runbzr('revert')
374
self.check_file_contents('goodbye', 'baz')
377
class MergeCommand(ExternalBase):
379
from bzrlib.branch import Branch
385
self.runbzr('branch a b')
387
file('goodbye', 'wt').write('quux')
388
self.runbzr(['commit', '-m', "more u's are always good"])
391
file('hello', 'wt').write('quuux')
392
# We can't merge when there are in-tree changes
393
self.runbzr('merge ../b', retcode=1)
394
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
395
self.runbzr('merge ../b')
396
self.check_file_contents('goodbye', 'quux')
397
# Merging a branch pulls its revision into the tree
400
a.get_revision_xml(b.last_patch())
401
print "Pending: %s" % a.pending_merges()
402
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
403
# % (a.pending_merges(), b.last_patch())