100
93
if bzr_email is not None:
101
94
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
96
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)
97
self.runbzr("pants", retcode=1)
98
self.runbzr("--pants off", retcode=1)
99
self.runbzr("diff --message foo", retcode=1)
120
101
def test_empty_commit(self):
121
102
self.runbzr("init")
122
103
self.build_tree(['hello.txt'])
123
self.runbzr("commit -m empty", retcode=3)
104
self.runbzr("commit -m empty", retcode=1)
124
105
self.runbzr("add hello.txt")
125
self.runbzr("commit -m added")
106
self.runbzr("commit -m added")
127
108
def test_empty_commit_message(self):
128
109
self.runbzr("init")
129
110
file('foo.c', 'wt').write('int main() {}')
130
111
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)
112
self.runbzr(["commit", "-m", ""] , retcode=1)
161
114
def test_ignore_patterns(self):
162
115
from bzrlib.branch import Branch
163
Branch.initialize('.')
164
self.assertEquals(self.capture('unknowns'), '')
117
b = Branch.initialize('.')
118
self.assertEquals(list(b.unknowns()), [])
166
120
file('foo.tmp', 'wt').write('tmp files are ignored')
167
self.assertEquals(self.capture('unknowns'), '')
121
self.assertEquals(list(b.unknowns()), [])
122
assert self.capture('unknowns') == ''
169
124
file('foo.c', 'wt').write('int main() {}')
170
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
125
self.assertEquals(list(b.unknowns()), ['foo.c'])
126
assert self.capture('unknowns') == 'foo.c\n'
172
128
self.runbzr(['add', 'foo.c'])
173
self.assertEquals(self.capture('unknowns'), '')
129
assert self.capture('unknowns') == ''
175
131
# 'ignore' works when creating the .bzignore file
176
132
file('foo.blah', 'wt').write('blah')
177
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
133
self.assertEquals(list(b.unknowns()), ['foo.blah'])
178
134
self.runbzr('ignore *.blah')
179
self.assertEquals(self.capture('unknowns'), '')
180
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
135
self.assertEquals(list(b.unknowns()), [])
136
assert file('.bzrignore', 'rU').read() == '*.blah\n'
182
138
# 'ignore' works when then .bzrignore file already exists
183
139
file('garh', 'wt').write('garh')
184
self.assertEquals(self.capture('unknowns'), 'garh\n')
140
self.assertEquals(list(b.unknowns()), ['garh'])
141
assert self.capture('unknowns') == 'garh\n'
185
142
self.runbzr('ignore garh')
186
self.assertEquals(self.capture('unknowns'), '')
187
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
143
self.assertEquals(list(b.unknowns()), [])
144
assert file('.bzrignore', 'rU').read() == '*.blah\ngarh\n'
189
146
def test_revert(self):
190
147
self.runbzr('init')
292
234
self.runbzr('export ../latest')
293
235
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
294
236
self.runbzr('export ../first -r 1')
295
self.assert_(not os.path.exists('../first/goodbye'))
237
assert not os.path.exists('../first/goodbye')
296
238
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
297
239
self.runbzr('export ../first.gz -r 1')
298
240
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
299
241
self.runbzr('export ../first.bz2 -r 1')
300
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')
302
245
from tarfile import TarFile
303
self.runbzr('export ../first.tar -r 1')
304
self.assert_(os.path.isfile('../first.tar'))
305
246
tf = TarFile('../first.tar')
306
self.assert_('first/hello' in tf.getnames(), tf.getnames())
247
assert 'first/hello' in tf.getnames(), tf.getnames()
307
248
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
308
249
self.runbzr('export ../first.tar.gz -r 1')
309
self.assert_(os.path.isfile('../first.tar.gz'))
250
assert os.path.isfile('../first.tar.gz')
310
251
self.runbzr('export ../first.tbz2 -r 1')
311
self.assert_(os.path.isfile('../first.tbz2'))
252
assert os.path.isfile('../first.tbz2')
312
253
self.runbzr('export ../first.tar.bz2 -r 1')
313
self.assert_(os.path.isfile('../first.tar.bz2'))
254
assert os.path.isfile('../first.tar.bz2')
314
255
self.runbzr('export ../first.tar.tbz2 -r 1')
315
self.assert_(os.path.isfile('../first.tar.tbz2'))
256
assert os.path.isfile('../first.tar.tbz2')
317
257
from bz2 import BZ2File
318
258
tf = TarFile('../first.tar.tbz2',
319
259
fileobj=BZ2File('../first.tar.tbz2', 'r'))
320
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
260
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
321
261
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
322
262
self.runbzr('export ../first2.tar -r 1 --root pizza')
323
263
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())
264
assert 'pizza/hello' in tf.getnames(), tf.getnames()
341
266
def test_diff(self):
342
267
self.example_branch()
343
268
file('hello', 'wt').write('hello world!')
344
269
self.runbzr('commit -m fixing hello')
345
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
270
output = self.runbzr('diff -r 2..3', backtick=1)
346
271
self.assert_('\n+hello world!' in output)
347
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)
348
273
self.assert_('\n+baz' in output)
349
file('moo', 'wb').write('moo')
350
self.runbzr('add moo')
354
275
def test_diff_branches(self):
355
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
276
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
356
277
branch = Branch.initialize('branch1')
357
branch.working_tree().add(['file'])
358
branch.working_tree().commit('add file')
279
branch.commit('add file')
359
280
copy_branch(branch, 'branch2')
360
print >> open('branch2/file', 'wb'), 'new content'
281
print >> open('branch2/file', 'w'), 'new content'
361
282
branch2 = Branch.open('branch2')
362
branch2.working_tree().commit('update file')
283
branch2.commit('update file')
363
284
# should open branch1 and diff against branch2,
364
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
285
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 'branch1'])
367
286
self.assertEquals(("=== modified file 'file'\n"
370
289
"@@ -1,1 +1,1 @@\n"
372
291
"+contents of branch1/file\n"
373
292
"\n", ''), output)
374
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
376
self.assertEqualDiff(("=== modified file 'file'\n"
381
"+contents of branch1/file\n"
385
294
def test_branch(self):
386
295
"""Branch from one branch to another."""
417
325
file('hello', 'wt').write('quuux')
418
326
# We can't merge when there are in-tree changes
419
self.runbzr('merge ../b', retcode=3)
327
self.runbzr('merge ../b', retcode=1)
420
328
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
421
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
423
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
424
self.runbzr('revert --no-backup')
425
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
426
self.runbzr('revert --no-backup')
427
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
428
self.runbzr('revert --no-backup')
429
self.runbzr('merge ../b -r last:1')
329
self.runbzr('merge ../b')
430
330
self.check_file_contents('goodbye', 'quux')
431
331
# Merging a branch pulls its revision into the tree
432
332
a = Branch.open('.')
433
333
b = Branch.open('../b')
434
334
a.get_revision_xml(b.last_revision())
435
self.log('pending merges: %s', a.working_tree().pending_merges())
436
self.assertEquals(a.working_tree().pending_merges(),
438
self.runbzr('commit -m merged')
439
self.runbzr('merge ../b -r last:1')
440
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
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())
442
339
def test_merge_with_missing_file(self):
443
340
"""Merge handles missing file conflicts"""
498
395
a = Branch.open('.')
499
396
b = Branch.open('../b')
500
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
397
assert a.revision_history() == b.revision_history()[:-1]
501
398
self.runbzr('pull ../b')
502
self.assertEquals(a.revision_history(), b.revision_history())
399
assert a.revision_history() == b.revision_history()
503
400
self.runbzr('commit -m blah2 --unchanged')
505
402
self.runbzr('commit -m blah3 --unchanged')
507
self.runbzr('pull ../a', retcode=3)
404
self.runbzr('pull ../a', retcode=1)
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(),
406
self.runbzr('branch b clobberme')
407
os.chdir('clobberme')
408
self.runbzr('pull --clobber ../a')
409
clobbered = Branch.open('.')
410
self.assertEqual(clobbered.revision_history(),
514
411
a.revision_history())
516
413
self.runbzr('merge ../b')
517
414
self.runbzr('commit -m blah4 --unchanged')
518
415
os.chdir('../b/subdir')
519
416
self.runbzr('pull ../../a')
520
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
417
assert a.revision_history()[-1] == b.revision_history()[-1]
521
418
self.runbzr('commit -m blah5 --unchanged')
522
419
self.runbzr('commit -m blah6 --unchanged')
529
426
self.runbzr('pull ../b')
530
427
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
429
def test_locations(self):
692
430
"""Using and remembering different locations"""
695
433
self.runbzr('init')
696
434
self.runbzr('commit -m unchanged --unchanged')
697
self.runbzr('pull', retcode=3)
698
self.runbzr('merge', retcode=3)
435
self.runbzr('pull', retcode=1)
436
self.runbzr('merge', retcode=1)
699
437
self.runbzr('branch . ../b')
701
439
self.runbzr('pull')
732
470
"""add -q does not print the names of added files."""
733
471
b = Branch.initialize('.')
734
472
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
735
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
473
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
736
474
# the ordering is not defined at the moment
737
475
results = sorted(out.rstrip('\n').split('\n'))
738
476
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
478
def test_unknown_command(self):
809
479
"""Handling of unknown command."""
810
480
out, err = self.run_bzr_captured(['fluffy-badger'],
812
482
self.assertEquals(out, '')
813
483
err.index('unknown command')
815
def create_conflicts(self):
816
"""Create a conflicted tree"""
485
def test_conflicts(self):
486
"""Handling of merge conflicts"""
819
489
file('hello', 'wb').write("hi world")
833
503
file('question', 'wb').write("What do you get when you multiply six"
835
505
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)
506
self.runbzr('merge ../other')
884
507
result = self.runbzr('conflicts', backtick=1)
885
508
self.assertEquals(result, "hello\nquestion\n")
886
509
result = self.runbzr('status', backtick=1)
887
self.assert_("conflicts:\n hello\n question\n" in result, result)
510
assert "conflicts:\n hello\n question\n" in result, result
888
511
self.runbzr('resolve hello')
889
512
result = self.runbzr('conflicts', backtick=1)
890
513
self.assertEquals(result, "question\n")
891
self.runbzr('commit -m conflicts', retcode=3)
514
self.runbzr('commit -m conflicts', retcode=1)
892
515
self.runbzr('resolve --all')
893
516
result = self.runbzr('conflicts', backtick=1)
894
517
self.runbzr('commit -m conflicts')
909
532
branch.revision_store.get('A', 'sig').read())
911
534
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
536
def listdir_sorted(dir):
1029
537
L = os.listdir(dir)
1059
567
self.assertEquals(capture('unknowns'), 'test.txt\n')
1061
569
out = capture("status")
1062
self.assertEquals(out, 'unknown:\n test.txt\n')
570
assert out == 'unknown:\n test.txt\n'
1064
572
out = capture("status --all")
1065
self.assertEquals(out, "unknown:\n test.txt\n")
573
assert out == "unknown:\n test.txt\n"
1067
575
out = capture("status test.txt --all")
1068
self.assertEquals(out, "unknown:\n test.txt\n")
576
assert out == "unknown:\n test.txt\n"
1070
578
f = file('test2.txt', 'wt')
1071
579
f.write('goodbye cruel world...\n')
1074
582
out = capture("status test.txt")
1075
self.assertEquals(out, "unknown:\n test.txt\n")
583
assert out == "unknown:\n test.txt\n"
1077
585
out = capture("status")
1078
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
586
assert out == ("unknown:\n"
1080
590
os.unlink('test2.txt')
1082
592
progress("command aliases")
1083
593
out = capture("st --all")
1084
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
594
assert out == ("unknown:\n"
1086
597
out = capture("stat")
1087
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
598
assert out == ("unknown:\n"
1089
601
progress("command help")
1090
602
runbzr("help st")
1092
604
runbzr("help commands")
1093
runbzr("help slartibartfast", 3)
605
runbzr("help slartibartfast", 1)
1095
607
out = capture("help ci")
1096
608
out.index('aliases: ')
1098
610
progress("can't rename unversioned file")
1099
runbzr("rename test.txt new-test.txt", 3)
611
runbzr("rename test.txt new-test.txt", 1)
1101
613
progress("adding a file")
1103
615
runbzr("add test.txt")
1104
self.assertEquals(capture("unknowns"), '')
1105
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
616
assert capture("unknowns") == ''
617
assert capture("status --all") == ("added:\n"
1107
620
progress("rename newly-added file")
1108
621
runbzr("rename test.txt hello.txt")
1109
self.assert_(os.path.exists("hello.txt"))
1110
self.assert_(not os.path.exists("test.txt"))
622
assert os.path.exists("hello.txt")
623
assert not os.path.exists("test.txt")
1112
self.assertEquals(capture("revno"), '0\n')
625
assert capture("revno") == '0\n'
1114
627
progress("add first revision")
1115
628
runbzr(['commit', '-m', 'add first revision'])
1117
630
progress("more complex renames")
1118
631
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)
632
runbzr("rename hello.txt sub1", 1)
633
runbzr("rename hello.txt sub1/hello.txt", 1)
634
runbzr("move hello.txt sub1", 1)
1123
636
runbzr("add sub1")
1124
637
runbzr("rename sub1 sub2")
1126
639
self.assertEqual(capture("relpath sub2/hello.txt"),
1127
640
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"))
642
assert exists("sub2")
643
assert exists("sub2/hello.txt")
644
assert not exists("sub1")
645
assert not exists("hello.txt")
1134
647
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1137
650
runbzr('add sub1')
1138
651
runbzr('move sub2/hello.txt sub1')
1139
self.assert_(not exists('sub2/hello.txt'))
1140
self.assert_(exists('sub1/hello.txt'))
652
assert not exists('sub2/hello.txt')
653
assert exists('sub1/hello.txt')
1141
654
runbzr('move sub2 sub1')
1142
self.assert_(not exists('sub2'))
1143
self.assert_(exists('sub1/sub2'))
655
assert not exists('sub2')
656
assert exists('sub1/sub2')
1145
658
runbzr(['commit', '-m', 'rename nested subdirectories'])
1148
661
self.assertEquals(capture('root')[:-1],
1149
662
os.path.join(self.test_dir, 'branch1'))
1150
663
runbzr('move ../hello.txt .')
1151
self.assert_(exists('./hello.txt'))
664
assert exists('./hello.txt')
1152
665
self.assertEquals(capture('relpath hello.txt'),
1153
666
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'))
667
assert capture('relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1155
668
runbzr(['commit', '-m', 'move to parent directory'])
1157
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
670
assert capture('relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1159
672
runbzr('move sub2/hello.txt .')
1160
self.assert_(exists('hello.txt'))
673
assert exists('hello.txt')
1162
675
f = file('hello.txt', 'wt')
1163
676
f.write('some nice new content\n')
1170
683
runbzr('commit -F msg.tmp')
1172
self.assertEquals(capture('revno'), '5\n')
685
assert capture('revno') == '5\n'
1173
686
runbzr('export -r 5 export-5.tmp')
1174
687
runbzr('export export.tmp')
1177
690
runbzr('log -v')
1178
691
runbzr('log -v --forward')
1179
runbzr('log -m', retcode=3)
692
runbzr('log -m', retcode=1)
1180
693
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'))
694
assert "this is my new commit\n and" in log_out
695
assert "rename nested" not in log_out
696
assert 'revision-id' not in log_out
697
assert 'revision-id' in capture('log --show-ids -m commit')
1186
699
log_out = capture('log --line')
1187
700
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)
701
assert len(line) <= 79, len(line)
702
assert "this is my new commit and" in log_out
1192
705
progress("file with spaces in name")
1193
706
mkdir('sub directory')
1194
707
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1196
runbzr('diff', retcode=1)
1197
710
runbzr('commit -m add-spaces')
1210
723
os.symlink("NOWHERE1", "link1")
1211
724
runbzr('add link1')
1212
self.assertEquals(self.capture('unknowns'), '')
725
assert self.capture('unknowns') == ''
1213
726
runbzr(['commit', '-m', '1: added symlink link1'])
1216
729
runbzr('add d1')
1217
self.assertEquals(self.capture('unknowns'), '')
730
assert self.capture('unknowns') == ''
1218
731
os.symlink("NOWHERE2", "d1/link2")
1219
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
732
assert self.capture('unknowns') == 'd1/link2\n'
1220
733
# is d1/link2 found when adding d1
1221
734
runbzr('add d1')
1222
self.assertEquals(self.capture('unknowns'), '')
735
assert self.capture('unknowns') == ''
1223
736
os.symlink("NOWHERE3", "d1/link3")
1224
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
737
assert self.capture('unknowns') == 'd1/link3\n'
1225
738
runbzr(['commit', '-m', '2: added dir, symlink'])
1227
740
runbzr('rename d1 d2')
1228
741
runbzr('move d2/link2 .')
1229
742
runbzr('move link1 d2')
1230
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1231
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
743
assert os.readlink("./link2") == "NOWHERE2"
744
assert os.readlink("d2/link1") == "NOWHERE1"
1232
745
runbzr('add d2/link3')
1233
runbzr('diff', retcode=1)
1234
747
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1236
749
os.unlink("link2")
1237
750
os.symlink("TARGET 2", "link2")
1238
751
os.unlink("d2/link1")
1239
752
os.symlink("TARGET 1", "d2/link1")
1240
runbzr('diff', retcode=1)
1241
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
754
assert self.capture("relpath d2/link1") == "d2/link1\n"
1242
755
runbzr(['commit', '-m', '4: retarget of two links'])
1244
757
runbzr('remove d2/link1')
1245
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
758
assert self.capture('unknowns') == 'd2/link1\n'
1246
759
runbzr(['commit', '-m', '5: remove d2/link1'])
1247
760
# try with the rm alias
1248
761
runbzr('add d2/link1')
1249
762
runbzr(['commit', '-m', '6: add d2/link1'])
1250
763
runbzr('rm d2/link1')
1251
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
764
assert self.capture('unknowns') == 'd2/link1\n'
1252
765
runbzr(['commit', '-m', '7: remove d2/link1'])
1255
768
runbzr('add d1')
1256
769
runbzr('rename d2/link3 d1/link3new')
1257
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
770
assert self.capture('unknowns') == 'd2/link1\n'
1258
771
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1260
773
runbzr(['check'])
1262
775
runbzr(['export', '-r', '1', 'exp1.tmp'])
1263
776
chdir("exp1.tmp")
1264
self.assertEquals(listdir_sorted("."), [ "link1" ])
1265
self.assertEquals(os.readlink("link1"), "NOWHERE1")
777
assert listdir_sorted(".") == [ "link1" ]
778
assert os.readlink("link1") == "NOWHERE1"
1268
781
runbzr(['export', '-r', '2', 'exp2.tmp'])
1269
782
chdir("exp2.tmp")
1270
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
783
assert listdir_sorted(".") == [ "d1", "link1" ]
1273
786
runbzr(['export', '-r', '3', 'exp3.tmp'])
1274
787
chdir("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")
788
assert listdir_sorted(".") == [ "d2", "link2" ]
789
assert listdir_sorted("d2") == [ "link1", "link3" ]
790
assert os.readlink("d2/link1") == "NOWHERE1"
791
assert os.readlink("link2") == "NOWHERE2"
1281
794
runbzr(['export', '-r', '4', 'exp4.tmp'])
1282
795
chdir("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" ])
796
assert listdir_sorted(".") == [ "d2", "link2" ]
797
assert os.readlink("d2/link1") == "TARGET 1"
798
assert os.readlink("link2") == "TARGET 2"
799
assert listdir_sorted("d2") == [ "link1", "link3" ]
1289
802
runbzr(['export', '-r', '5', 'exp5.tmp'])
1290
803
chdir("exp5.tmp")
1291
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1292
self.assert_(os.path.islink("link2"))
1293
self.assert_(listdir_sorted("d2")== [ "link3" ])
804
assert listdir_sorted(".") == [ "d2", "link2" ]
805
assert os.path.islink("link2")
806
assert listdir_sorted("d2")== [ "link3" ]
1296
809
runbzr(['export', '-r', '8', 'exp6.tmp'])
1297
810
chdir("exp6.tmp")
1298
811
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")
812
assert listdir_sorted("d1") == [ "link3new" ]
813
assert listdir_sorted("d2") == []
814
assert os.readlink("d1/link3new") == "NOWHERE3"
1304
817
progress("skipping symlink tests")