90
72
f = file('.bzr/email', 'wt')
91
73
f.write('Branch Identity <branch@identi.ty>')
93
bzr_email = os.environ.get('BZREMAIL')
94
if bzr_email is not None:
95
del os.environ['BZREMAIL']
96
75
whoami = self.runbzr("whoami",backtick=True)
97
76
whoami_email = self.runbzr("whoami --email",backtick=True)
98
77
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
99
78
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
100
# Verify that the environment variable overrides the value
102
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
103
whoami = self.runbzr("whoami",backtick=True)
104
whoami_email = self.runbzr("whoami --email",backtick=True)
105
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
106
self.assertTrue(whoami_email.startswith('other@environ.ment'))
107
if bzr_email is not None:
108
os.environ['BZREMAIL'] = bzr_email
110
def test_nick_command(self):
111
"""bzr nick for viewing, setting nicknames"""
115
nick = self.runbzr("nick",backtick=True)
116
self.assertEqual(nick, 'me.dev\n')
117
nick = self.runbzr("nick moo")
118
nick = self.runbzr("nick",backtick=True)
119
self.assertEqual(nick, 'moo\n')
122
80
def test_invalid_commands(self):
123
self.runbzr("pants", retcode=3)
124
self.runbzr("--pants off", retcode=3)
125
self.runbzr("diff --message foo", retcode=3)
81
self.runbzr("pants", retcode=1)
82
self.runbzr("--pants off", retcode=1)
83
self.runbzr("diff --message foo", retcode=1)
127
85
def test_empty_commit(self):
128
86
self.runbzr("init")
129
87
self.build_tree(['hello.txt'])
130
self.runbzr("commit -m empty", retcode=3)
88
self.runbzr("commit -m empty", retcode=1)
131
89
self.runbzr("add hello.txt")
132
self.runbzr("commit -m added")
134
def test_empty_commit_message(self):
136
file('foo.c', 'wt').write('int main() {}')
137
self.runbzr(['add', 'foo.c'])
138
self.runbzr(["commit", "-m", ""] , retcode=3)
140
def test_remove_deleted(self):
142
self.build_tree(['a'])
143
self.runbzr(['add', 'a'])
144
self.runbzr(['commit', '-m', 'added a'])
146
self.runbzr(['remove', 'a'])
148
def test_other_branch_commit(self):
149
# this branch is to ensure consistent behaviour, whether we're run
150
# inside a branch, or not.
151
os.mkdir('empty_branch')
152
os.chdir('empty_branch')
157
file('foo.c', 'wt').write('int main() {}')
158
file('bar.c', 'wt').write('int main() {}')
160
self.runbzr(['add', 'branch/foo.c'])
161
self.runbzr(['add', 'branch'])
162
# can't commit files in different trees; sane error
163
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
164
self.runbzr('commit -m newstuff branch/foo.c')
165
self.runbzr('commit -m newstuff branch')
166
self.runbzr('commit -m newstuff branch', retcode=3)
90
self.runbzr("commit -m added")
168
92
def test_ignore_patterns(self):
170
self.assertEquals(self.capture('unknowns'), '')
93
from bzrlib.branch import Branch
95
b = Branch('.', init=True)
96
self.assertEquals(list(b.unknowns()), [])
172
98
file('foo.tmp', 'wt').write('tmp files are ignored')
173
self.assertEquals(self.capture('unknowns'), '')
99
self.assertEquals(list(b.unknowns()), [])
100
assert self.backtick('bzr unknowns') == ''
175
102
file('foo.c', 'wt').write('int main() {}')
176
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
103
self.assertEquals(list(b.unknowns()), ['foo.c'])
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
178
106
self.runbzr(['add', 'foo.c'])
179
self.assertEquals(self.capture('unknowns'), '')
107
assert self.backtick('bzr unknowns') == ''
181
109
# 'ignore' works when creating the .bzignore file
182
110
file('foo.blah', 'wt').write('blah')
183
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
111
self.assertEquals(list(b.unknowns()), ['foo.blah'])
184
112
self.runbzr('ignore *.blah')
185
self.assertEquals(self.capture('unknowns'), '')
186
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
113
self.assertEquals(list(b.unknowns()), [])
114
assert file('.bzrignore', 'rb').read() == '*.blah\n'
188
116
# 'ignore' works when then .bzrignore file already exists
189
117
file('garh', 'wt').write('garh')
190
self.assertEquals(self.capture('unknowns'), 'garh\n')
118
self.assertEquals(list(b.unknowns()), ['garh'])
119
assert self.backtick('bzr unknowns') == 'garh\n'
191
120
self.runbzr('ignore garh')
192
self.assertEquals(self.capture('unknowns'), '')
193
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
121
self.assertEquals(list(b.unknowns()), [])
122
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
195
124
def test_revert(self):
196
126
self.runbzr('init')
198
128
file('hello', 'wt').write('foo')
293
182
test.runbzr('add goodbye')
294
183
test.runbzr('commit -m setup goodbye')
296
def test_export(self):
299
self.example_branch()
300
self.runbzr('export ../latest')
301
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
302
self.runbzr('export ../first -r 1')
303
self.assert_(not os.path.exists('../first/goodbye'))
304
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
305
self.runbzr('export ../first.gz -r 1')
306
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
307
self.runbzr('export ../first.bz2 -r 1')
308
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
310
from tarfile import TarFile
311
self.runbzr('export ../first.tar -r 1')
312
self.assert_(os.path.isfile('../first.tar'))
313
tf = TarFile('../first.tar')
314
self.assert_('first/hello' in tf.getnames(), tf.getnames())
315
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
316
self.runbzr('export ../first.tar.gz -r 1')
317
self.assert_(os.path.isfile('../first.tar.gz'))
318
self.runbzr('export ../first.tbz2 -r 1')
319
self.assert_(os.path.isfile('../first.tbz2'))
320
self.runbzr('export ../first.tar.bz2 -r 1')
321
self.assert_(os.path.isfile('../first.tar.bz2'))
322
self.runbzr('export ../first.tar.tbz2 -r 1')
323
self.assert_(os.path.isfile('../first.tar.tbz2'))
325
from bz2 import BZ2File
326
tf = TarFile('../first.tar.tbz2',
327
fileobj=BZ2File('../first.tar.tbz2', 'r'))
328
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
329
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
330
self.runbzr('export ../first2.tar -r 1 --root pizza')
331
tf = TarFile('../first2.tar')
332
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
334
from zipfile import ZipFile
335
self.runbzr('export ../first.zip -r 1')
336
self.failUnlessExists('../first.zip')
337
zf = ZipFile('../first.zip')
338
self.assert_('first/hello' in zf.namelist(), zf.namelist())
339
self.assertEqual(zf.read('first/hello'), 'foo')
341
self.runbzr('export ../first2.zip -r 1 --root pizza')
342
zf = ZipFile('../first2.zip')
343
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
345
self.runbzr('export ../first-zip --format=zip -r 1')
346
zf = ZipFile('../first-zip')
347
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
349
def test_branch(self):
350
"""Branch from one branch to another."""
353
self.example_branch()
355
self.runbzr('branch a b')
356
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
357
self.runbzr('branch a c -r 1')
359
self.runbzr('commit -m foo --unchanged')
362
def test_branch_basis(self):
363
# ensure that basis really does grab from the basis by having incomplete source
364
tree = self.make_branch_and_tree('commit_tree')
365
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
367
tree.commit('revision 1', rev_id='1')
368
source = self.make_branch_and_tree('source')
369
# this gives us an incomplete repository
370
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
371
tree.commit('revision 2', rev_id='2', allow_pointless=True)
372
tree.bzrdir.open_branch().copy_content_into(source.branch)
373
tree.copy_content_into(source)
374
self.assertFalse(source.branch.repository.has_revision('2'))
376
self.runbzr('branch source target --basis commit_tree')
377
target = bzrdir.BzrDir.open('target')
378
self.assertEqual('2', target.open_branch().last_revision())
379
self.assertEqual('2', target.open_workingtree().last_revision())
380
self.assertTrue(target.open_branch().repository.has_revision('2'))
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')
382
195
def test_merge(self):
383
196
from bzrlib.branch import Branch
387
202
self.example_branch()
389
204
self.runbzr('branch a b')
395
210
file('hello', 'wt').write('quuux')
396
211
# We can't merge when there are in-tree changes
397
self.runbzr('merge ../b', retcode=3)
212
self.runbzr('merge ../b', retcode=1)
398
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
399
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
401
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
402
self.runbzr('revert --no-backup')
403
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
404
self.runbzr('revert --no-backup')
405
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
406
self.runbzr('revert --no-backup')
407
self.runbzr('merge ../b -r last:1')
214
self.runbzr('merge ../b')
408
215
self.check_file_contents('goodbye', 'quux')
409
216
# Merging a branch pulls its revision into the tree
410
a = WorkingTree.open('.')
411
b = Branch.open('../b')
412
a.branch.repository.get_revision_xml(b.last_revision())
219
a.get_revision_xml(b.last_revision())
413
221
self.log('pending merges: %s', a.pending_merges())
414
self.assertEquals(a.pending_merges(),
416
self.runbzr('commit -m merged')
417
self.runbzr('merge ../b -r last:1')
418
self.assertEqual(a.pending_merges(), [])
420
def test_merge_with_missing_file(self):
421
"""Merge handles missing file conflicts"""
425
print >> file('sub/a.txt', 'wb'), "hello"
426
print >> file('b.txt', 'wb'), "hello"
427
print >> file('sub/c.txt', 'wb'), "hello"
430
self.runbzr(('commit', '-m', 'added a'))
431
self.runbzr('branch . ../b')
432
print >> file('sub/a.txt', 'ab'), "there"
433
print >> file('b.txt', 'ab'), "there"
434
print >> file('sub/c.txt', 'ab'), "there"
435
self.runbzr(('commit', '-m', 'Added there'))
436
os.unlink('sub/a.txt')
437
os.unlink('sub/c.txt')
440
self.runbzr(('commit', '-m', 'Removed a.txt'))
442
print >> file('sub/a.txt', 'ab'), "something"
443
print >> file('b.txt', 'ab'), "something"
444
print >> file('sub/c.txt', 'ab'), "something"
445
self.runbzr(('commit', '-m', 'Modified a.txt'))
446
self.runbzr('merge ../a/', retcode=1)
447
self.assert_(os.path.exists('sub/a.txt.THIS'))
448
self.assert_(os.path.exists('sub/a.txt.BASE'))
450
self.runbzr('merge ../b/', retcode=1)
451
self.assert_(os.path.exists('sub/a.txt.OTHER'))
452
self.assert_(os.path.exists('sub/a.txt.BASE'))
454
def test_inventory(self):
456
def output_equals(value, *args):
457
out = self.runbzr(['inventory'] + list(args), backtick=True)
458
self.assertEquals(out, value)
461
open('a', 'wb').write('hello\n')
467
output_equals('a\n', '--kind', 'file')
468
output_equals('b\n', '--kind', 'directory')
471
"""Test the abilities of 'bzr ls'"""
473
def bzrout(*args, **kwargs):
474
kwargs['backtick'] = True
475
return self.runbzr(*args, **kwargs)
477
def ls_equals(value, *args):
478
out = self.runbzr(['ls'] + list(args), backtick=True)
479
self.assertEquals(out, value)
482
open('a', 'wb').write('hello\n')
485
bzr('ls --verbose --null', retcode=3)
488
ls_equals('? a\n', '--verbose')
489
ls_equals('a\n', '--unknown')
490
ls_equals('', '--ignored')
491
ls_equals('', '--versioned')
492
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
493
ls_equals('', '--ignored', '--versioned')
494
ls_equals('a\0', '--null')
497
ls_equals('V a\n', '--verbose')
504
open('subdir/b', 'wb').write('b\n')
510
bzr('commit -m subdir')
518
, '--verbose', '--non-recursive')
520
# Check what happens in a sub-directory
532
, '--from-root', '--null')
535
, '--from-root', '--non-recursive')
539
# Check what happens when we supply a specific revision
540
ls_equals('a\n', '--revision', '1')
542
, '--verbose', '--revision', '1')
545
ls_equals('', '--revision', '1')
547
# Now try to do ignored files.
549
open('blah.py', 'wb').write('unknown\n')
550
open('blah.pyo', 'wb').write('ignored\n')
562
ls_equals('blah.pyo\n'
564
ls_equals('blah.py\n'
573
file("myfile", "wb").write("My contents\n")
575
self.runbzr('commit -m myfile')
576
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
578
def test_pull_verbose(self):
579
"""Pull changes from one branch to another and watch the output."""
585
self.example_branch()
590
open('b', 'wb').write('else\n')
592
bzr(['commit', '-m', 'added b'])
595
out = bzr('pull --verbose ../b', backtick=True)
596
self.failIfEqual(out.find('Added Revisions:'), -1)
597
self.failIfEqual(out.find('message:\n added b'), -1)
598
self.failIfEqual(out.find('added b'), -1)
600
# Check that --overwrite --verbose prints out the removed entries
601
bzr('commit -m foo --unchanged')
603
bzr('commit -m baz --unchanged')
604
bzr('pull ../a', retcode=3)
605
out = bzr('pull --overwrite --verbose ../a', backtick=1)
607
remove_loc = out.find('Removed Revisions:')
608
self.failIfEqual(remove_loc, -1)
609
added_loc = out.find('Added Revisions:')
610
self.failIfEqual(added_loc, -1)
612
removed_message = out.find('message:\n baz')
613
self.failIfEqual(removed_message, -1)
614
self.failUnless(remove_loc < removed_message < added_loc)
616
added_message = out.find('message:\n foo')
617
self.failIfEqual(added_message, -1)
618
self.failUnless(added_loc < added_message)
620
def test_locations(self):
621
"""Using and remembering different locations"""
625
self.runbzr('commit -m unchanged --unchanged')
626
self.runbzr('pull', retcode=3)
627
self.runbzr('merge', retcode=3)
628
self.runbzr('branch . ../b')
631
self.runbzr('branch . ../c')
632
self.runbzr('pull ../c')
635
self.runbzr('pull ../b')
637
self.runbzr('pull ../c')
638
self.runbzr('branch ../c ../d')
639
shutil.rmtree('../c')
644
self.runbzr('pull', retcode=3)
645
self.runbzr('pull ../a --remember')
222
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
223
# % (a.pending_merges(), b.last_revision())
648
226
def test_add_reports(self):
649
227
"""add command prints the names of added files."""
651
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
652
out = self.run_bzr_captured(['add'], retcode=0)[0]
228
b = Branch('.', init=True)
229
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
from cStringIO import StringIO
234
ret = self.apply_redirected(None, out, None,
237
self.assertEquals(ret, 0)
653
239
# the ordering is not defined at the moment
654
results = sorted(out.rstrip('\n').split('\n'))
655
self.assertEquals(['If you wish to add some of these files, please'\
656
' add them by name.',
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
self.assertEquals(['added dir',
658
242
'added dir/sub.txt',
660
'ignored 1 file(s) matching "CVS"'],
662
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
663
results = sorted(out.rstrip('\n').split('\n'))
664
self.assertEquals(['If you wish to add some of these files, please'\
665
' add them by name.',
666
'ignored CVS matching "CVS"'],
669
def test_add_quiet_is(self):
670
"""add -q does not print the names of added files."""
672
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
673
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
674
# the ordering is not defined at the moment
675
results = sorted(out.rstrip('\n').split('\n'))
676
self.assertEquals([''], results)
678
def test_add_in_unversioned(self):
679
"""Try to add a file in an unversioned directory.
681
"bzr add" should add the parent(s) as necessary.
684
self.build_tree(['inertiatic/', 'inertiatic/esp'])
685
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
686
self.run_bzr('add', 'inertiatic/esp')
687
self.assertEquals(self.capture('unknowns'), '')
689
# Multiple unversioned parents
690
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
691
self.assertEquals(self.capture('unknowns'), 'veil\n')
692
self.run_bzr('add', 'veil/cerpin/taxt')
693
self.assertEquals(self.capture('unknowns'), '')
695
# Check whacky paths work
696
self.build_tree(['cicatriz/', 'cicatriz/esp'])
697
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
698
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
699
self.assertEquals(self.capture('unknowns'), '')
701
def test_add_in_versioned(self):
702
"""Try to add a file in a versioned directory.
704
"bzr add" should do this happily.
707
self.build_tree(['inertiatic/', 'inertiatic/esp'])
708
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
709
self.run_bzr('add', '--no-recurse', 'inertiatic')
710
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
711
self.run_bzr('add', 'inertiatic/esp')
712
self.assertEquals(self.capture('unknowns'), '')
714
def test_subdir_add(self):
715
"""Add in subdirectory should add only things from there down"""
716
from bzrlib.workingtree import WorkingTree
718
eq = self.assertEqual
722
t = self.make_branch_and_tree('.')
724
self.build_tree(['src/', 'README'])
726
eq(sorted(t.unknowns()),
729
self.run_bzr('add', 'src')
731
self.build_tree(['src/foo.c'])
736
self.assertEquals(self.capture('unknowns'), 'README\n')
737
eq(len(t.read_working_inventory()), 3)
741
self.assertEquals(self.capture('unknowns'), '')
742
self.run_bzr('check')
744
def test_unknown_command(self):
745
"""Handling of unknown command."""
746
out, err = self.run_bzr_captured(['fluffy-badger'],
748
self.assertEquals(out, '')
749
err.index('unknown command')
751
def create_conflicts(self):
752
"""Create a conflicted tree"""
755
file('hello', 'wb').write("hi world")
756
file('answer', 'wb').write("42")
759
self.runbzr('commit -m base')
760
self.runbzr('branch . ../other')
761
self.runbzr('branch . ../this')
763
file('hello', 'wb').write("Hello.")
764
file('answer', 'wb').write("Is anyone there?")
765
self.runbzr('commit -m other')
767
file('hello', 'wb').write("Hello, world")
768
self.runbzr('mv answer question')
769
file('question', 'wb').write("What do you get when you multiply six"
771
self.runbzr('commit -m this')
773
def test_remerge(self):
774
"""Remerge command works as expected"""
775
self.create_conflicts()
776
self.runbzr('merge ../other --show-base', retcode=1)
777
conflict_text = file('hello').read()
778
assert '|||||||' in conflict_text
779
assert 'hi world' in conflict_text
780
self.runbzr('remerge', retcode=1)
781
conflict_text = file('hello').read()
782
assert '|||||||' not in conflict_text
783
assert 'hi world' not in conflict_text
784
os.unlink('hello.OTHER')
785
self.runbzr('remerge hello --merge-type weave', retcode=1)
786
assert os.path.exists('hello.OTHER')
787
file_id = self.runbzr('file-id hello')
788
file_id = self.runbzr('file-id hello.THIS', retcode=3)
789
self.runbzr('remerge --merge-type weave', retcode=1)
790
assert os.path.exists('hello.OTHER')
791
assert not os.path.exists('hello.BASE')
792
assert '|||||||' not in conflict_text
793
assert 'hi world' not in conflict_text
794
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
795
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
796
self.runbzr('remerge . --show-base --reprocess', retcode=3)
797
self.runbzr('remerge hello --show-base', retcode=1)
798
self.runbzr('remerge hello --reprocess', retcode=1)
799
self.runbzr('resolve --all')
800
self.runbzr('commit -m done',)
801
self.runbzr('remerge', retcode=3)
803
def test_status(self):
807
self.runbzr('commit --unchanged --message f')
808
self.runbzr('branch . ../branch2')
809
self.runbzr('branch . ../branch3')
810
self.runbzr('commit --unchanged --message peter')
811
os.chdir('../branch2')
812
self.runbzr('merge ../branch1')
813
self.runbzr('commit --unchanged --message pumpkin')
814
os.chdir('../branch3')
815
self.runbzr('merge ../branch2')
816
message = self.capture('status')
819
def test_conflicts(self):
820
"""Handling of merge conflicts"""
821
self.create_conflicts()
822
self.runbzr('merge ../other --show-base', retcode=1)
823
conflict_text = file('hello').read()
824
self.assert_('<<<<<<<' in conflict_text)
825
self.assert_('>>>>>>>' in conflict_text)
826
self.assert_('=======' in conflict_text)
827
self.assert_('|||||||' in conflict_text)
828
self.assert_('hi world' in conflict_text)
829
self.runbzr('revert')
830
self.runbzr('resolve --all')
831
self.runbzr('merge ../other', retcode=1)
832
conflict_text = file('hello').read()
833
self.assert_('|||||||' not in conflict_text)
834
self.assert_('hi world' not in conflict_text)
835
result = self.runbzr('conflicts', backtick=1)
836
self.assertEquals(result, "hello\nquestion\n")
837
result = self.runbzr('status', backtick=1)
838
self.assert_("conflicts:\n hello\n question\n" in result, result)
839
self.runbzr('resolve hello')
840
result = self.runbzr('conflicts', backtick=1)
841
self.assertEquals(result, "question\n")
842
self.runbzr('commit -m conflicts', retcode=3)
843
self.runbzr('resolve --all')
844
result = self.runbzr('conflicts', backtick=1)
845
self.runbzr('commit -m conflicts')
846
self.assertEquals(result, "")
848
def test_resign(self):
849
"""Test re signing of data."""
851
oldstrategy = bzrlib.gpg.GPGStrategy
852
wt = self.make_branch_and_tree('.')
854
wt.commit("base", allow_pointless=True, rev_id='A')
856
# monkey patch gpg signing mechanism
857
from bzrlib.testament import Testament
858
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
859
self.runbzr('re-sign -r revid:A')
860
self.assertEqual(Testament.from_revision(branch.repository,
861
'A').as_short_text(),
862
branch.repository.revision_store.get('A',
865
bzrlib.gpg.GPGStrategy = oldstrategy
867
def test_resign_range(self):
869
oldstrategy = bzrlib.gpg.GPGStrategy
870
wt = self.make_branch_and_tree('.')
872
wt.commit("base", allow_pointless=True, rev_id='A')
873
wt.commit("base", allow_pointless=True, rev_id='B')
874
wt.commit("base", allow_pointless=True, rev_id='C')
876
# monkey patch gpg signing mechanism
877
from bzrlib.testament import Testament
878
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
879
self.runbzr('re-sign -r 1..')
881
Testament.from_revision(branch.repository,'A').as_short_text(),
882
branch.repository.revision_store.get('A', 'sig').read())
884
Testament.from_revision(branch.repository,'B').as_short_text(),
885
branch.repository.revision_store.get('B', 'sig').read())
886
self.assertEqual(Testament.from_revision(branch.repository,
887
'C').as_short_text(),
888
branch.repository.revision_store.get('C',
891
bzrlib.gpg.GPGStrategy = oldstrategy
894
# create a source branch
895
os.mkdir('my-branch')
896
os.chdir('my-branch')
897
self.example_branch()
899
# with no push target, fail
900
self.runbzr('push', retcode=3)
901
# with an explicit target work
902
self.runbzr('push ../output-branch')
903
# with an implicit target work
906
self.runbzr('missing ../output-branch')
907
# advance this branch
908
self.runbzr('commit --unchanged -m unchanged')
910
os.chdir('../output-branch')
911
# There is no longer a difference as long as we have
912
# access to the working tree
915
# But we should be missing a revision
916
self.runbzr('missing ../my-branch', retcode=1)
918
# diverge the branches
919
self.runbzr('commit --unchanged -m unchanged')
920
os.chdir('../my-branch')
922
self.runbzr('push', retcode=3)
923
# and there are difference
924
self.runbzr('missing ../output-branch', retcode=1)
925
self.runbzr('missing --verbose ../output-branch', retcode=1)
926
# but we can force a push
927
self.runbzr('push --overwrite')
929
self.runbzr('missing ../output-branch')
931
# pushing to a new dir with no parent should fail
932
self.runbzr('push ../missing/new-branch', retcode=3)
933
# unless we provide --create-prefix
934
self.runbzr('push --create-prefix ../missing/new-branch')
936
self.runbzr('missing ../missing/new-branch')
938
def test_external_command(self):
939
"""test that external commands can be run by setting the path"""
940
cmd_name = 'test-command'
941
output = 'Hello from test-command'
942
if sys.platform == 'win32':
948
oldpath = os.environ.get('BZRPATH', None)
953
if os.environ.has_key('BZRPATH'):
954
del os.environ['BZRPATH']
956
f = file(cmd_name, 'wb')
957
if sys.platform == 'win32':
958
f.write('@echo off\n')
960
f.write('#!/bin/sh\n')
961
f.write('echo Hello from test-command')
963
os.chmod(cmd_name, 0755)
965
# It should not find the command in the local
966
# directory by default, since it is not in my path
967
bzr(cmd_name, retcode=3)
969
# Now put it into my path
970
os.environ['BZRPATH'] = '.'
973
# The test suite does not capture stdout for external commands
974
# this is because you have to have a real file object
975
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
976
# (just replacing sys.stdout does not change a spawned objects stdout)
977
#self.assertEquals(bzr(cmd_name), output)
979
# Make sure empty path elements are ignored
980
os.environ['BZRPATH'] = os.pathsep
982
bzr(cmd_name, retcode=3)
986
os.environ['BZRPATH'] = oldpath
989
def listdir_sorted(dir):
995
247
class OldTests(ExternalBase):
1017
270
f.write('hello world!\n')
1020
self.assertEquals(capture('unknowns'), 'test.txt\n')
1022
out = capture("status")
1023
self.assertEquals(out, 'unknown:\n test.txt\n')
1025
out = capture("status --all")
1026
self.assertEquals(out, "unknown:\n test.txt\n")
1028
out = capture("status test.txt --all")
1029
self.assertEquals(out, "unknown:\n test.txt\n")
273
out = backtick("bzr unknowns")
274
self.assertEquals(out, 'test.txt\n')
276
out = backtick("bzr status")
277
assert out == 'unknown:\n test.txt\n'
279
out = backtick("bzr status --all")
280
assert out == "unknown:\n test.txt\n"
282
out = backtick("bzr status test.txt --all")
283
assert out == "unknown:\n test.txt\n"
1031
285
f = file('test2.txt', 'wt')
1032
286
f.write('goodbye cruel world...\n')
1035
out = capture("status test.txt")
1036
self.assertEquals(out, "unknown:\n test.txt\n")
289
out = backtick("bzr status test.txt")
290
assert out == "unknown:\n test.txt\n"
1038
out = capture("status")
1039
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
292
out = backtick("bzr status")
293
assert out == ("unknown:\n"
1041
297
os.unlink('test2.txt')
1043
299
progress("command aliases")
1044
out = capture("st --all")
1045
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
300
out = backtick("bzr st --all")
301
assert out == ("unknown:\n"
1047
out = capture("stat")
1048
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
304
out = backtick("bzr stat")
305
assert out == ("unknown:\n"
1050
308
progress("command help")
1051
309
runbzr("help st")
1053
311
runbzr("help commands")
1054
runbzr("help slartibartfast", 3)
312
runbzr("help slartibartfast", 1)
1056
out = capture("help ci")
314
out = backtick("bzr help ci")
1057
315
out.index('aliases: ')
1059
317
progress("can't rename unversioned file")
1060
runbzr("rename test.txt new-test.txt", 3)
318
runbzr("rename test.txt new-test.txt", 1)
1062
320
progress("adding a file")
1064
322
runbzr("add test.txt")
1065
self.assertEquals(capture("unknowns"), '')
1066
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
323
assert backtick("bzr unknowns") == ''
324
assert backtick("bzr status --all") == ("added:\n"
1068
327
progress("rename newly-added file")
1069
328
runbzr("rename test.txt hello.txt")
1070
self.assert_(os.path.exists("hello.txt"))
1071
self.assert_(not os.path.exists("test.txt"))
329
assert os.path.exists("hello.txt")
330
assert not os.path.exists("test.txt")
1073
self.assertEquals(capture("revno"), '0\n')
332
assert backtick("bzr revno") == '0\n'
1075
334
progress("add first revision")
1076
335
runbzr(['commit', '-m', 'add first revision'])
1078
337
progress("more complex renames")
1079
338
os.mkdir("sub1")
1080
runbzr("rename hello.txt sub1", 3)
1081
runbzr("rename hello.txt sub1/hello.txt", 3)
1082
runbzr("move hello.txt sub1", 3)
339
runbzr("rename hello.txt sub1", 1)
340
runbzr("rename hello.txt sub1/hello.txt", 1)
341
runbzr("move hello.txt sub1", 1)
1084
343
runbzr("add sub1")
1085
344
runbzr("rename sub1 sub2")
1086
345
runbzr("move hello.txt sub2")
1087
self.assertEqual(capture("relpath sub2/hello.txt"),
1088
pathjoin("sub2", "hello.txt\n"))
346
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1090
self.assert_(exists("sub2"))
1091
self.assert_(exists("sub2/hello.txt"))
1092
self.assert_(not exists("sub1"))
1093
self.assert_(not exists("hello.txt"))
348
assert exists("sub2")
349
assert exists("sub2/hello.txt")
350
assert not exists("sub1")
351
assert not exists("hello.txt")
1095
353
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1098
356
runbzr('add sub1')
1099
357
runbzr('move sub2/hello.txt sub1')
1100
self.assert_(not exists('sub2/hello.txt'))
1101
self.assert_(exists('sub1/hello.txt'))
358
assert not exists('sub2/hello.txt')
359
assert exists('sub1/hello.txt')
1102
360
runbzr('move sub2 sub1')
1103
self.assert_(not exists('sub2'))
1104
self.assert_(exists('sub1/sub2'))
361
assert not exists('sub2')
362
assert exists('sub1/sub2')
1106
364
runbzr(['commit', '-m', 'rename nested subdirectories'])
1108
366
chdir('sub1/sub2')
1109
self.assertEquals(capture('root')[:-1],
1110
pathjoin(self.test_dir, 'branch1'))
367
self.assertEquals(backtick('bzr root')[:-1],
368
os.path.join(self.test_dir, 'branch1'))
1111
369
runbzr('move ../hello.txt .')
1112
self.assert_(exists('./hello.txt'))
1113
self.assertEquals(capture('relpath hello.txt'),
1114
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
1115
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
370
assert exists('./hello.txt')
371
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
372
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1116
373
runbzr(['commit', '-m', 'move to parent directory'])
1118
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
375
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1120
377
runbzr('move sub2/hello.txt .')
1121
self.assert_(exists('hello.txt'))
378
assert exists('hello.txt')
1123
380
f = file('hello.txt', 'wt')
1124
381
f.write('some nice new content\n')
1127
384
f = file('msg.tmp', 'wt')
1128
f.write('this is my new commit\nand it has multiple lines, for fun')
385
f.write('this is my new commit\n')
1131
388
runbzr('commit -F msg.tmp')
1133
self.assertEquals(capture('revno'), '5\n')
390
assert backtick('bzr revno') == '5\n'
1134
391
runbzr('export -r 5 export-5.tmp')
1135
392
runbzr('export export.tmp')
1138
395
runbzr('log -v')
1139
396
runbzr('log -v --forward')
1140
runbzr('log -m', retcode=3)
1141
log_out = capture('log -m commit')
1142
self.assert_("this is my new commit\n and" in log_out)
1143
self.assert_("rename nested" not in log_out)
1144
self.assert_('revision-id' not in log_out)
1145
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1147
log_out = capture('log --line')
1148
for line in log_out.splitlines():
1149
self.assert_(len(line) <= 79, len(line))
1150
self.assert_("this is my new commit and" in log_out)
397
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
399
assert "this is my new commit" in log_out
400
assert "rename nested" not in log_out
401
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1153
405
progress("file with spaces in name")
1154
406
mkdir('sub directory')
1155
407
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1157
runbzr('diff', retcode=1)
1158
410
runbzr('commit -m add-spaces')
1167
progress("symlinks")
1171
os.symlink("NOWHERE1", "link1")
1173
self.assertEquals(self.capture('unknowns'), '')
1174
runbzr(['commit', '-m', '1: added symlink link1'])
1178
self.assertEquals(self.capture('unknowns'), '')
1179
os.symlink("NOWHERE2", "d1/link2")
1180
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1181
# is d1/link2 found when adding d1
1183
self.assertEquals(self.capture('unknowns'), '')
1184
os.symlink("NOWHERE3", "d1/link3")
1185
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1186
runbzr(['commit', '-m', '2: added dir, symlink'])
1188
runbzr('rename d1 d2')
1189
runbzr('move d2/link2 .')
1190
runbzr('move link1 d2')
1191
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1192
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1193
runbzr('add d2/link3')
1194
runbzr('diff', retcode=1)
1195
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1198
os.symlink("TARGET 2", "link2")
1199
os.unlink("d2/link1")
1200
os.symlink("TARGET 1", "d2/link1")
1201
runbzr('diff', retcode=1)
1202
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1203
runbzr(['commit', '-m', '4: retarget of two links'])
1205
runbzr('remove d2/link1')
1206
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1207
runbzr(['commit', '-m', '5: remove d2/link1'])
1208
# try with the rm alias
1209
runbzr('add d2/link1')
1210
runbzr(['commit', '-m', '6: add d2/link1'])
1211
runbzr('rm d2/link1')
1212
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1213
runbzr(['commit', '-m', '7: remove d2/link1'])
1217
runbzr('rename d2/link3 d1/link3new')
1218
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1219
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1223
runbzr(['export', '-r', '1', 'exp1.tmp'])
1225
self.assertEquals(listdir_sorted("."), [ "link1" ])
1226
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1229
runbzr(['export', '-r', '2', 'exp2.tmp'])
1231
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1234
runbzr(['export', '-r', '3', 'exp3.tmp'])
1236
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1237
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1238
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1239
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1242
runbzr(['export', '-r', '4', 'exp4.tmp'])
1244
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1245
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1246
self.assertEquals(os.readlink("link2") , "TARGET 2")
1247
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1250
runbzr(['export', '-r', '5', 'exp5.tmp'])
1252
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1253
self.assert_(os.path.islink("link2"))
1254
self.assert_(listdir_sorted("d2")== [ "link3" ])
1257
runbzr(['export', '-r', '8', 'exp6.tmp'])
1259
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1260
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1261
self.assertEquals(listdir_sorted("d2"), [])
1262
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1265
progress("skipping symlink tests")
1268
class RemoteTests(object):
1269
"""Test bzr ui commands against remote branches."""
1271
def test_branch(self):
1273
wt = self.make_branch_and_tree('from')
1275
wt.commit('empty commit for nonsense', allow_pointless=True)
1276
url = self.get_readonly_url('from')
1277
self.run_bzr('branch', url, 'to')
1278
branch = Branch.open('to')
1279
self.assertEqual(1, len(branch.revision_history()))
1280
# the branch should be set in to to from
1281
self.assertEqual(url + '/', branch.get_parent())
1284
self.build_tree(['branch/', 'branch/file'])
1285
self.capture('init branch')
1286
self.capture('add branch/file')
1287
self.capture('commit -m foo branch')
1288
url = self.get_readonly_url('branch/file')
1289
output = self.capture('log %s' % url)
1290
self.assertEqual(8, len(output.split('\n')))
1292
def test_check(self):
1293
self.build_tree(['branch/', 'branch/file'])
1294
self.capture('init branch')
1295
self.capture('add branch/file')
1296
self.capture('commit -m foo branch')
1297
url = self.get_readonly_url('branch/')
1298
self.run_bzr('check', url)
1301
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1302
"""Test various commands against a HTTP server."""
1305
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1306
"""Test various commands against a SFTP server using abs paths."""
1309
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1310
"""Test various commands against a SFTP server using abs paths."""
1313
super(SFTPTestsAbsoluteSibling, self).setUp()
1314
self._override_home = '/dev/noone/runs/tests/here'
1317
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1318
"""Test various commands against a SFTP server using homedir rel paths."""
1321
super(SFTPTestsRelative, self).setUp()
1322
self._get_remote_is_absolute = False