112
93
if bzr_email is not None:
113
94
os.environ['BZREMAIL'] = bzr_email
115
def test_nick_command(self):
116
"""bzr nick for viewing, setting nicknames"""
120
nick = self.runbzr("nick",backtick=True)
121
self.assertEqual(nick, 'me.dev\n')
122
nick = self.runbzr("nick moo")
123
nick = self.runbzr("nick",backtick=True)
124
self.assertEqual(nick, 'moo\n')
127
96
def test_invalid_commands(self):
128
self.runbzr("pants", retcode=3)
129
self.runbzr("--pants off", retcode=3)
130
self.runbzr("diff --message foo", retcode=3)
97
self.runbzr("pants", retcode=1)
98
self.runbzr("--pants off", retcode=1)
99
self.runbzr("diff --message foo", retcode=1)
132
101
def test_empty_commit(self):
133
102
self.runbzr("init")
134
103
self.build_tree(['hello.txt'])
135
self.runbzr("commit -m empty", retcode=3)
104
self.runbzr("commit -m empty", retcode=1)
136
105
self.runbzr("add hello.txt")
137
self.runbzr("commit -m added")
106
self.runbzr("commit -m added")
139
108
def test_empty_commit_message(self):
140
109
self.runbzr("init")
141
110
file('foo.c', 'wt').write('int main() {}')
142
111
self.runbzr(['add', 'foo.c'])
143
self.runbzr(["commit", "-m", ""] , retcode=3)
145
def test_remove_deleted(self):
147
self.build_tree(['a'])
148
self.runbzr(['add', 'a'])
149
self.runbzr(['commit', '-m', 'added a'])
151
self.runbzr(['remove', 'a'])
153
def test_other_branch_commit(self):
154
# this branch is to ensure consistent behaviour, whether we're run
155
# inside a branch, or not.
156
os.mkdir('empty_branch')
157
os.chdir('empty_branch')
162
file('foo.c', 'wt').write('int main() {}')
163
file('bar.c', 'wt').write('int main() {}')
165
self.runbzr(['add', 'branch/foo.c'])
166
self.runbzr(['add', 'branch'])
167
# can't commit files in different trees; sane error
168
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
169
self.runbzr('commit -m newstuff branch/foo.c')
170
self.runbzr('commit -m newstuff branch')
171
self.runbzr('commit -m newstuff branch', retcode=3)
112
self.runbzr(["commit", "-m", ""] , retcode=1)
173
114
def test_ignore_patterns(self):
174
115
from bzrlib.branch import Branch
175
Branch.initialize('.')
176
self.assertEquals(self.capture('unknowns'), '')
117
b = Branch.initialize('.')
118
self.assertEquals(list(b.unknowns()), [])
178
120
file('foo.tmp', 'wt').write('tmp files are ignored')
179
self.assertEquals(self.capture('unknowns'), '')
121
self.assertEquals(list(b.unknowns()), [])
122
assert self.capture('unknowns') == ''
181
124
file('foo.c', 'wt').write('int main() {}')
182
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
125
self.assertEquals(list(b.unknowns()), ['foo.c'])
126
assert self.capture('unknowns') == 'foo.c\n'
184
128
self.runbzr(['add', 'foo.c'])
185
self.assertEquals(self.capture('unknowns'), '')
129
assert self.capture('unknowns') == ''
187
131
# 'ignore' works when creating the .bzignore file
188
132
file('foo.blah', 'wt').write('blah')
189
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
133
self.assertEquals(list(b.unknowns()), ['foo.blah'])
190
134
self.runbzr('ignore *.blah')
191
self.assertEquals(self.capture('unknowns'), '')
192
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
135
self.assertEquals(list(b.unknowns()), [])
136
assert file('.bzrignore', 'rU').read() == '*.blah\n'
194
138
# 'ignore' works when then .bzrignore file already exists
195
139
file('garh', 'wt').write('garh')
196
self.assertEquals(self.capture('unknowns'), 'garh\n')
140
self.assertEquals(list(b.unknowns()), ['garh'])
141
assert self.capture('unknowns') == 'garh\n'
197
142
self.runbzr('ignore garh')
198
self.assertEquals(self.capture('unknowns'), '')
199
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
143
self.assertEquals(list(b.unknowns()), [])
144
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
201
146
def test_revert(self):
202
147
self.runbzr('init')
304
234
self.runbzr('export ../latest')
305
235
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
306
236
self.runbzr('export ../first -r 1')
307
self.assert_(not os.path.exists('../first/goodbye'))
237
assert not os.path.exists('../first/goodbye')
308
238
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
309
239
self.runbzr('export ../first.gz -r 1')
310
240
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
311
241
self.runbzr('export ../first.bz2 -r 1')
312
242
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
243
self.runbzr('export ../first.tar -r 1')
244
assert os.path.isfile('../first.tar')
314
245
from tarfile import TarFile
315
self.runbzr('export ../first.tar -r 1')
316
self.assert_(os.path.isfile('../first.tar'))
317
246
tf = TarFile('../first.tar')
318
self.assert_('first/hello' in tf.getnames(), tf.getnames())
247
assert 'first/hello' in tf.getnames(), tf.getnames()
319
248
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
320
249
self.runbzr('export ../first.tar.gz -r 1')
321
self.assert_(os.path.isfile('../first.tar.gz'))
250
assert os.path.isfile('../first.tar.gz')
322
251
self.runbzr('export ../first.tbz2 -r 1')
323
self.assert_(os.path.isfile('../first.tbz2'))
252
assert os.path.isfile('../first.tbz2')
324
253
self.runbzr('export ../first.tar.bz2 -r 1')
325
self.assert_(os.path.isfile('../first.tar.bz2'))
254
assert os.path.isfile('../first.tar.bz2')
326
255
self.runbzr('export ../first.tar.tbz2 -r 1')
327
self.assert_(os.path.isfile('../first.tar.tbz2'))
256
assert os.path.isfile('../first.tar.tbz2')
329
257
from bz2 import BZ2File
330
258
tf = TarFile('../first.tar.tbz2',
331
259
fileobj=BZ2File('../first.tar.tbz2', 'r'))
332
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
260
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
333
261
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
334
262
self.runbzr('export ../first2.tar -r 1 --root pizza')
335
263
tf = TarFile('../first2.tar')
336
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
338
from zipfile import ZipFile
339
self.runbzr('export ../first.zip -r 1')
340
self.failUnlessExists('../first.zip')
341
zf = ZipFile('../first.zip')
342
self.assert_('first/hello' in zf.namelist(), zf.namelist())
343
self.assertEqual(zf.read('first/hello'), 'foo')
345
self.runbzr('export ../first2.zip -r 1 --root pizza')
346
zf = ZipFile('../first2.zip')
347
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
349
self.runbzr('export ../first-zip --format=zip -r 1')
350
zf = ZipFile('../first-zip')
351
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
264
assert 'pizza/hello' in tf.getnames(), tf.getnames()
353
266
def test_diff(self):
354
267
self.example_branch()
355
268
file('hello', 'wt').write('hello world!')
356
269
self.runbzr('commit -m fixing hello')
357
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
270
output = self.runbzr('diff -r 2..3', backtick=1)
358
271
self.assert_('\n+hello world!' in output)
359
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
272
output = self.runbzr('diff -r last:3..last:1', backtick=1)
360
273
self.assert_('\n+baz' in output)
361
file('moo', 'wb').write('moo')
362
self.runbzr('add moo')
366
275
def test_diff_branches(self):
367
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
276
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
368
277
branch = Branch.initialize('branch1')
369
branch.working_tree().add(['file'])
370
branch.working_tree().commit('add file')
279
branch.commit('add file')
371
280
copy_branch(branch, 'branch2')
372
print >> open('branch2/file', 'wb'), 'new content'
281
print >> open('branch2/file', 'w'), 'new content'
373
282
branch2 = Branch.open('branch2')
374
branch2.working_tree().commit('update file')
283
branch2.commit('update file')
375
284
# should open branch1 and diff against branch2,
376
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
285
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
379
286
self.assertEquals(("=== modified file 'file'\n"
382
289
"@@ -1,1 +1,1 @@\n"
384
291
"+contents of branch1/file\n"
385
292
"\n", ''), output)
386
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
388
self.assertEqualDiff(("=== modified file 'file'\n"
393
"+contents of branch1/file\n"
397
294
def test_branch(self):
398
295
"""Branch from one branch to another."""
429
325
file('hello', 'wt').write('quuux')
430
326
# We can't merge when there are in-tree changes
431
self.runbzr('merge ../b', retcode=3)
327
self.runbzr('merge ../b', retcode=1)
432
328
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
433
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
435
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
436
self.runbzr('revert --no-backup')
437
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
438
self.runbzr('revert --no-backup')
439
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
440
self.runbzr('revert --no-backup')
441
self.runbzr('merge ../b -r last:1')
329
self.runbzr('merge ../b')
442
330
self.check_file_contents('goodbye', 'quux')
443
331
# Merging a branch pulls its revision into the tree
444
332
a = Branch.open('.')
445
333
b = Branch.open('../b')
446
334
a.get_revision_xml(b.last_revision())
447
self.log('pending merges: %s', a.working_tree().pending_merges())
448
self.assertEquals(a.working_tree().pending_merges(),
450
self.runbzr('commit -m merged')
451
self.runbzr('merge ../b -r last:1')
452
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
335
self.log('pending merges: %s', a.pending_merges())
336
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
337
# % (a.pending_merges(), b.last_patch())
454
339
def test_merge_with_missing_file(self):
455
340
"""Merge handles missing file conflicts"""
541
420
self.runbzr('pull ../b')
542
421
self.runbzr('pull ../b')
544
def test_inventory(self):
546
def output_equals(value, *args):
547
out = self.runbzr(['inventory'] + list(args), backtick=True)
548
self.assertEquals(out, value)
551
open('a', 'wb').write('hello\n')
557
output_equals('a\n', '--kind', 'file')
558
output_equals('b\n', '--kind', 'directory')
561
"""Test the abilities of 'bzr ls'"""
563
def bzrout(*args, **kwargs):
564
kwargs['backtick'] = True
565
return self.runbzr(*args, **kwargs)
567
def ls_equals(value, *args):
568
out = self.runbzr(['ls'] + list(args), backtick=True)
569
self.assertEquals(out, value)
572
open('a', 'wb').write('hello\n')
575
bzr('ls --verbose --null', retcode=3)
578
ls_equals('? a\n', '--verbose')
579
ls_equals('a\n', '--unknown')
580
ls_equals('', '--ignored')
581
ls_equals('', '--versioned')
582
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
583
ls_equals('', '--ignored', '--versioned')
584
ls_equals('a\0', '--null')
587
ls_equals('V a\n', '--verbose')
594
open('subdir/b', 'wb').write('b\n')
600
bzr('commit -m subdir')
608
, '--verbose', '--non-recursive')
610
# Check what happens in a sub-directory
622
, '--from-root', '--null')
625
, '--from-root', '--non-recursive')
629
# Check what happens when we supply a specific revision
630
ls_equals('a\n', '--revision', '1')
632
, '--verbose', '--revision', '1')
635
ls_equals('', '--revision', '1')
637
# Now try to do ignored files.
639
open('blah.py', 'wb').write('unknown\n')
640
open('blah.pyo', 'wb').write('ignored\n')
652
ls_equals('blah.pyo\n'
654
ls_equals('blah.py\n'
661
def test_pull_verbose(self):
662
"""Pull changes from one branch to another and watch the output."""
668
self.example_branch()
673
open('b', 'wb').write('else\n')
675
bzr(['commit', '-m', 'added b'])
678
out = bzr('pull --verbose ../b', backtick=True)
679
self.failIfEqual(out.find('Added Revisions:'), -1)
680
self.failIfEqual(out.find('message:\n added b'), -1)
681
self.failIfEqual(out.find('added b'), -1)
683
# Check that --overwrite --verbose prints out the removed entries
684
bzr('commit -m foo --unchanged')
686
bzr('commit -m baz --unchanged')
687
bzr('pull ../a', retcode=3)
688
out = bzr('pull --overwrite --verbose ../a', backtick=1)
690
remove_loc = out.find('Removed Revisions:')
691
self.failIfEqual(remove_loc, -1)
692
added_loc = out.find('Added Revisions:')
693
self.failIfEqual(added_loc, -1)
695
removed_message = out.find('message:\n baz')
696
self.failIfEqual(removed_message, -1)
697
self.failUnless(remove_loc < removed_message < added_loc)
699
added_message = out.find('message:\n foo')
700
self.failIfEqual(added_message, -1)
701
self.failUnless(added_loc < added_message)
703
423
def test_locations(self):
704
424
"""Using and remembering different locations"""
707
427
self.runbzr('init')
708
428
self.runbzr('commit -m unchanged --unchanged')
709
self.runbzr('pull', retcode=3)
710
self.runbzr('merge', retcode=3)
429
self.runbzr('pull', retcode=1)
430
self.runbzr('merge', retcode=1)
711
431
self.runbzr('branch . ../b')
713
433
self.runbzr('pull')
744
464
"""add -q does not print the names of added files."""
745
465
b = Branch.initialize('.')
746
466
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
747
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
467
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
748
468
# the ordering is not defined at the moment
749
469
results = sorted(out.rstrip('\n').split('\n'))
750
470
self.assertEquals([''], results)
752
def test_add_in_unversioned(self):
753
"""Try to add a file in an unversioned directory.
755
"bzr add" should add the parent(s) as necessary.
757
from bzrlib.branch import Branch
758
Branch.initialize('.')
759
self.build_tree(['inertiatic/', 'inertiatic/esp'])
760
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
761
self.run_bzr('add', 'inertiatic/esp')
762
self.assertEquals(self.capture('unknowns'), '')
764
# Multiple unversioned parents
765
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
766
self.assertEquals(self.capture('unknowns'), 'veil\n')
767
self.run_bzr('add', 'veil/cerpin/taxt')
768
self.assertEquals(self.capture('unknowns'), '')
770
# Check whacky paths work
771
self.build_tree(['cicatriz/', 'cicatriz/esp'])
772
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
773
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
774
self.assertEquals(self.capture('unknowns'), '')
776
def test_add_in_versioned(self):
777
"""Try to add a file in a versioned directory.
779
"bzr add" should do this happily.
781
from bzrlib.branch import Branch
782
Branch.initialize('.')
783
self.build_tree(['inertiatic/', 'inertiatic/esp'])
784
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
785
self.run_bzr('add', '--no-recurse', 'inertiatic')
786
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
787
self.run_bzr('add', 'inertiatic/esp')
788
self.assertEquals(self.capture('unknowns'), '')
790
def test_subdir_add(self):
791
"""Add in subdirectory should add only things from there down"""
792
from bzrlib.branch import Branch
794
eq = self.assertEqual
798
b = Branch.initialize('.')
800
self.build_tree(['src/', 'README'])
802
eq(sorted(t.unknowns()),
805
self.run_bzr('add', 'src')
807
self.build_tree(['src/foo.c'])
812
self.assertEquals(self.capture('unknowns'), 'README\n')
813
eq(len(t.read_working_inventory()), 3)
817
self.assertEquals(self.capture('unknowns'), '')
818
self.run_bzr('check')
820
472
def test_unknown_command(self):
821
473
"""Handling of unknown command."""
822
474
out, err = self.run_bzr_captured(['fluffy-badger'],
824
476
self.assertEquals(out, '')
825
477
err.index('unknown command')
827
def create_conflicts(self):
828
"""Create a conflicted tree"""
479
def test_conflicts(self):
480
"""Handling of merge conflicts"""
831
483
file('hello', 'wb').write("hi world")
845
497
file('question', 'wb').write("What do you get when you multiply six"
847
499
self.runbzr('commit -m this')
849
def test_remerge(self):
850
"""Remerge command works as expected"""
851
self.create_conflicts()
852
self.runbzr('merge ../other --show-base', retcode=1)
853
conflict_text = file('hello').read()
854
assert '|||||||' in conflict_text
855
assert 'hi world' in conflict_text
856
self.runbzr('remerge', retcode=1)
857
conflict_text = file('hello').read()
858
assert '|||||||' not in conflict_text
859
assert 'hi world' not in conflict_text
860
os.unlink('hello.OTHER')
861
self.runbzr('remerge hello --merge-type weave', retcode=1)
862
assert os.path.exists('hello.OTHER')
863
file_id = self.runbzr('file-id hello')
864
file_id = self.runbzr('file-id hello.THIS', retcode=3)
865
self.runbzr('remerge --merge-type weave', retcode=1)
866
assert os.path.exists('hello.OTHER')
867
assert not os.path.exists('hello.BASE')
868
assert '|||||||' not in conflict_text
869
assert 'hi world' not in conflict_text
870
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
871
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
872
self.runbzr('remerge . --show-base --reprocess', retcode=3)
873
self.runbzr('remerge hello --show-base', retcode=1)
874
self.runbzr('remerge hello --reprocess', retcode=1)
875
self.runbzr('resolve --all')
876
self.runbzr('commit -m done',)
877
self.runbzr('remerge', retcode=3)
880
def test_conflicts(self):
881
"""Handling of merge conflicts"""
882
self.create_conflicts()
883
self.runbzr('merge ../other --show-base', retcode=1)
884
conflict_text = file('hello').read()
885
self.assert_('<<<<<<<' in conflict_text)
886
self.assert_('>>>>>>>' in conflict_text)
887
self.assert_('=======' in conflict_text)
888
self.assert_('|||||||' in conflict_text)
889
self.assert_('hi world' in conflict_text)
890
self.runbzr('revert')
891
self.runbzr('resolve --all')
892
self.runbzr('merge ../other', retcode=1)
893
conflict_text = file('hello').read()
894
self.assert_('|||||||' not in conflict_text)
895
self.assert_('hi world' not in conflict_text)
500
self.runbzr('merge ../other')
896
501
result = self.runbzr('conflicts', backtick=1)
897
502
self.assertEquals(result, "hello\nquestion\n")
898
503
result = self.runbzr('status', backtick=1)
899
self.assert_("conflicts:\n hello\n question\n" in result, result)
504
assert "conflicts:\n hello\n question\n" in result, result
900
505
self.runbzr('resolve hello')
901
506
result = self.runbzr('conflicts', backtick=1)
902
507
self.assertEquals(result, "question\n")
903
self.runbzr('commit -m conflicts', retcode=3)
508
self.runbzr('commit -m conflicts', retcode=1)
904
509
self.runbzr('resolve --all')
905
510
result = self.runbzr('conflicts', backtick=1)
906
511
self.runbzr('commit -m conflicts')
907
512
self.assertEquals(result, "")
909
def test_resign(self):
910
"""Test re signing of data."""
912
oldstrategy = bzrlib.gpg.GPGStrategy
913
branch = Branch.initialize('.')
914
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
916
# monkey patch gpg signing mechanism
917
from bzrlib.testament import Testament
918
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
919
self.runbzr('re-sign -r revid:A')
920
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
921
branch.revision_store.get('A', 'sig').read())
923
bzrlib.gpg.GPGStrategy = oldstrategy
925
def test_resign_range(self):
927
oldstrategy = bzrlib.gpg.GPGStrategy
928
branch = Branch.initialize('.')
929
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
930
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
931
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
933
# monkey patch gpg signing mechanism
934
from bzrlib.testament import Testament
935
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
936
self.runbzr('re-sign -r 1..')
937
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
938
branch.revision_store.get('A', 'sig').read())
939
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
940
branch.revision_store.get('B', 'sig').read())
941
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
942
branch.revision_store.get('C', 'sig').read())
944
bzrlib.gpg.GPGStrategy = oldstrategy
947
# create a source branch
948
os.mkdir('my-branch')
949
os.chdir('my-branch')
950
self.example_branch()
952
# with no push target, fail
953
self.runbzr('push', retcode=3)
954
# with an explicit target work
955
self.runbzr('push ../output-branch')
956
# with an implicit target work
959
self.runbzr('missing ../output-branch')
960
# advance this branch
961
self.runbzr('commit --unchanged -m unchanged')
963
os.chdir('../output-branch')
964
# should be a diff as we have not pushed the tree
965
self.runbzr('diff', retcode=1)
966
self.runbzr('revert')
969
# diverge the branches
970
self.runbzr('commit --unchanged -m unchanged')
971
os.chdir('../my-branch')
973
self.runbzr('push', retcode=3)
974
# and there are difference
975
self.runbzr('missing ../output-branch', retcode=1)
976
self.runbzr('missing --verbose ../output-branch', retcode=1)
977
# but we can force a push
978
self.runbzr('push --overwrite')
980
self.runbzr('missing ../output-branch')
982
# pushing to a new dir with no parent should fail
983
self.runbzr('push ../missing/new-branch', retcode=3)
984
# unless we provide --create-prefix
985
self.runbzr('push --create-prefix ../missing/new-branch')
987
self.runbzr('missing ../missing/new-branch')
989
def test_external_command(self):
990
"""test that external commands can be run by setting the path"""
991
cmd_name = 'test-command'
992
output = 'Hello from test-command'
993
if sys.platform == 'win32':
999
oldpath = os.environ.get('BZRPATH', None)
1004
if os.environ.has_key('BZRPATH'):
1005
del os.environ['BZRPATH']
1007
f = file(cmd_name, 'wb')
1008
if sys.platform == 'win32':
1009
f.write('@echo off\n')
1011
f.write('#!/bin/sh\n')
1012
f.write('echo Hello from test-command')
1014
os.chmod(cmd_name, 0755)
1016
# It should not find the command in the local
1017
# directory by default, since it is not in my path
1018
bzr(cmd_name, retcode=3)
1020
# Now put it into my path
1021
os.environ['BZRPATH'] = '.'
1024
# The test suite does not capture stdout for external commands
1025
# this is because you have to have a real file object
1026
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
1027
# (just replacing sys.stdout does not change a spawned objects stdout)
1028
#self.assertEquals(bzr(cmd_name), output)
1030
# Make sure empty path elements are ignored
1031
os.environ['BZRPATH'] = os.pathsep
1033
bzr(cmd_name, retcode=3)
1037
os.environ['BZRPATH'] = oldpath
1040
514
def listdir_sorted(dir):
1041
515
L = os.listdir(dir)
1071
545
self.assertEquals(capture('unknowns'), 'test.txt\n')
1073
547
out = capture("status")
1074
self.assertEquals(out, 'unknown:\n test.txt\n')
548
assert out == 'unknown:\n test.txt\n'
1076
550
out = capture("status --all")
1077
self.assertEquals(out, "unknown:\n test.txt\n")
551
assert out == "unknown:\n test.txt\n"
1079
553
out = capture("status test.txt --all")
1080
self.assertEquals(out, "unknown:\n test.txt\n")
554
assert out == "unknown:\n test.txt\n"
1082
556
f = file('test2.txt', 'wt')
1083
557
f.write('goodbye cruel world...\n')
1086
560
out = capture("status test.txt")
1087
self.assertEquals(out, "unknown:\n test.txt\n")
561
assert out == "unknown:\n test.txt\n"
1089
563
out = capture("status")
1090
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
564
assert out == ("unknown:\n"
1092
568
os.unlink('test2.txt')
1094
570
progress("command aliases")
1095
571
out = capture("st --all")
1096
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
572
assert out == ("unknown:\n"
1098
575
out = capture("stat")
1099
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
576
assert out == ("unknown:\n"
1101
579
progress("command help")
1102
580
runbzr("help st")
1104
582
runbzr("help commands")
1105
runbzr("help slartibartfast", 3)
583
runbzr("help slartibartfast", 1)
1107
585
out = capture("help ci")
1108
586
out.index('aliases: ')
1110
588
progress("can't rename unversioned file")
1111
runbzr("rename test.txt new-test.txt", 3)
589
runbzr("rename test.txt new-test.txt", 1)
1113
591
progress("adding a file")
1115
593
runbzr("add test.txt")
1116
self.assertEquals(capture("unknowns"), '')
1117
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
594
assert capture("unknowns") == ''
595
assert capture("status --all") == ("added:\n"
1119
598
progress("rename newly-added file")
1120
599
runbzr("rename test.txt hello.txt")
1121
self.assert_(os.path.exists("hello.txt"))
1122
self.assert_(not os.path.exists("test.txt"))
600
assert os.path.exists("hello.txt")
601
assert not os.path.exists("test.txt")
1124
self.assertEquals(capture("revno"), '0\n')
603
assert capture("revno") == '0\n'
1126
605
progress("add first revision")
1127
606
runbzr(['commit', '-m', 'add first revision'])
1129
608
progress("more complex renames")
1130
609
os.mkdir("sub1")
1131
runbzr("rename hello.txt sub1", 3)
1132
runbzr("rename hello.txt sub1/hello.txt", 3)
1133
runbzr("move hello.txt sub1", 3)
610
runbzr("rename hello.txt sub1", 1)
611
runbzr("rename hello.txt sub1/hello.txt", 1)
612
runbzr("move hello.txt sub1", 1)
1135
614
runbzr("add sub1")
1136
615
runbzr("rename sub1 sub2")
1137
616
runbzr("move hello.txt sub2")
1138
self.assertEqual(capture("relpath sub2/hello.txt"),
1139
os.path.join("sub2", "hello.txt\n"))
617
assert capture("relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1141
self.assert_(exists("sub2"))
1142
self.assert_(exists("sub2/hello.txt"))
1143
self.assert_(not exists("sub1"))
1144
self.assert_(not exists("hello.txt"))
619
assert exists("sub2")
620
assert exists("sub2/hello.txt")
621
assert not exists("sub1")
622
assert not exists("hello.txt")
1146
624
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1149
627
runbzr('add sub1')
1150
628
runbzr('move sub2/hello.txt sub1')
1151
self.assert_(not exists('sub2/hello.txt'))
1152
self.assert_(exists('sub1/hello.txt'))
629
assert not exists('sub2/hello.txt')
630
assert exists('sub1/hello.txt')
1153
631
runbzr('move sub2 sub1')
1154
self.assert_(not exists('sub2'))
1155
self.assert_(exists('sub1/sub2'))
632
assert not exists('sub2')
633
assert exists('sub1/sub2')
1157
635
runbzr(['commit', '-m', 'rename nested subdirectories'])
1182
660
runbzr('commit -F msg.tmp')
1184
self.assertEquals(capture('revno'), '5\n')
662
assert capture('revno') == '5\n'
1185
663
runbzr('export -r 5 export-5.tmp')
1186
664
runbzr('export export.tmp')
1189
667
runbzr('log -v')
1190
668
runbzr('log -v --forward')
1191
runbzr('log -m', retcode=3)
669
runbzr('log -m', retcode=1)
1192
670
log_out = capture('log -m commit')
1193
self.assert_("this is my new commit\n and" in log_out)
1194
self.assert_("rename nested" not in log_out)
1195
self.assert_('revision-id' not in log_out)
1196
self.assert_('revision-id' in capture('log --show-ids -m commit'))
671
assert "this is my new commit\n and" in log_out
672
assert "rename nested" not in log_out
673
assert 'revision-id' not in log_out
674
assert 'revision-id' in capture('log --show-ids -m commit')
1198
676
log_out = capture('log --line')
1199
677
for line in log_out.splitlines():
1200
self.assert_(len(line) <= 79, len(line))
1201
self.assert_("this is my new commit and" in log_out)
678
assert len(line) <= 79, len(line)
679
assert "this is my new commit and" in log_out
1204
682
progress("file with spaces in name")
1205
683
mkdir('sub directory')
1206
684
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1208
runbzr('diff', retcode=1)
1209
687
runbzr('commit -m add-spaces')
1222
700
os.symlink("NOWHERE1", "link1")
1223
701
runbzr('add link1')
1224
self.assertEquals(self.capture('unknowns'), '')
702
assert self.capture('unknowns') == ''
1225
703
runbzr(['commit', '-m', '1: added symlink link1'])
1228
706
runbzr('add d1')
1229
self.assertEquals(self.capture('unknowns'), '')
707
assert self.capture('unknowns') == ''
1230
708
os.symlink("NOWHERE2", "d1/link2")
1231
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
709
assert self.capture('unknowns') == 'd1/link2\n'
1232
710
# is d1/link2 found when adding d1
1233
711
runbzr('add d1')
1234
self.assertEquals(self.capture('unknowns'), '')
712
assert self.capture('unknowns') == ''
1235
713
os.symlink("NOWHERE3", "d1/link3")
1236
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
714
assert self.capture('unknowns') == 'd1/link3\n'
1237
715
runbzr(['commit', '-m', '2: added dir, symlink'])
1239
717
runbzr('rename d1 d2')
1240
718
runbzr('move d2/link2 .')
1241
719
runbzr('move link1 d2')
1242
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1243
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
720
assert os.readlink("./link2") == "NOWHERE2"
721
assert os.readlink("d2/link1") == "NOWHERE1"
1244
722
runbzr('add d2/link3')
1245
runbzr('diff', retcode=1)
1246
724
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1248
726
os.unlink("link2")
1249
727
os.symlink("TARGET 2", "link2")
1250
728
os.unlink("d2/link1")
1251
729
os.symlink("TARGET 1", "d2/link1")
1252
runbzr('diff', retcode=1)
1253
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
731
assert self.capture("relpath d2/link1") == "d2/link1\n"
1254
732
runbzr(['commit', '-m', '4: retarget of two links'])
1256
734
runbzr('remove d2/link1')
1257
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
735
assert self.capture('unknowns') == 'd2/link1\n'
1258
736
runbzr(['commit', '-m', '5: remove d2/link1'])
1259
737
# try with the rm alias
1260
738
runbzr('add d2/link1')
1261
739
runbzr(['commit', '-m', '6: add d2/link1'])
1262
740
runbzr('rm d2/link1')
1263
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
741
assert self.capture('unknowns') == 'd2/link1\n'
1264
742
runbzr(['commit', '-m', '7: remove d2/link1'])
1267
745
runbzr('add d1')
1268
746
runbzr('rename d2/link3 d1/link3new')
1269
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
747
assert self.capture('unknowns') == 'd2/link1\n'
1270
748
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1272
750
runbzr(['check'])
1274
752
runbzr(['export', '-r', '1', 'exp1.tmp'])
1275
753
chdir("exp1.tmp")
1276
self.assertEquals(listdir_sorted("."), [ "link1" ])
1277
self.assertEquals(os.readlink("link1"), "NOWHERE1")
754
assert listdir_sorted(".") == [ "link1" ]
755
assert os.readlink("link1") == "NOWHERE1"
1280
758
runbzr(['export', '-r', '2', 'exp2.tmp'])
1281
759
chdir("exp2.tmp")
1282
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
760
assert listdir_sorted(".") == [ "d1", "link1" ]
1285
763
runbzr(['export', '-r', '3', 'exp3.tmp'])
1286
764
chdir("exp3.tmp")
1287
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1288
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1289
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1290
self.assertEquals(os.readlink("link2") , "NOWHERE2")
765
assert listdir_sorted(".") == [ "d2", "link2" ]
766
assert listdir_sorted("d2") == [ "link1", "link3" ]
767
assert os.readlink("d2/link1") == "NOWHERE1"
768
assert os.readlink("link2") == "NOWHERE2"
1293
771
runbzr(['export', '-r', '4', 'exp4.tmp'])
1294
772
chdir("exp4.tmp")
1295
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1296
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1297
self.assertEquals(os.readlink("link2") , "TARGET 2")
1298
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
773
assert listdir_sorted(".") == [ "d2", "link2" ]
774
assert os.readlink("d2/link1") == "TARGET 1"
775
assert os.readlink("link2") == "TARGET 2"
776
assert listdir_sorted("d2") == [ "link1", "link3" ]
1301
779
runbzr(['export', '-r', '5', 'exp5.tmp'])
1302
780
chdir("exp5.tmp")
1303
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1304
self.assert_(os.path.islink("link2"))
1305
self.assert_(listdir_sorted("d2")== [ "link3" ])
781
assert listdir_sorted(".") == [ "d2", "link2" ]
782
assert os.path.islink("link2")
783
assert listdir_sorted("d2")== [ "link3" ]
1308
786
runbzr(['export', '-r', '8', 'exp6.tmp'])
1309
787
chdir("exp6.tmp")
1310
788
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1311
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1312
self.assertEquals(listdir_sorted("d2"), [])
1313
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
789
assert listdir_sorted("d1") == [ "link3new" ]
790
assert listdir_sorted("d2") == []
791
assert os.readlink("d1/link3new") == "NOWHERE3"
1316
794
progress("skipping symlink tests")