66
72
f = file('.bzr/email', 'wt')
67
73
f.write('Branch Identity <branch@identi.ty>')
69
bzr_email = os.environ.get('BZREMAIL')
70
if bzr_email is not None:
71
del os.environ['BZREMAIL']
72
75
whoami = self.runbzr("whoami",backtick=True)
73
76
whoami_email = self.runbzr("whoami --email",backtick=True)
74
77
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
75
78
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
76
# Verify that the environment variable overrides the value
78
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
79
whoami = self.runbzr("whoami",backtick=True)
80
whoami_email = self.runbzr("whoami --email",backtick=True)
81
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
82
self.assertTrue(whoami_email.startswith('other@environ.ment'))
83
if bzr_email is not None:
84
os.environ['BZREMAIL'] = bzr_email
86
def test_nick_command(self):
87
"""bzr nick for viewing, setting nicknames"""
91
nick = self.runbzr("nick",backtick=True)
92
self.assertEqual(nick, 'me.dev\n')
93
nick = self.runbzr("nick moo")
94
nick = self.runbzr("nick",backtick=True)
95
self.assertEqual(nick, 'moo\n')
97
80
def test_invalid_commands(self):
98
self.runbzr("pants", retcode=3)
99
self.runbzr("--pants off", retcode=3)
100
self.runbzr("diff --message foo", retcode=3)
81
self.runbzr("pants", retcode=1)
82
self.runbzr("--pants off", retcode=1)
83
self.runbzr("diff --message foo", retcode=1)
102
def test_remove_deleted(self):
85
def test_empty_commit(self):
103
86
self.runbzr("init")
104
self.build_tree(['a'])
105
self.runbzr(['add', 'a'])
106
self.runbzr(['commit', '-m', 'added a'])
108
self.runbzr(['remove', 'a'])
87
self.build_tree(['hello.txt'])
88
self.runbzr("commit -m empty", retcode=1)
89
self.runbzr("add hello.txt")
90
self.runbzr("commit -m added")
110
92
def test_ignore_patterns(self):
112
self.assertEquals(self.capture('unknowns'), '')
93
from bzrlib.branch import Branch
95
b = Branch('.', init=True)
96
self.assertEquals(list(b.unknowns()), [])
114
98
file('foo.tmp', 'wt').write('tmp files are ignored')
115
self.assertEquals(self.capture('unknowns'), '')
99
self.assertEquals(list(b.unknowns()), [])
100
assert self.backtick('bzr unknowns') == ''
117
102
file('foo.c', 'wt').write('int main() {}')
118
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
103
self.assertEquals(list(b.unknowns()), ['foo.c'])
104
assert self.backtick('bzr unknowns') == 'foo.c\n'
120
106
self.runbzr(['add', 'foo.c'])
121
self.assertEquals(self.capture('unknowns'), '')
107
assert self.backtick('bzr unknowns') == ''
123
109
# 'ignore' works when creating the .bzignore file
124
110
file('foo.blah', 'wt').write('blah')
125
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
111
self.assertEquals(list(b.unknowns()), ['foo.blah'])
126
112
self.runbzr('ignore *.blah')
127
self.assertEquals(self.capture('unknowns'), '')
128
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
113
self.assertEquals(list(b.unknowns()), [])
114
assert file('.bzrignore', 'rb').read() == '*.blah\n'
130
116
# 'ignore' works when then .bzrignore file already exists
131
117
file('garh', 'wt').write('garh')
132
self.assertEquals(self.capture('unknowns'), 'garh\n')
118
self.assertEquals(list(b.unknowns()), ['garh'])
119
assert self.backtick('bzr unknowns') == 'garh\n'
133
120
self.runbzr('ignore garh')
134
self.assertEquals(self.capture('unknowns'), '')
135
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
121
self.assertEquals(list(b.unknowns()), [])
122
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
137
124
def test_revert(self):
138
126
self.runbzr('init')
140
128
file('hello', 'wt').write('foo')
219
182
test.runbzr('add goodbye')
220
183
test.runbzr('commit -m setup goodbye')
222
def test_export(self):
225
self.example_branch()
226
self.runbzr('export ../latest')
227
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
228
self.runbzr('export ../first -r 1')
229
self.assert_(not os.path.exists('../first/goodbye'))
230
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
231
self.runbzr('export ../first.gz -r 1')
232
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
233
self.runbzr('export ../first.bz2 -r 1')
234
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
236
from tarfile import TarFile
237
self.runbzr('export ../first.tar -r 1')
238
self.assert_(os.path.isfile('../first.tar'))
239
tf = TarFile('../first.tar')
240
self.assert_('first/hello' in tf.getnames(), tf.getnames())
241
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
self.runbzr('export ../first.tar.gz -r 1')
243
self.assert_(os.path.isfile('../first.tar.gz'))
244
self.runbzr('export ../first.tbz2 -r 1')
245
self.assert_(os.path.isfile('../first.tbz2'))
246
self.runbzr('export ../first.tar.bz2 -r 1')
247
self.assert_(os.path.isfile('../first.tar.bz2'))
248
self.runbzr('export ../first.tar.tbz2 -r 1')
249
self.assert_(os.path.isfile('../first.tar.tbz2'))
251
from bz2 import BZ2File
252
tf = TarFile('../first.tar.tbz2',
253
fileobj=BZ2File('../first.tar.tbz2', 'r'))
254
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
255
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
256
self.runbzr('export ../first2.tar -r 1 --root pizza')
257
tf = TarFile('../first2.tar')
258
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
260
from zipfile import ZipFile
261
self.runbzr('export ../first.zip -r 1')
262
self.failUnlessExists('../first.zip')
263
zf = ZipFile('../first.zip')
264
self.assert_('first/hello' in zf.namelist(), zf.namelist())
265
self.assertEqual(zf.read('first/hello'), 'foo')
267
self.runbzr('export ../first2.zip -r 1 --root pizza')
268
zf = ZipFile('../first2.zip')
269
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
271
self.runbzr('export ../first-zip --format=zip -r 1')
272
zf = ZipFile('../first-zip')
273
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
275
def test_branch(self):
276
"""Branch from one branch to another."""
279
self.example_branch()
281
self.runbzr('branch a b')
282
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
283
self.runbzr('branch a c -r 1')
285
self.runbzr('commit -m foo --unchanged')
288
def test_branch_basis(self):
289
# ensure that basis really does grab from the basis by having incomplete source
290
tree = self.make_branch_and_tree('commit_tree')
291
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
293
tree.commit('revision 1', rev_id='1')
294
source = self.make_branch_and_tree('source')
295
# this gives us an incomplete repository
296
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
297
tree.commit('revision 2', rev_id='2', allow_pointless=True)
298
tree.bzrdir.open_branch().copy_content_into(source.branch)
299
tree.copy_content_into(source)
300
self.assertFalse(source.branch.repository.has_revision('2'))
302
self.runbzr('branch source target --basis commit_tree')
303
target = bzrdir.BzrDir.open('target')
304
self.assertEqual('2', target.open_branch().last_revision())
305
self.assertEqual('2', target.open_workingtree().last_revision())
306
self.assertTrue(target.open_branch().repository.has_revision('2'))
185
def test_revert(self):
186
self.example_branch()
187
file('hello', 'wt').write('bar')
188
file('goodbye', 'wt').write('qux')
189
self.runbzr('revert hello')
190
self.check_file_contents('hello', 'foo')
191
self.check_file_contents('goodbye', 'qux')
192
self.runbzr('revert')
193
self.check_file_contents('goodbye', 'baz')
308
195
def test_merge(self):
309
196
from bzrlib.branch import Branch
313
202
self.example_branch()
315
204
self.runbzr('branch a b')
321
210
file('hello', 'wt').write('quuux')
322
211
# We can't merge when there are in-tree changes
323
self.runbzr('merge ../b', retcode=3)
212
self.runbzr('merge ../b', retcode=1)
324
213
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
325
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
327
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
328
self.runbzr('revert --no-backup')
329
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
330
self.runbzr('revert --no-backup')
331
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
332
self.runbzr('revert --no-backup')
333
self.runbzr('merge ../b -r last:1')
214
self.runbzr('merge ../b')
334
215
self.check_file_contents('goodbye', 'quux')
335
216
# Merging a branch pulls its revision into the tree
336
a = WorkingTree.open('.')
337
b = Branch.open('../b')
338
a.branch.repository.get_revision_xml(b.last_revision())
219
a.get_revision_xml(b.last_patch())
339
221
self.log('pending merges: %s', a.pending_merges())
340
self.assertEquals(a.pending_merges(),
342
self.runbzr('commit -m merged')
343
self.runbzr('merge ../b -r last:1')
344
self.assertEqual(a.pending_merges(), [])
346
def test_merge_with_missing_file(self):
347
"""Merge handles missing file conflicts"""
351
print >> file('sub/a.txt', 'wb'), "hello"
352
print >> file('b.txt', 'wb'), "hello"
353
print >> file('sub/c.txt', 'wb'), "hello"
356
self.runbzr(('commit', '-m', 'added a'))
357
self.runbzr('branch . ../b')
358
print >> file('sub/a.txt', 'ab'), "there"
359
print >> file('b.txt', 'ab'), "there"
360
print >> file('sub/c.txt', 'ab'), "there"
361
self.runbzr(('commit', '-m', 'Added there'))
362
os.unlink('sub/a.txt')
363
os.unlink('sub/c.txt')
366
self.runbzr(('commit', '-m', 'Removed a.txt'))
368
print >> file('sub/a.txt', 'ab'), "something"
369
print >> file('b.txt', 'ab'), "something"
370
print >> file('sub/c.txt', 'ab'), "something"
371
self.runbzr(('commit', '-m', 'Modified a.txt'))
372
self.runbzr('merge ../a/', retcode=1)
373
self.assert_(os.path.exists('sub/a.txt.THIS'))
374
self.assert_(os.path.exists('sub/a.txt.BASE'))
376
self.runbzr('merge ../b/', retcode=1)
377
self.assert_(os.path.exists('sub/a.txt.OTHER'))
378
self.assert_(os.path.exists('sub/a.txt.BASE'))
380
def test_inventory(self):
382
def output_equals(value, *args):
383
out = self.runbzr(['inventory'] + list(args), backtick=True)
384
self.assertEquals(out, value)
387
open('a', 'wb').write('hello\n')
393
output_equals('a\n', '--kind', 'file')
394
output_equals('b\n', '--kind', 'directory')
397
"""Test the abilities of 'bzr ls'"""
399
def bzrout(*args, **kwargs):
400
kwargs['backtick'] = True
401
return self.runbzr(*args, **kwargs)
403
def ls_equals(value, *args):
404
out = self.runbzr(['ls'] + list(args), backtick=True)
405
self.assertEquals(out, value)
408
open('a', 'wb').write('hello\n')
411
bzr('ls --verbose --null', retcode=3)
414
ls_equals('? a\n', '--verbose')
415
ls_equals('a\n', '--unknown')
416
ls_equals('', '--ignored')
417
ls_equals('', '--versioned')
418
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
419
ls_equals('', '--ignored', '--versioned')
420
ls_equals('a\0', '--null')
423
ls_equals('V a\n', '--verbose')
430
open('subdir/b', 'wb').write('b\n')
436
bzr('commit -m subdir')
444
, '--verbose', '--non-recursive')
446
# Check what happens in a sub-directory
458
, '--from-root', '--null')
461
, '--from-root', '--non-recursive')
465
# Check what happens when we supply a specific revision
466
ls_equals('a\n', '--revision', '1')
468
, '--verbose', '--revision', '1')
471
ls_equals('', '--revision', '1')
473
# Now try to do ignored files.
475
open('blah.py', 'wb').write('unknown\n')
476
open('blah.pyo', 'wb').write('ignored\n')
488
ls_equals('blah.pyo\n'
490
ls_equals('blah.py\n'
499
file("myfile", "wb").write("My contents\n")
501
self.runbzr('commit -m myfile')
502
self.run_bzr_captured('cat -r 1 myfile'.split(' '))
504
def test_pull_verbose(self):
505
"""Pull changes from one branch to another and watch the output."""
511
self.example_branch()
516
open('b', 'wb').write('else\n')
518
bzr(['commit', '-m', 'added b'])
521
out = bzr('pull --verbose ../b', backtick=True)
522
self.failIfEqual(out.find('Added Revisions:'), -1)
523
self.failIfEqual(out.find('message:\n added b'), -1)
524
self.failIfEqual(out.find('added b'), -1)
526
# Check that --overwrite --verbose prints out the removed entries
527
bzr('commit -m foo --unchanged')
529
bzr('commit -m baz --unchanged')
530
bzr('pull ../a', retcode=3)
531
out = bzr('pull --overwrite --verbose ../a', backtick=1)
533
remove_loc = out.find('Removed Revisions:')
534
self.failIfEqual(remove_loc, -1)
535
added_loc = out.find('Added Revisions:')
536
self.failIfEqual(added_loc, -1)
538
removed_message = out.find('message:\n baz')
539
self.failIfEqual(removed_message, -1)
540
self.failUnless(remove_loc < removed_message < added_loc)
542
added_message = out.find('message:\n foo')
543
self.failIfEqual(added_message, -1)
544
self.failUnless(added_loc < added_message)
546
def test_locations(self):
547
"""Using and remembering different locations"""
551
self.runbzr('commit -m unchanged --unchanged')
552
self.runbzr('pull', retcode=3)
553
self.runbzr('merge', retcode=3)
554
self.runbzr('branch . ../b')
557
self.runbzr('branch . ../c')
558
self.runbzr('pull ../c')
561
self.runbzr('pull ../b')
563
self.runbzr('pull ../c')
564
self.runbzr('branch ../c ../d')
565
shutil.rmtree('../c')
570
self.runbzr('pull', retcode=3)
571
self.runbzr('pull ../a --remember')
222
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
# % (a.pending_merges(), b.last_patch())
574
226
def test_add_reports(self):
575
227
"""add command prints the names of added files."""
577
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
578
out = self.run_bzr_captured(['add'], retcode=0)[0]
228
b = Branch('.', init=True)
229
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
231
from cStringIO import StringIO
234
ret = self.apply_redirected(None, out, None,
237
self.assertEquals(ret, 0)
579
239
# the ordering is not defined at the moment
580
results = sorted(out.rstrip('\n').split('\n'))
581
self.assertEquals(['If you wish to add some of these files, please'\
582
' add them by name.',
240
results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
self.assertEquals(['added dir',
584
242
'added dir/sub.txt',
586
'ignored 1 file(s) matching "CVS"'],
588
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
589
results = sorted(out.rstrip('\n').split('\n'))
590
self.assertEquals(['If you wish to add some of these files, please'\
591
' add them by name.',
592
'ignored CVS matching "CVS"'],
595
def test_add_quiet_is(self):
596
"""add -q does not print the names of added files."""
598
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
599
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
600
# the ordering is not defined at the moment
601
results = sorted(out.rstrip('\n').split('\n'))
602
self.assertEquals([''], results)
604
def test_add_in_unversioned(self):
605
"""Try to add a file in an unversioned directory.
607
"bzr add" should add the parent(s) as necessary.
610
self.build_tree(['inertiatic/', 'inertiatic/esp'])
611
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
612
self.run_bzr('add', 'inertiatic/esp')
613
self.assertEquals(self.capture('unknowns'), '')
615
# Multiple unversioned parents
616
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
617
self.assertEquals(self.capture('unknowns'), 'veil\n')
618
self.run_bzr('add', 'veil/cerpin/taxt')
619
self.assertEquals(self.capture('unknowns'), '')
621
# Check whacky paths work
622
self.build_tree(['cicatriz/', 'cicatriz/esp'])
623
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
624
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
625
self.assertEquals(self.capture('unknowns'), '')
627
def test_add_in_versioned(self):
628
"""Try to add a file in a versioned directory.
630
"bzr add" should do this happily.
633
self.build_tree(['inertiatic/', 'inertiatic/esp'])
634
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
635
self.run_bzr('add', '--no-recurse', 'inertiatic')
636
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
637
self.run_bzr('add', 'inertiatic/esp')
638
self.assertEquals(self.capture('unknowns'), '')
640
def test_subdir_add(self):
641
"""Add in subdirectory should add only things from there down"""
642
from bzrlib.workingtree import WorkingTree
644
eq = self.assertEqual
648
t = self.make_branch_and_tree('.')
650
self.build_tree(['src/', 'README'])
652
eq(sorted(t.unknowns()),
655
self.run_bzr('add', 'src')
657
self.build_tree(['src/foo.c'])
662
self.assertEquals(self.capture('unknowns'), 'README\n')
663
eq(len(t.read_working_inventory()), 3)
667
self.assertEquals(self.capture('unknowns'), '')
668
self.run_bzr('check')
670
def test_unknown_command(self):
671
"""Handling of unknown command."""
672
out, err = self.run_bzr_captured(['fluffy-badger'],
674
self.assertEquals(out, '')
675
err.index('unknown command')
677
def create_conflicts(self):
678
"""Create a conflicted tree"""
681
file('hello', 'wb').write("hi world")
682
file('answer', 'wb').write("42")
685
self.runbzr('commit -m base')
686
self.runbzr('branch . ../other')
687
self.runbzr('branch . ../this')
689
file('hello', 'wb').write("Hello.")
690
file('answer', 'wb').write("Is anyone there?")
691
self.runbzr('commit -m other')
693
file('hello', 'wb').write("Hello, world")
694
self.runbzr('mv answer question')
695
file('question', 'wb').write("What do you get when you multiply six"
697
self.runbzr('commit -m this')
699
def test_remerge(self):
700
"""Remerge command works as expected"""
701
self.create_conflicts()
702
self.runbzr('merge ../other --show-base', retcode=1)
703
conflict_text = file('hello').read()
704
assert '|||||||' in conflict_text
705
assert 'hi world' in conflict_text
706
self.runbzr('remerge', retcode=1)
707
conflict_text = file('hello').read()
708
assert '|||||||' not in conflict_text
709
assert 'hi world' not in conflict_text
710
os.unlink('hello.OTHER')
711
os.unlink('question.OTHER')
712
self.runbzr('remerge jello --merge-type weave', retcode=3)
713
self.runbzr('remerge hello --merge-type weave', retcode=1)
714
assert os.path.exists('hello.OTHER')
715
self.assertIs(False, os.path.exists('question.OTHER'))
716
file_id = self.runbzr('file-id hello')
717
file_id = self.runbzr('file-id hello.THIS', retcode=3)
718
self.runbzr('remerge --merge-type weave', retcode=1)
719
assert os.path.exists('hello.OTHER')
720
assert not os.path.exists('hello.BASE')
721
assert '|||||||' not in conflict_text
722
assert 'hi world' not in conflict_text
723
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
724
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
725
self.runbzr('remerge . --show-base --reprocess', retcode=3)
726
self.runbzr('remerge hello --show-base', retcode=1)
727
self.runbzr('remerge hello --reprocess', retcode=1)
728
self.runbzr('resolve --all')
729
self.runbzr('commit -m done',)
730
self.runbzr('remerge', retcode=3)
732
def test_status(self):
736
self.runbzr('commit --unchanged --message f')
737
self.runbzr('branch . ../branch2')
738
self.runbzr('branch . ../branch3')
739
self.runbzr('commit --unchanged --message peter')
740
os.chdir('../branch2')
741
self.runbzr('merge ../branch1')
742
self.runbzr('commit --unchanged --message pumpkin')
743
os.chdir('../branch3')
744
self.runbzr('merge ../branch2')
745
message = self.capture('status')
748
def test_conflicts(self):
749
"""Handling of merge conflicts"""
750
self.create_conflicts()
751
self.runbzr('merge ../other --show-base', retcode=1)
752
conflict_text = file('hello').read()
753
self.assert_('<<<<<<<' in conflict_text)
754
self.assert_('>>>>>>>' in conflict_text)
755
self.assert_('=======' in conflict_text)
756
self.assert_('|||||||' in conflict_text)
757
self.assert_('hi world' in conflict_text)
758
self.runbzr('revert')
759
self.runbzr('resolve --all')
760
self.runbzr('merge ../other', retcode=1)
761
conflict_text = file('hello').read()
762
self.assert_('|||||||' not in conflict_text)
763
self.assert_('hi world' not in conflict_text)
764
result = self.runbzr('conflicts', backtick=1)
765
self.assertEquals(result, "Text conflict in hello\nText conflict in"
767
result = self.runbzr('status', backtick=1)
768
self.assert_("conflicts:\n Text conflict in hello\n"
769
" Text conflict in question\n" in result, result)
770
self.runbzr('resolve hello')
771
result = self.runbzr('conflicts', backtick=1)
772
self.assertEquals(result, "Text conflict in question\n")
773
self.runbzr('commit -m conflicts', retcode=3)
774
self.runbzr('resolve --all')
775
result = self.runbzr('conflicts', backtick=1)
776
self.runbzr('commit -m conflicts')
777
self.assertEquals(result, "")
780
# create a source branch
781
os.mkdir('my-branch')
782
os.chdir('my-branch')
783
self.example_branch()
785
# with no push target, fail
786
self.runbzr('push', retcode=3)
787
# with an explicit target work
788
self.runbzr('push ../output-branch')
789
# with an implicit target work
792
self.runbzr('missing ../output-branch')
793
# advance this branch
794
self.runbzr('commit --unchanged -m unchanged')
796
os.chdir('../output-branch')
797
# There is no longer a difference as long as we have
798
# access to the working tree
801
# But we should be missing a revision
802
self.runbzr('missing ../my-branch', retcode=1)
804
# diverge the branches
805
self.runbzr('commit --unchanged -m unchanged')
806
os.chdir('../my-branch')
808
self.runbzr('push', retcode=3)
809
# and there are difference
810
self.runbzr('missing ../output-branch', retcode=1)
811
self.runbzr('missing --verbose ../output-branch', retcode=1)
812
# but we can force a push
813
self.runbzr('push --overwrite')
815
self.runbzr('missing ../output-branch')
817
# pushing to a new dir with no parent should fail
818
self.runbzr('push ../missing/new-branch', retcode=3)
819
# unless we provide --create-prefix
820
self.runbzr('push --create-prefix ../missing/new-branch')
822
self.runbzr('missing ../missing/new-branch')
824
def test_external_command(self):
825
"""Test that external commands can be run by setting the path
827
# We don't at present run bzr in a subprocess for blackbox tests, and so
828
# don't really capture stdout, only the internal python stream.
829
# Therefore we don't use a subcommand that produces any output or does
830
# anything -- we just check that it can be run successfully.
831
cmd_name = 'test-command'
832
if sys.platform == 'win32':
834
oldpath = os.environ.get('BZRPATH', None)
837
if os.environ.has_key('BZRPATH'):
838
del os.environ['BZRPATH']
840
f = file(cmd_name, 'wb')
841
if sys.platform == 'win32':
842
f.write('@echo off\n')
844
f.write('#!/bin/sh\n')
845
# f.write('echo Hello from test-command')
847
os.chmod(cmd_name, 0755)
849
# It should not find the command in the local
850
# directory by default, since it is not in my path
851
bzr(cmd_name, retcode=3)
853
# Now put it into my path
854
os.environ['BZRPATH'] = '.'
858
# Make sure empty path elements are ignored
859
os.environ['BZRPATH'] = os.pathsep
861
bzr(cmd_name, retcode=3)
865
os.environ['BZRPATH'] = oldpath
868
def listdir_sorted(dir):
874
247
class OldTests(ExternalBase):
896
270
f.write('hello world!\n')
899
self.assertEquals(capture('unknowns'), 'test.txt\n')
901
out = capture("status")
902
self.assertEquals(out, 'unknown:\n test.txt\n')
904
out = capture("status --all")
905
self.assertEquals(out, "unknown:\n test.txt\n")
907
out = capture("status test.txt --all")
908
self.assertEquals(out, "unknown:\n test.txt\n")
273
out = backtick("bzr unknowns")
274
self.assertEquals(out, 'test.txt\n')
276
out = backtick("bzr status")
277
assert out == 'unknown:\n test.txt\n'
279
out = backtick("bzr status --all")
280
assert out == "unknown:\n test.txt\n"
282
out = backtick("bzr status test.txt --all")
283
assert out == "unknown:\n test.txt\n"
910
285
f = file('test2.txt', 'wt')
911
286
f.write('goodbye cruel world...\n')
914
out = capture("status test.txt")
915
self.assertEquals(out, "unknown:\n test.txt\n")
289
out = backtick("bzr status test.txt")
290
assert out == "unknown:\n test.txt\n"
917
out = capture("status")
918
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
292
out = backtick("bzr status")
293
assert out == ("unknown:\n"
920
297
os.unlink('test2.txt')
922
299
progress("command aliases")
923
out = capture("st --all")
924
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
300
out = backtick("bzr st --all")
301
assert out == ("unknown:\n"
926
out = capture("stat")
927
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
304
out = backtick("bzr stat")
305
assert out == ("unknown:\n"
929
308
progress("command help")
930
309
runbzr("help st")
932
311
runbzr("help commands")
933
runbzr("help slartibartfast", 3)
312
runbzr("help slartibartfast", 1)
935
out = capture("help ci")
314
out = backtick("bzr help ci")
936
315
out.index('aliases: ')
938
317
progress("can't rename unversioned file")
939
runbzr("rename test.txt new-test.txt", 3)
318
runbzr("rename test.txt new-test.txt", 1)
941
320
progress("adding a file")
943
322
runbzr("add test.txt")
944
self.assertEquals(capture("unknowns"), '')
945
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
323
assert backtick("bzr unknowns") == ''
324
assert backtick("bzr status --all") == ("added:\n"
947
327
progress("rename newly-added file")
948
328
runbzr("rename test.txt hello.txt")
949
self.assert_(os.path.exists("hello.txt"))
950
self.assert_(not os.path.exists("test.txt"))
329
assert os.path.exists("hello.txt")
330
assert not os.path.exists("test.txt")
952
self.assertEquals(capture("revno"), '0\n')
332
assert backtick("bzr revno") == '0\n'
954
334
progress("add first revision")
955
335
runbzr(['commit', '-m', 'add first revision'])
957
337
progress("more complex renames")
959
runbzr("rename hello.txt sub1", 3)
960
runbzr("rename hello.txt sub1/hello.txt", 3)
961
runbzr("move hello.txt sub1", 3)
339
runbzr("rename hello.txt sub1", 1)
340
runbzr("rename hello.txt sub1/hello.txt", 1)
341
runbzr("move hello.txt sub1", 1)
963
343
runbzr("add sub1")
964
344
runbzr("rename sub1 sub2")
965
345
runbzr("move hello.txt sub2")
966
self.assertEqual(capture("relpath sub2/hello.txt"),
967
pathjoin("sub2", "hello.txt\n"))
346
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
969
self.assert_(exists("sub2"))
970
self.assert_(exists("sub2/hello.txt"))
971
self.assert_(not exists("sub1"))
972
self.assert_(not exists("hello.txt"))
348
assert exists("sub2")
349
assert exists("sub2/hello.txt")
350
assert not exists("sub1")
351
assert not exists("hello.txt")
974
353
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
977
356
runbzr('add sub1')
978
357
runbzr('move sub2/hello.txt sub1')
979
self.assert_(not exists('sub2/hello.txt'))
980
self.assert_(exists('sub1/hello.txt'))
358
assert not exists('sub2/hello.txt')
359
assert exists('sub1/hello.txt')
981
360
runbzr('move sub2 sub1')
982
self.assert_(not exists('sub2'))
983
self.assert_(exists('sub1/sub2'))
361
assert not exists('sub2')
362
assert exists('sub1/sub2')
985
364
runbzr(['commit', '-m', 'rename nested subdirectories'])
987
366
chdir('sub1/sub2')
988
self.assertEquals(capture('root')[:-1],
989
pathjoin(self.test_dir, 'branch1'))
367
self.assertEquals(backtick('bzr root')[:-1],
368
os.path.join(self.test_dir, 'branch1'))
990
369
runbzr('move ../hello.txt .')
991
self.assert_(exists('./hello.txt'))
992
self.assertEquals(capture('relpath hello.txt'),
993
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
994
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
370
assert exists('./hello.txt')
371
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
372
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
995
373
runbzr(['commit', '-m', 'move to parent directory'])
997
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
375
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
999
377
runbzr('move sub2/hello.txt .')
1000
self.assert_(exists('hello.txt'))
378
assert exists('hello.txt')
1002
380
f = file('hello.txt', 'wt')
1003
381
f.write('some nice new content\n')
1006
384
f = file('msg.tmp', 'wt')
1007
f.write('this is my new commit\nand it has multiple lines, for fun')
385
f.write('this is my new commit\n')
1010
388
runbzr('commit -F msg.tmp')
1012
self.assertEquals(capture('revno'), '5\n')
390
assert backtick('bzr revno') == '5\n'
1013
391
runbzr('export -r 5 export-5.tmp')
1014
392
runbzr('export export.tmp')
1017
395
runbzr('log -v')
1018
396
runbzr('log -v --forward')
1019
runbzr('log -m', retcode=3)
1020
log_out = capture('log -m commit')
1021
self.assert_("this is my new commit\n and" in log_out)
1022
self.assert_("rename nested" not in log_out)
1023
self.assert_('revision-id' not in log_out)
1024
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1026
log_out = capture('log --line')
1027
for line in log_out.splitlines():
1028
self.assert_(len(line) <= 79, len(line))
1029
self.assert_("this is my new commit and" in log_out)
397
runbzr('log -m', retcode=1)
398
log_out = backtick('bzr log -m commit')
399
assert "this is my new commit" in log_out
400
assert "rename nested" not in log_out
401
assert 'revision-id' not in log_out
402
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1032
405
progress("file with spaces in name")
1033
406
mkdir('sub directory')
1034
407
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1036
runbzr('diff', retcode=1)
1037
410
runbzr('commit -m add-spaces')
1046
progress("symlinks")
1050
os.symlink("NOWHERE1", "link1")
1052
self.assertEquals(self.capture('unknowns'), '')
1053
runbzr(['commit', '-m', '1: added symlink link1'])
1057
self.assertEquals(self.capture('unknowns'), '')
1058
os.symlink("NOWHERE2", "d1/link2")
1059
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1060
# is d1/link2 found when adding d1
1062
self.assertEquals(self.capture('unknowns'), '')
1063
os.symlink("NOWHERE3", "d1/link3")
1064
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1065
runbzr(['commit', '-m', '2: added dir, symlink'])
1067
runbzr('rename d1 d2')
1068
runbzr('move d2/link2 .')
1069
runbzr('move link1 d2')
1070
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1071
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1072
runbzr('add d2/link3')
1073
runbzr('diff', retcode=1)
1074
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1077
os.symlink("TARGET 2", "link2")
1078
os.unlink("d2/link1")
1079
os.symlink("TARGET 1", "d2/link1")
1080
runbzr('diff', retcode=1)
1081
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1082
runbzr(['commit', '-m', '4: retarget of two links'])
1084
runbzr('remove d2/link1')
1085
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1086
runbzr(['commit', '-m', '5: remove d2/link1'])
1087
# try with the rm alias
1088
runbzr('add d2/link1')
1089
runbzr(['commit', '-m', '6: add d2/link1'])
1090
runbzr('rm d2/link1')
1091
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1092
runbzr(['commit', '-m', '7: remove d2/link1'])
1096
runbzr('rename d2/link3 d1/link3new')
1097
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1098
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1102
runbzr(['export', '-r', '1', 'exp1.tmp'])
1104
self.assertEquals(listdir_sorted("."), [ "link1" ])
1105
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1108
runbzr(['export', '-r', '2', 'exp2.tmp'])
1110
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1113
runbzr(['export', '-r', '3', 'exp3.tmp'])
1115
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1116
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1117
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1118
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1121
runbzr(['export', '-r', '4', 'exp4.tmp'])
1123
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1124
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1125
self.assertEquals(os.readlink("link2") , "TARGET 2")
1126
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1129
runbzr(['export', '-r', '5', 'exp5.tmp'])
1131
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1132
self.assert_(os.path.islink("link2"))
1133
self.assert_(listdir_sorted("d2")== [ "link3" ])
1136
runbzr(['export', '-r', '8', 'exp6.tmp'])
1138
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1139
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1140
self.assertEquals(listdir_sorted("d2"), [])
1141
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1144
progress("skipping symlink tests")
1147
class RemoteTests(object):
1148
"""Test bzr ui commands against remote branches."""
1150
def test_branch(self):
1152
wt = self.make_branch_and_tree('from')
1154
wt.commit('empty commit for nonsense', allow_pointless=True)
1155
url = self.get_readonly_url('from')
1156
self.run_bzr('branch', url, 'to')
1157
branch = Branch.open('to')
1158
self.assertEqual(1, len(branch.revision_history()))
1159
# the branch should be set in to to from
1160
self.assertEqual(url + '/', branch.get_parent())
1163
self.build_tree(['branch/', 'branch/file'])
1164
self.capture('init branch')
1165
self.capture('add branch/file')
1166
self.capture('commit -m foo branch')
1167
url = self.get_readonly_url('branch/file')
1168
output = self.capture('log %s' % url)
1169
self.assertEqual(8, len(output.split('\n')))
1171
def test_check(self):
1172
self.build_tree(['branch/', 'branch/file'])
1173
self.capture('init branch')
1174
self.capture('add branch/file')
1175
self.capture('commit -m foo branch')
1176
url = self.get_readonly_url('branch/')
1177
self.run_bzr('check', url)
1179
def test_push(self):
1180
# create a source branch
1181
os.mkdir('my-branch')
1182
os.chdir('my-branch')
1183
self.run_bzr('init')
1184
file('hello', 'wt').write('foo')
1185
self.run_bzr('add', 'hello')
1186
self.run_bzr('commit', '-m', 'setup')
1188
# with an explicit target work
1189
self.run_bzr('push', self.get_url('output-branch'))
1192
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1193
"""Test various commands against a HTTP server."""
1196
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1197
"""Test various commands against a SFTP server using abs paths."""
1200
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1201
"""Test various commands against a SFTP server using abs paths."""
1204
super(SFTPTestsAbsoluteSibling, self).setUp()
1205
self._override_home = '/dev/noone/runs/tests/here'
1208
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1209
"""Test various commands against a SFTP server using homedir rel paths."""
1212
super(SFTPTestsRelative, self).setUp()
1213
self._get_remote_is_absolute = False