83
73
f = file('.bzr/email', 'wt')
84
74
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
76
whoami = self.runbzr("whoami",backtick=True)
90
77
whoami_email = self.runbzr("whoami --email",backtick=True)
91
78
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
92
79
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
81
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)
82
self.runbzr("pants", retcode=1)
83
self.runbzr("--pants off", retcode=1)
84
self.runbzr("diff --message foo", retcode=1)
120
86
def test_empty_commit(self):
121
87
self.runbzr("init")
122
88
self.build_tree(['hello.txt'])
123
self.runbzr("commit -m empty", retcode=3)
89
self.runbzr("commit -m empty", retcode=1)
124
90
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)
91
self.runbzr("commit -m added")
161
93
def test_ignore_patterns(self):
162
94
from bzrlib.branch import Branch
163
Branch.initialize('.')
164
self.assertEquals(self.capture('unknowns'), '')
96
b = Branch('.', init=True)
97
self.assertEquals(list(b.unknowns()), [])
166
99
file('foo.tmp', 'wt').write('tmp files are ignored')
167
self.assertEquals(self.capture('unknowns'), '')
100
self.assertEquals(list(b.unknowns()), [])
101
assert self.backtick('bzr unknowns') == ''
169
103
file('foo.c', 'wt').write('int main() {}')
170
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'
172
107
self.runbzr(['add', 'foo.c'])
173
self.assertEquals(self.capture('unknowns'), '')
108
assert self.backtick('bzr unknowns') == ''
175
110
# 'ignore' works when creating the .bzignore file
176
111
file('foo.blah', 'wt').write('blah')
177
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
112
self.assertEquals(list(b.unknowns()), ['foo.blah'])
178
113
self.runbzr('ignore *.blah')
179
self.assertEquals(self.capture('unknowns'), '')
180
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
114
self.assertEquals(list(b.unknowns()), [])
115
assert file('.bzrignore', 'rb').read() == '*.blah\n'
182
117
# 'ignore' works when then .bzrignore file already exists
183
118
file('garh', 'wt').write('garh')
184
self.assertEquals(self.capture('unknowns'), 'garh\n')
119
self.assertEquals(list(b.unknowns()), ['garh'])
120
assert self.backtick('bzr unknowns') == 'garh\n'
185
121
self.runbzr('ignore garh')
186
self.assertEquals(self.capture('unknowns'), '')
187
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
122
self.assertEquals(list(b.unknowns()), [])
123
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
189
125
def test_revert(self):
190
126
self.runbzr('init')
285
184
test.runbzr('add goodbye')
286
185
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')
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')
404
197
def test_merge(self):
405
198
from bzrlib.branch import Branch
481
229
self.example_branch()
482
self.runbzr('pull', retcode=3)
483
self.runbzr('missing', retcode=3)
230
self.runbzr('pull', retcode=1)
231
self.runbzr('missing', retcode=1)
484
232
self.runbzr('missing .')
485
233
self.runbzr('missing')
486
234
self.runbzr('pull')
487
self.runbzr('pull /', retcode=3)
235
self.runbzr('pull /', retcode=1)
488
236
self.runbzr('pull')
491
239
self.runbzr('branch a b')
493
241
self.runbzr('pull')
495
self.runbzr('add subdir')
496
242
self.runbzr('commit -m blah --unchanged')
499
b = Branch.open('../b')
500
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
246
assert a.revision_history() == b.revision_history()[:-1]
501
247
self.runbzr('pull ../b')
502
self.assertEquals(a.revision_history(), b.revision_history())
248
assert a.revision_history() == b.revision_history()
503
249
self.runbzr('commit -m blah2 --unchanged')
505
251
self.runbzr('commit -m blah3 --unchanged')
507
self.runbzr('pull ../a', retcode=3)
509
self.runbzr('branch b overwriteme')
510
os.chdir('overwriteme')
511
self.runbzr('pull --overwrite ../a')
512
overwritten = Branch.open('.')
513
self.assertEqual(overwritten.revision_history(),
514
a.revision_history())
252
self.runbzr('pull ../a', retcode=1)
516
254
self.runbzr('merge ../b')
517
255
self.runbzr('commit -m blah4 --unchanged')
518
os.chdir('../b/subdir')
519
self.runbzr('pull ../../a')
520
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
521
self.runbzr('commit -m blah5 --unchanged')
522
self.runbzr('commit -m blah6 --unchanged')
524
257
self.runbzr('pull ../a')
526
self.runbzr('commit -m blah7 --unchanged')
527
self.runbzr('merge ../b')
528
self.runbzr('commit -m blah8 --unchanged')
529
self.runbzr('pull ../b')
530
self.runbzr('pull ../b')
532
def test_inventory(self):
534
def output_equals(value, *args):
535
out = self.runbzr(['inventory'] + list(args), backtick=True)
536
self.assertEquals(out, value)
539
open('a', 'wb').write('hello\n')
545
output_equals('a\n', '--kind', 'file')
546
output_equals('b\n', '--kind', 'directory')
549
"""Test the abilities of 'bzr ls'"""
551
def bzrout(*args, **kwargs):
552
kwargs['backtick'] = True
553
return self.runbzr(*args, **kwargs)
555
def ls_equals(value, *args):
556
out = self.runbzr(['ls'] + list(args), backtick=True)
557
self.assertEquals(out, value)
560
open('a', 'wb').write('hello\n')
563
bzr('ls --verbose --null', retcode=3)
566
ls_equals('? a\n', '--verbose')
567
ls_equals('a\n', '--unknown')
568
ls_equals('', '--ignored')
569
ls_equals('', '--versioned')
570
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
571
ls_equals('', '--ignored', '--versioned')
572
ls_equals('a\0', '--null')
575
ls_equals('V a\n', '--verbose')
582
open('subdir/b', 'wb').write('b\n')
588
bzr('commit -m subdir')
596
, '--verbose', '--non-recursive')
598
# Check what happens in a sub-directory
610
, '--from-root', '--null')
613
, '--from-root', '--non-recursive')
617
# Check what happens when we supply a specific revision
618
ls_equals('a\n', '--revision', '1')
620
, '--verbose', '--revision', '1')
623
ls_equals('', '--revision', '1')
625
# Now try to do ignored files.
627
open('blah.py', 'wb').write('unknown\n')
628
open('blah.pyo', 'wb').write('ignored\n')
640
ls_equals('blah.pyo\n'
642
ls_equals('blah.py\n'
649
def test_pull_verbose(self):
650
"""Pull changes from one branch to another and watch the output."""
656
self.example_branch()
661
open('b', 'wb').write('else\n')
663
bzr(['commit', '-m', 'added b'])
666
out = bzr('pull --verbose ../b', backtick=True)
667
self.failIfEqual(out.find('Added Revisions:'), -1)
668
self.failIfEqual(out.find('message:\n added b'), -1)
669
self.failIfEqual(out.find('added b'), -1)
671
# Check that --overwrite --verbose prints out the removed entries
672
bzr('commit -m foo --unchanged')
674
bzr('commit -m baz --unchanged')
675
bzr('pull ../a', retcode=3)
676
out = bzr('pull --overwrite --verbose ../a', backtick=1)
678
remove_loc = out.find('Removed Revisions:')
679
self.failIfEqual(remove_loc, -1)
680
added_loc = out.find('Added Revisions:')
681
self.failIfEqual(added_loc, -1)
683
removed_message = out.find('message:\n baz')
684
self.failIfEqual(removed_message, -1)
685
self.failUnless(remove_loc < removed_message < added_loc)
687
added_message = out.find('message:\n foo')
688
self.failIfEqual(added_message, -1)
689
self.failUnless(added_loc < added_message)
691
def test_locations(self):
692
"""Using and remembering different locations"""
696
self.runbzr('commit -m unchanged --unchanged')
697
self.runbzr('pull', retcode=3)
698
self.runbzr('merge', retcode=3)
699
self.runbzr('branch . ../b')
702
self.runbzr('branch . ../c')
703
self.runbzr('pull ../c')
706
self.runbzr('pull ../b')
708
self.runbzr('pull ../c')
709
self.runbzr('branch ../c ../d')
710
shutil.rmtree('../c')
715
self.runbzr('pull', retcode=3)
716
self.runbzr('pull ../a --remember')
258
assert a.revision_history()[-1] == b.revision_history()[-1]
719
261
def test_add_reports(self):
720
262
"""add command prints the names of added files."""
721
b = Branch.initialize('.')
263
b = Branch('.', init=True)
722
264
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
723
out = self.run_bzr_captured(['add'], retcode=0)[0]
266
from cStringIO import StringIO
269
ret = self.apply_redirected(None, out, None,
272
self.assertEquals(ret, 0)
724
274
# the ordering is not defined at the moment
725
results = sorted(out.rstrip('\n').split('\n'))
275
results = sorted(out.getvalue().rstrip('\n').split('\n'))
726
276
self.assertEquals(['added dir',
727
'added dir'+os.sep+'sub.txt',
728
278
'added top.txt',],
731
def test_add_quiet_is(self):
732
"""add -q does not print the names of added files."""
733
b = Branch.initialize('.')
734
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
735
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
736
# the ordering is not defined at the moment
737
results = sorted(out.rstrip('\n').split('\n'))
738
self.assertEquals([''], results)
740
def test_add_in_unversioned(self):
741
"""Try to add a file in an unversioned directory.
743
"bzr add" should add the parent(s) as necessary.
745
from bzrlib.branch import Branch
746
Branch.initialize('.')
747
self.build_tree(['inertiatic/', 'inertiatic/esp'])
748
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
749
self.run_bzr('add', 'inertiatic/esp')
750
self.assertEquals(self.capture('unknowns'), '')
752
# Multiple unversioned parents
753
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
754
self.assertEquals(self.capture('unknowns'), 'veil\n')
755
self.run_bzr('add', 'veil/cerpin/taxt')
756
self.assertEquals(self.capture('unknowns'), '')
758
# Check whacky paths work
759
self.build_tree(['cicatriz/', 'cicatriz/esp'])
760
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
761
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
762
self.assertEquals(self.capture('unknowns'), '')
764
def test_add_in_versioned(self):
765
"""Try to add a file in a versioned directory.
767
"bzr add" should do this happily.
769
from bzrlib.branch import Branch
770
Branch.initialize('.')
771
self.build_tree(['inertiatic/', 'inertiatic/esp'])
772
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
773
self.run_bzr('add', '--no-recurse', 'inertiatic')
774
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
775
self.run_bzr('add', 'inertiatic/esp')
776
self.assertEquals(self.capture('unknowns'), '')
778
def test_subdir_add(self):
779
"""Add in subdirectory should add only things from there down"""
780
from bzrlib.branch import Branch
782
eq = self.assertEqual
786
b = Branch.initialize('.')
788
self.build_tree(['src/', 'README'])
790
eq(sorted(t.unknowns()),
793
self.run_bzr('add', 'src')
795
self.build_tree(['src/foo.c'])
800
self.assertEquals(self.capture('unknowns'), 'README\n')
801
eq(len(t.read_working_inventory()), 3)
805
self.assertEquals(self.capture('unknowns'), '')
806
self.run_bzr('check')
808
def test_unknown_command(self):
809
"""Handling of unknown command."""
810
out, err = self.run_bzr_captured(['fluffy-badger'],
812
self.assertEquals(out, '')
813
err.index('unknown command')
815
def create_conflicts(self):
816
"""Create a conflicted tree"""
819
file('hello', 'wb').write("hi world")
820
file('answer', 'wb').write("42")
823
self.runbzr('commit -m base')
824
self.runbzr('branch . ../other')
825
self.runbzr('branch . ../this')
827
file('hello', 'wb').write("Hello.")
828
file('answer', 'wb').write("Is anyone there?")
829
self.runbzr('commit -m other')
831
file('hello', 'wb').write("Hello, world")
832
self.runbzr('mv answer question')
833
file('question', 'wb').write("What do you get when you multiply six"
835
self.runbzr('commit -m this')
837
def test_remerge(self):
838
"""Remerge command works as expected"""
839
self.create_conflicts()
840
self.runbzr('merge ../other --show-base', retcode=1)
841
conflict_text = file('hello').read()
842
assert '|||||||' in conflict_text
843
assert 'hi world' in conflict_text
844
self.runbzr('remerge', retcode=1)
845
conflict_text = file('hello').read()
846
assert '|||||||' not in conflict_text
847
assert 'hi world' not in conflict_text
848
os.unlink('hello.OTHER')
849
self.runbzr('remerge hello --merge-type weave', retcode=1)
850
assert os.path.exists('hello.OTHER')
851
file_id = self.runbzr('file-id hello')
852
file_id = self.runbzr('file-id hello.THIS', retcode=3)
853
self.runbzr('remerge --merge-type weave', retcode=1)
854
assert os.path.exists('hello.OTHER')
855
assert not os.path.exists('hello.BASE')
856
assert '|||||||' not in conflict_text
857
assert 'hi world' not in conflict_text
858
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
859
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
860
self.runbzr('remerge . --show-base --reprocess', retcode=3)
861
self.runbzr('remerge hello --show-base', retcode=1)
862
self.runbzr('remerge hello --reprocess', retcode=1)
863
self.runbzr('resolve --all')
864
self.runbzr('commit -m done',)
865
self.runbzr('remerge', retcode=3)
868
def test_conflicts(self):
869
"""Handling of merge conflicts"""
870
self.create_conflicts()
871
self.runbzr('merge ../other --show-base', retcode=1)
872
conflict_text = file('hello').read()
873
self.assert_('<<<<<<<' in conflict_text)
874
self.assert_('>>>>>>>' in conflict_text)
875
self.assert_('=======' in conflict_text)
876
self.assert_('|||||||' in conflict_text)
877
self.assert_('hi world' in conflict_text)
878
self.runbzr('revert')
879
self.runbzr('resolve --all')
880
self.runbzr('merge ../other', retcode=1)
881
conflict_text = file('hello').read()
882
self.assert_('|||||||' not in conflict_text)
883
self.assert_('hi world' not in conflict_text)
884
result = self.runbzr('conflicts', backtick=1)
885
self.assertEquals(result, "hello\nquestion\n")
886
result = self.runbzr('status', backtick=1)
887
self.assert_("conflicts:\n hello\n question\n" in result, result)
888
self.runbzr('resolve hello')
889
result = self.runbzr('conflicts', backtick=1)
890
self.assertEquals(result, "question\n")
891
self.runbzr('commit -m conflicts', retcode=3)
892
self.runbzr('resolve --all')
893
result = self.runbzr('conflicts', backtick=1)
894
self.runbzr('commit -m conflicts')
895
self.assertEquals(result, "")
897
def test_resign(self):
898
"""Test re signing of data."""
900
oldstrategy = bzrlib.gpg.GPGStrategy
901
branch = Branch.initialize('.')
902
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
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 revid:A')
908
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
909
branch.revision_store.get('A', 'sig').read())
911
bzrlib.gpg.GPGStrategy = oldstrategy
913
def test_resign_range(self):
915
oldstrategy = bzrlib.gpg.GPGStrategy
916
branch = Branch.initialize('.')
917
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
918
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
919
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
921
# monkey patch gpg signing mechanism
922
from bzrlib.testament import Testament
923
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
924
self.runbzr('re-sign -r 1..')
925
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
926
branch.revision_store.get('A', 'sig').read())
927
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
928
branch.revision_store.get('B', 'sig').read())
929
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
930
branch.revision_store.get('C', 'sig').read())
932
bzrlib.gpg.GPGStrategy = oldstrategy
935
# create a source branch
936
os.mkdir('my-branch')
937
os.chdir('my-branch')
938
self.example_branch()
940
# with no push target, fail
941
self.runbzr('push', retcode=3)
942
# with an explicit target work
943
self.runbzr('push ../output-branch')
944
# with an implicit target work
947
self.runbzr('missing ../output-branch')
948
# advance this branch
949
self.runbzr('commit --unchanged -m unchanged')
951
os.chdir('../output-branch')
952
# should be a diff as we have not pushed the tree
953
self.runbzr('diff', retcode=1)
954
self.runbzr('revert')
957
# diverge the branches
958
self.runbzr('commit --unchanged -m unchanged')
959
os.chdir('../my-branch')
961
self.runbzr('push', retcode=3)
962
# and there are difference
963
self.runbzr('missing ../output-branch', retcode=1)
964
self.runbzr('missing --verbose ../output-branch', retcode=1)
965
# but we can force a push
966
self.runbzr('push --overwrite')
968
self.runbzr('missing ../output-branch')
970
# pushing to a new dir with no parent should fail
971
self.runbzr('push ../missing/new-branch', retcode=3)
972
# unless we provide --create-prefix
973
self.runbzr('push --create-prefix ../missing/new-branch')
975
self.runbzr('missing ../missing/new-branch')
977
def test_external_command(self):
978
"""test that external commands can be run by setting the path"""
979
cmd_name = 'test-command'
980
output = 'Hello from test-command'
981
if sys.platform == 'win32':
987
oldpath = os.environ.get('BZRPATH', None)
992
if os.environ.has_key('BZRPATH'):
993
del os.environ['BZRPATH']
995
f = file(cmd_name, 'wb')
996
if sys.platform == 'win32':
997
f.write('@echo off\n')
999
f.write('#!/bin/sh\n')
1000
f.write('echo Hello from test-command')
1002
os.chmod(cmd_name, 0755)
1004
# It should not find the command in the local
1005
# directory by default, since it is not in my path
1006
bzr(cmd_name, retcode=3)
1008
# Now put it into my path
1009
os.environ['BZRPATH'] = '.'
1012
# The test suite does not capture stdout for external commands
1013
# this is because you have to have a real file object
1014
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
1015
# (just replacing sys.stdout does not change a spawned objects stdout)
1016
#self.assertEquals(bzr(cmd_name), output)
1018
# Make sure empty path elements are ignored
1019
os.environ['BZRPATH'] = os.pathsep
1021
bzr(cmd_name, retcode=3)
1025
os.environ['BZRPATH'] = oldpath
1028
def listdir_sorted(dir):
1034
282
class OldTests(ExternalBase):
1035
283
"""old tests moved from ./testbzr."""
1056
304
f.write('hello world!\n')
1059
self.assertEquals(capture('unknowns'), 'test.txt\n')
1061
out = capture("status")
1062
self.assertEquals(out, 'unknown:\n test.txt\n')
1064
out = capture("status --all")
1065
self.assertEquals(out, "unknown:\n test.txt\n")
1067
out = capture("status test.txt --all")
1068
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"
1070
319
f = file('test2.txt', 'wt')
1071
320
f.write('goodbye cruel world...\n')
1074
out = capture("status test.txt")
1075
self.assertEquals(out, "unknown:\n test.txt\n")
323
out = backtick("bzr status test.txt")
324
assert out == "unknown:\n test.txt\n"
1077
out = capture("status")
1078
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
326
out = backtick("bzr status")
327
assert out == ("unknown:\n"
1080
331
os.unlink('test2.txt')
1082
333
progress("command aliases")
1083
out = capture("st --all")
1084
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
334
out = backtick("bzr st --all")
335
assert out == ("unknown:\n"
1086
out = capture("stat")
1087
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
338
out = backtick("bzr stat")
339
assert out == ("unknown:\n"
1089
342
progress("command help")
1090
343
runbzr("help st")
1092
345
runbzr("help commands")
1093
runbzr("help slartibartfast", 3)
346
runbzr("help slartibartfast", 1)
1095
out = capture("help ci")
348
out = backtick("bzr help ci")
1096
349
out.index('aliases: ')
1098
351
progress("can't rename unversioned file")
1099
runbzr("rename test.txt new-test.txt", 3)
352
runbzr("rename test.txt new-test.txt", 1)
1101
354
progress("adding a file")
1103
356
runbzr("add test.txt")
1104
self.assertEquals(capture("unknowns"), '')
1105
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
357
assert backtick("bzr unknowns") == ''
358
assert backtick("bzr status --all") == ("added:\n"
1107
361
progress("rename newly-added file")
1108
362
runbzr("rename test.txt hello.txt")
1109
self.assert_(os.path.exists("hello.txt"))
1110
self.assert_(not os.path.exists("test.txt"))
363
assert os.path.exists("hello.txt")
364
assert not os.path.exists("test.txt")
1112
self.assertEquals(capture("revno"), '0\n')
366
assert backtick("bzr revno") == '0\n'
1114
368
progress("add first revision")
1115
369
runbzr(['commit', '-m', 'add first revision'])
1117
371
progress("more complex renames")
1118
372
os.mkdir("sub1")
1119
runbzr("rename hello.txt sub1", 3)
1120
runbzr("rename hello.txt sub1/hello.txt", 3)
1121
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)
1123
377
runbzr("add sub1")
1124
378
runbzr("rename sub1 sub2")
1125
379
runbzr("move hello.txt sub2")
1126
self.assertEqual(capture("relpath sub2/hello.txt"),
1127
os.path.join("sub2", "hello.txt\n"))
380
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1129
self.assert_(exists("sub2"))
1130
self.assert_(exists("sub2/hello.txt"))
1131
self.assert_(not exists("sub1"))
1132
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")
1134
387
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1137
390
runbzr('add sub1')
1138
391
runbzr('move sub2/hello.txt sub1')
1139
self.assert_(not exists('sub2/hello.txt'))
1140
self.assert_(exists('sub1/hello.txt'))
392
assert not exists('sub2/hello.txt')
393
assert exists('sub1/hello.txt')
1141
394
runbzr('move sub2 sub1')
1142
self.assert_(not exists('sub2'))
1143
self.assert_(exists('sub1/sub2'))
395
assert not exists('sub2')
396
assert exists('sub1/sub2')
1145
398
runbzr(['commit', '-m', 'rename nested subdirectories'])
1147
400
chdir('sub1/sub2')
1148
self.assertEquals(capture('root')[:-1],
401
self.assertEquals(backtick('bzr root')[:-1],
1149
402
os.path.join(self.test_dir, 'branch1'))
1150
403
runbzr('move ../hello.txt .')
1151
self.assert_(exists('./hello.txt'))
1152
self.assertEquals(capture('relpath hello.txt'),
1153
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1154
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('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')
1155
407
runbzr(['commit', '-m', 'move to parent directory'])
1157
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
409
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1159
411
runbzr('move sub2/hello.txt .')
1160
self.assert_(exists('hello.txt'))
412
assert exists('hello.txt')
1162
414
f = file('hello.txt', 'wt')
1163
415
f.write('some nice new content\n')
1166
418
f = file('msg.tmp', 'wt')
1167
f.write('this is my new commit\nand it has multiple lines, for fun')
419
f.write('this is my new commit\n')
1170
422
runbzr('commit -F msg.tmp')
1172
self.assertEquals(capture('revno'), '5\n')
424
assert backtick('bzr revno') == '5\n'
1173
425
runbzr('export -r 5 export-5.tmp')
1174
426
runbzr('export export.tmp')
1177
429
runbzr('log -v')
1178
430
runbzr('log -v --forward')
1179
runbzr('log -m', retcode=3)
1180
log_out = capture('log -m commit')
1181
self.assert_("this is my new commit\n and" in log_out)
1182
self.assert_("rename nested" not in log_out)
1183
self.assert_('revision-id' not in log_out)
1184
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1186
log_out = capture('log --line')
1187
for line in log_out.splitlines():
1188
self.assert_(len(line) <= 79, len(line))
1189
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')
1192
439
progress("file with spaces in name")
1193
440
mkdir('sub directory')
1194
441
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1196
runbzr('diff', retcode=1)
1197
444
runbzr('commit -m add-spaces')
1206
progress("symlinks")
1210
os.symlink("NOWHERE1", "link1")
1212
self.assertEquals(self.capture('unknowns'), '')
1213
runbzr(['commit', '-m', '1: added symlink link1'])
1217
self.assertEquals(self.capture('unknowns'), '')
1218
os.symlink("NOWHERE2", "d1/link2")
1219
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1220
# is d1/link2 found when adding d1
1222
self.assertEquals(self.capture('unknowns'), '')
1223
os.symlink("NOWHERE3", "d1/link3")
1224
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1225
runbzr(['commit', '-m', '2: added dir, symlink'])
1227
runbzr('rename d1 d2')
1228
runbzr('move d2/link2 .')
1229
runbzr('move link1 d2')
1230
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1231
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1232
runbzr('add d2/link3')
1233
runbzr('diff', retcode=1)
1234
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1237
os.symlink("TARGET 2", "link2")
1238
os.unlink("d2/link1")
1239
os.symlink("TARGET 1", "d2/link1")
1240
runbzr('diff', retcode=1)
1241
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1242
runbzr(['commit', '-m', '4: retarget of two links'])
1244
runbzr('remove d2/link1')
1245
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1246
runbzr(['commit', '-m', '5: remove d2/link1'])
1247
# try with the rm alias
1248
runbzr('add d2/link1')
1249
runbzr(['commit', '-m', '6: add d2/link1'])
1250
runbzr('rm d2/link1')
1251
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1252
runbzr(['commit', '-m', '7: remove d2/link1'])
1256
runbzr('rename d2/link3 d1/link3new')
1257
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1258
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1262
runbzr(['export', '-r', '1', 'exp1.tmp'])
1264
self.assertEquals(listdir_sorted("."), [ "link1" ])
1265
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1268
runbzr(['export', '-r', '2', 'exp2.tmp'])
1270
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1273
runbzr(['export', '-r', '3', 'exp3.tmp'])
1275
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1276
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1277
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1278
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1281
runbzr(['export', '-r', '4', 'exp4.tmp'])
1283
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1284
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1285
self.assertEquals(os.readlink("link2") , "TARGET 2")
1286
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1289
runbzr(['export', '-r', '5', 'exp5.tmp'])
1291
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1292
self.assert_(os.path.islink("link2"))
1293
self.assert_(listdir_sorted("d2")== [ "link3" ])
1296
runbzr(['export', '-r', '8', 'exp6.tmp'])
1298
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1299
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1300
self.assertEquals(listdir_sorted("d2"), [])
1301
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1304
progress("skipping symlink tests")
1307
class HttpTests(TestCaseWithWebserver):
1308
"""Test bzr ui commands against remote branches."""
1310
def test_branch(self):
1312
branch = Branch.initialize('from')
1313
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1314
url = self.get_remote_url('from')
1315
self.run_bzr('branch', url, 'to')
1316
branch = Branch.open('to')
1317
self.assertEqual(1, len(branch.revision_history()))
1320
self.build_tree(['branch/', 'branch/file'])
1321
branch = Branch.initialize('branch')
1322
branch.working_tree().add(['file'])
1323
branch.working_tree().commit('add file', rev_id='A')
1324
url = self.get_remote_url('branch/file')
1325
output = self.capture('log %s' % url)
1326
self.assertEqual(8, len(output.split('\n')))
1328
def test_check(self):
1329
self.build_tree(['branch/', 'branch/file'])
1330
branch = Branch.initialize('branch')
1331
branch.working_tree().add(['file'])
1332
branch.working_tree().commit('add file', rev_id='A')
1333
url = self.get_remote_url('branch/')
1334
self.run_bzr('check', url)