77
129
self.assertEquals(self.runbzr("whoami --email",
78
130
backtick=True).count('@'), 1)
80
def test_whoami_branch(self):
81
"""branch specific user identity works."""
132
class UserIdentityBranch(ExternalBase):
134
# tests branch specific user identity
82
135
self.runbzr('init')
83
136
f = file('.bzr/email', 'wt')
84
137
f.write('Branch Identity <branch@identi.ty>')
86
bzr_email = os.environ.get('BZREMAIL')
87
if bzr_email is not None:
88
del os.environ['BZREMAIL']
89
139
whoami = self.runbzr("whoami",backtick=True)
90
140
whoami_email = self.runbzr("whoami --email",backtick=True)
91
141
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
92
142
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
93
# Verify that the environment variable overrides the value
95
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
96
whoami = self.runbzr("whoami",backtick=True)
97
whoami_email = self.runbzr("whoami --email",backtick=True)
98
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
99
self.assertTrue(whoami_email.startswith('other@environ.ment'))
100
if bzr_email is not None:
101
os.environ['BZREMAIL'] = bzr_email
103
def test_nick_command(self):
104
"""bzr nick for viewing, setting nicknames"""
108
nick = self.runbzr("nick",backtick=True)
109
self.assertEqual(nick, 'me.dev\n')
110
nick = self.runbzr("nick moo")
111
nick = self.runbzr("nick",backtick=True)
112
self.assertEqual(nick, 'moo\n')
115
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)
120
def test_empty_commit(self):
145
class InvalidCommands(ExternalBase):
147
self.runbzr("pants", retcode=1)
148
self.runbzr("--pants off", retcode=1)
149
self.runbzr("diff --message foo", retcode=1)
153
class EmptyCommit(ExternalBase):
121
155
self.runbzr("init")
122
156
self.build_tree(['hello.txt'])
123
self.runbzr("commit -m empty", retcode=3)
157
self.runbzr("commit -m empty", retcode=1)
124
158
self.runbzr("add hello.txt")
125
self.runbzr("commit -m added")
127
def test_empty_commit_message(self):
129
file('foo.c', 'wt').write('int main() {}')
130
self.runbzr(['add', 'foo.c'])
131
self.runbzr(["commit", "-m", ""] , retcode=3)
133
def test_remove_deleted(self):
135
self.build_tree(['a'])
136
self.runbzr(['add', 'a'])
137
self.runbzr(['commit', '-m', 'added a'])
139
self.runbzr(['remove', 'a'])
141
def test_other_branch_commit(self):
142
# this branch is to ensure consistent behaviour, whether we're run
143
# inside a branch, or not.
144
os.mkdir('empty_branch')
145
os.chdir('empty_branch')
150
file('foo.c', 'wt').write('int main() {}')
151
file('bar.c', 'wt').write('int main() {}')
153
self.runbzr(['add', 'branch/foo.c'])
154
self.runbzr(['add', 'branch'])
155
# can't commit files in different trees; sane error
156
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
157
self.runbzr('commit -m newstuff branch/foo.c')
158
self.runbzr('commit -m newstuff branch')
159
self.runbzr('commit -m newstuff branch', retcode=3)
161
def test_ignore_patterns(self):
159
self.runbzr("commit -m added")
163
class IgnorePatterns(ExternalBase):
162
165
from bzrlib.branch import Branch
163
Branch.initialize('.')
164
self.assertEquals(self.capture('unknowns'), '')
167
b = Branch('.', init=True)
168
self.assertEquals(list(b.unknowns()), [])
166
170
file('foo.tmp', 'wt').write('tmp files are ignored')
167
self.assertEquals(self.capture('unknowns'), '')
171
self.assertEquals(list(b.unknowns()), [])
172
assert self.backtick('bzr unknowns') == ''
169
174
file('foo.c', 'wt').write('int main() {}')
170
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
175
self.assertEquals(list(b.unknowns()), ['foo.c'])
176
assert self.backtick('bzr unknowns') == 'foo.c\n'
172
178
self.runbzr(['add', 'foo.c'])
173
self.assertEquals(self.capture('unknowns'), '')
179
assert self.backtick('bzr unknowns') == ''
175
181
# 'ignore' works when creating the .bzignore file
176
182
file('foo.blah', 'wt').write('blah')
177
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
183
self.assertEquals(list(b.unknowns()), ['foo.blah'])
178
184
self.runbzr('ignore *.blah')
179
self.assertEquals(self.capture('unknowns'), '')
180
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
185
self.assertEquals(list(b.unknowns()), [])
186
assert file('.bzrignore', 'rb').read() == '*.blah\n'
182
188
# 'ignore' works when then .bzrignore file already exists
183
189
file('garh', 'wt').write('garh')
184
self.assertEquals(self.capture('unknowns'), 'garh\n')
190
self.assertEquals(list(b.unknowns()), ['garh'])
191
assert self.backtick('bzr unknowns') == 'garh\n'
185
192
self.runbzr('ignore garh')
186
self.assertEquals(self.capture('unknowns'), '')
187
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
189
def test_revert(self):
192
file('hello', 'wt').write('foo')
193
self.runbzr('add hello')
194
self.runbzr('commit -m setup hello')
196
file('goodbye', 'wt').write('baz')
197
self.runbzr('add goodbye')
198
self.runbzr('commit -m setup goodbye')
200
file('hello', 'wt').write('bar')
201
file('goodbye', 'wt').write('qux')
202
self.runbzr('revert hello')
203
self.check_file_contents('hello', 'foo')
204
self.check_file_contents('goodbye', 'qux')
205
self.runbzr('revert')
206
self.check_file_contents('goodbye', 'baz')
208
os.mkdir('revertdir')
209
self.runbzr('add revertdir')
210
self.runbzr('commit -m f')
211
os.rmdir('revertdir')
212
self.runbzr('revert')
214
os.symlink('/unlikely/to/exist', 'symlink')
215
self.runbzr('add symlink')
216
self.runbzr('commit -m f')
218
self.runbzr('revert')
219
self.failUnlessExists('symlink')
221
os.symlink('a-different-path', 'symlink')
222
self.runbzr('revert')
223
self.assertEqual('/unlikely/to/exist',
224
os.readlink('symlink'))
226
file('hello', 'wt').write('xyz')
227
self.runbzr('commit -m xyz hello')
228
self.runbzr('revert -r 1 hello')
229
self.check_file_contents('hello', 'foo')
230
self.runbzr('revert hello')
231
self.check_file_contents('hello', 'xyz')
232
os.chdir('revertdir')
233
self.runbzr('revert')
236
def test_status(self):
238
self.build_tree(['hello.txt'])
239
result = self.runbzr("status")
240
self.assert_("unknown:\n hello.txt\n" in result, result)
241
self.runbzr("add hello.txt")
242
result = self.runbzr("status")
243
self.assert_("added:\n hello.txt\n" in result, result)
244
self.runbzr("commit -m added")
245
result = self.runbzr("status -r 0..1")
246
self.assert_("added:\n hello.txt\n" in result, result)
247
self.build_tree(['world.txt'])
248
result = self.runbzr("status -r 0")
249
self.assert_("added:\n hello.txt\n" \
250
"unknown:\n world.txt\n" in result, result)
252
def test_mv_modes(self):
253
"""Test two modes of operation for mv"""
254
from bzrlib.branch import Branch
255
b = Branch.initialize('.')
256
self.build_tree(['a', 'c', 'subdir/'])
257
self.run_bzr_captured(['add', self.test_dir])
258
self.run_bzr_captured(['mv', 'a', 'b'])
259
self.run_bzr_captured(['mv', 'b', 'subdir'])
260
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
261
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
262
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
264
def test_main_version(self):
265
"""Check output from version command and master option is reasonable"""
266
# output is intentionally passed through to stdout so that we
267
# can see the version being tested
268
output = self.runbzr('version', backtick=1)
269
self.log('bzr version output:')
271
self.assert_(output.startswith('bzr (bazaar-ng) '))
272
self.assertNotEqual(output.index('Canonical'), -1)
273
# make sure --version is consistent
274
tmp_output = self.runbzr('--version', backtick=1)
275
self.log('bzr --version output:')
277
self.assertEquals(output, tmp_output)
279
def example_branch(test):
281
file('hello', 'wt').write('foo')
282
test.runbzr('add hello')
283
test.runbzr('commit -m setup hello')
284
file('goodbye', 'wt').write('baz')
285
test.runbzr('add goodbye')
286
test.runbzr('commit -m setup goodbye')
288
def test_export(self):
291
self.example_branch()
292
self.runbzr('export ../latest')
293
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
294
self.runbzr('export ../first -r 1')
295
self.assert_(not os.path.exists('../first/goodbye'))
296
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
297
self.runbzr('export ../first.gz -r 1')
298
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
299
self.runbzr('export ../first.bz2 -r 1')
300
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
302
from tarfile import TarFile
303
self.runbzr('export ../first.tar -r 1')
304
self.assert_(os.path.isfile('../first.tar'))
305
tf = TarFile('../first.tar')
306
self.assert_('first/hello' in tf.getnames(), tf.getnames())
307
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
308
self.runbzr('export ../first.tar.gz -r 1')
309
self.assert_(os.path.isfile('../first.tar.gz'))
310
self.runbzr('export ../first.tbz2 -r 1')
311
self.assert_(os.path.isfile('../first.tbz2'))
312
self.runbzr('export ../first.tar.bz2 -r 1')
313
self.assert_(os.path.isfile('../first.tar.bz2'))
314
self.runbzr('export ../first.tar.tbz2 -r 1')
315
self.assert_(os.path.isfile('../first.tar.tbz2'))
317
from bz2 import BZ2File
318
tf = TarFile('../first.tar.tbz2',
319
fileobj=BZ2File('../first.tar.tbz2', 'r'))
320
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
321
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
322
self.runbzr('export ../first2.tar -r 1 --root pizza')
323
tf = TarFile('../first2.tar')
324
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
326
from zipfile import ZipFile
327
self.runbzr('export ../first.zip -r 1')
328
self.failUnlessExists('../first.zip')
329
zf = ZipFile('../first.zip')
330
self.assert_('first/hello' in zf.namelist(), zf.namelist())
331
self.assertEqual(zf.read('first/hello'), 'foo')
333
self.runbzr('export ../first2.zip -r 1 --root pizza')
334
zf = ZipFile('../first2.zip')
335
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
337
self.runbzr('export ../first-zip --format=zip -r 1')
338
zf = ZipFile('../first-zip')
339
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
342
self.example_branch()
343
file('hello', 'wt').write('hello world!')
344
self.runbzr('commit -m fixing hello')
345
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
346
self.assert_('\n+hello world!' in output)
347
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
348
self.assert_('\n+baz' in output)
349
file('moo', 'wb').write('moo')
350
self.runbzr('add moo')
354
def test_diff_branches(self):
355
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
356
branch = Branch.initialize('branch1')
357
branch.working_tree().add(['file'])
358
branch.working_tree().commit('add file')
359
copy_branch(branch, 'branch2')
360
print >> open('branch2/file', 'wb'), 'new content'
361
branch2 = Branch.open('branch2')
362
branch2.working_tree().commit('update file')
363
# should open branch1 and diff against branch2,
364
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
367
self.assertEquals(("=== modified file 'file'\n"
372
"+contents of branch1/file\n"
374
output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
376
self.assertEqualDiff(("=== modified file 'file'\n"
381
"+contents of branch1/file\n"
385
def test_branch(self):
386
"""Branch from one branch to another."""
389
self.example_branch()
391
self.runbzr('branch a b')
392
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
393
self.runbzr('branch a c -r 1')
395
self.runbzr('commit -m foo --unchanged')
397
# naughty - abstraction violations RBC 20050928
398
print "test_branch used to delete the stores, how is this meant to work ?"
399
#shutil.rmtree('a/.bzr/revision-store')
400
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
401
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
402
self.runbzr('branch a d --basis b')
404
def test_merge(self):
405
from bzrlib.branch import Branch
409
self.example_branch()
411
self.runbzr('branch a b')
413
file('goodbye', 'wt').write('quux')
414
self.runbzr(['commit', '-m', "more u's are always good"])
417
file('hello', 'wt').write('quuux')
418
# We can't merge when there are in-tree changes
419
self.runbzr('merge ../b', retcode=3)
420
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')
430
self.check_file_contents('goodbye', 'quux')
431
# Merging a branch pulls its revision into the tree
433
b = Branch.open('../b')
434
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(), [])
442
def test_merge_with_missing_file(self):
443
"""Merge handles missing file conflicts"""
447
print >> file('sub/a.txt', 'wb'), "hello"
448
print >> file('b.txt', 'wb'), "hello"
449
print >> file('sub/c.txt', 'wb'), "hello"
452
self.runbzr(('commit', '-m', 'added a'))
453
self.runbzr('branch . ../b')
454
print >> file('sub/a.txt', 'ab'), "there"
455
print >> file('b.txt', 'ab'), "there"
456
print >> file('sub/c.txt', 'ab'), "there"
457
self.runbzr(('commit', '-m', 'Added there'))
458
os.unlink('sub/a.txt')
459
os.unlink('sub/c.txt')
462
self.runbzr(('commit', '-m', 'Removed a.txt'))
464
print >> file('sub/a.txt', 'ab'), "something"
465
print >> file('b.txt', 'ab'), "something"
466
print >> file('sub/c.txt', 'ab'), "something"
467
self.runbzr(('commit', '-m', 'Modified a.txt'))
468
self.runbzr('merge ../a/', retcode=1)
469
self.assert_(os.path.exists('sub/a.txt.THIS'))
470
self.assert_(os.path.exists('sub/a.txt.BASE'))
472
self.runbzr('merge ../b/', retcode=1)
473
self.assert_(os.path.exists('sub/a.txt.OTHER'))
474
self.assert_(os.path.exists('sub/a.txt.BASE'))
477
"""Pull changes from one branch to another."""
481
self.example_branch()
482
self.runbzr('pull', retcode=3)
483
self.runbzr('missing', retcode=3)
484
self.runbzr('missing .')
485
self.runbzr('missing')
487
self.runbzr('pull /', retcode=3)
491
self.runbzr('branch a b')
495
self.runbzr('add subdir')
496
self.runbzr('commit -m blah --unchanged')
499
b = Branch.open('../b')
500
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
501
self.runbzr('pull ../b')
502
self.assertEquals(a.revision_history(), b.revision_history())
503
self.runbzr('commit -m blah2 --unchanged')
505
self.runbzr('commit -m blah3 --unchanged')
507
self.runbzr('pull ../a', retcode=3)
509
self.runbzr('branch b overwriteme')
510
os.chdir('overwriteme')
511
self.runbzr('pull --overwrite ../a')
512
overwritten = Branch.open('.')
513
self.assertEqual(overwritten.revision_history(),
514
a.revision_history())
516
self.runbzr('merge ../b')
517
self.runbzr('commit -m blah4 --unchanged')
518
os.chdir('../b/subdir')
519
self.runbzr('pull ../../a')
520
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
521
self.runbzr('commit -m blah5 --unchanged')
522
self.runbzr('commit -m blah6 --unchanged')
524
self.runbzr('pull ../a')
526
self.runbzr('commit -m blah7 --unchanged')
527
self.runbzr('merge ../b')
528
self.runbzr('commit -m blah8 --unchanged')
529
self.runbzr('pull ../b')
530
self.runbzr('pull ../b')
532
def test_inventory(self):
534
def output_equals(value, *args):
535
out = self.runbzr(['inventory'] + list(args), backtick=True)
536
self.assertEquals(out, value)
539
open('a', 'wb').write('hello\n')
545
output_equals('a\n', '--kind', 'file')
546
output_equals('b\n', '--kind', 'directory')
549
"""Test the abilities of 'bzr ls'"""
551
def bzrout(*args, **kwargs):
552
kwargs['backtick'] = True
553
return self.runbzr(*args, **kwargs)
555
def ls_equals(value, *args):
556
out = self.runbzr(['ls'] + list(args), backtick=True)
557
self.assertEquals(out, value)
560
open('a', 'wb').write('hello\n')
563
bzr('ls --verbose --null', retcode=3)
566
ls_equals('? a\n', '--verbose')
567
ls_equals('a\n', '--unknown')
568
ls_equals('', '--ignored')
569
ls_equals('', '--versioned')
570
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
571
ls_equals('', '--ignored', '--versioned')
572
ls_equals('a\0', '--null')
575
ls_equals('V a\n', '--verbose')
582
open('subdir/b', 'wb').write('b\n')
588
bzr('commit -m subdir')
596
, '--verbose', '--non-recursive')
598
# Check what happens in a sub-directory
610
, '--from-root', '--null')
613
, '--from-root', '--non-recursive')
617
# Check what happens when we supply a specific revision
618
ls_equals('a\n', '--revision', '1')
620
, '--verbose', '--revision', '1')
623
ls_equals('', '--revision', '1')
625
# Now try to do ignored files.
627
open('blah.py', 'wb').write('unknown\n')
628
open('blah.pyo', 'wb').write('ignored\n')
640
ls_equals('blah.pyo\n'
642
ls_equals('blah.py\n'
649
def test_pull_verbose(self):
650
"""Pull changes from one branch to another and watch the output."""
656
self.example_branch()
661
open('b', 'wb').write('else\n')
663
bzr(['commit', '-m', 'added b'])
666
out = bzr('pull --verbose ../b', backtick=True)
667
self.failIfEqual(out.find('Added Revisions:'), -1)
668
self.failIfEqual(out.find('message:\n added b'), -1)
669
self.failIfEqual(out.find('added b'), -1)
671
# Check that --overwrite --verbose prints out the removed entries
672
bzr('commit -m foo --unchanged')
674
bzr('commit -m baz --unchanged')
675
bzr('pull ../a', retcode=3)
676
out = bzr('pull --overwrite --verbose ../a', backtick=1)
678
remove_loc = out.find('Removed Revisions:')
679
self.failIfEqual(remove_loc, -1)
680
added_loc = out.find('Added Revisions:')
681
self.failIfEqual(added_loc, -1)
683
removed_message = out.find('message:\n baz')
684
self.failIfEqual(removed_message, -1)
685
self.failUnless(remove_loc < removed_message < added_loc)
687
added_message = out.find('message:\n foo')
688
self.failIfEqual(added_message, -1)
689
self.failUnless(added_loc < added_message)
691
def test_locations(self):
692
"""Using and remembering different locations"""
696
self.runbzr('commit -m unchanged --unchanged')
697
self.runbzr('pull', retcode=3)
698
self.runbzr('merge', retcode=3)
699
self.runbzr('branch . ../b')
702
self.runbzr('branch . ../c')
703
self.runbzr('pull ../c')
706
self.runbzr('pull ../b')
708
self.runbzr('pull ../c')
709
self.runbzr('branch ../c ../d')
710
shutil.rmtree('../c')
715
self.runbzr('pull', retcode=3)
716
self.runbzr('pull ../a --remember')
719
def test_add_reports(self):
720
"""add command prints the names of added files."""
721
b = Branch.initialize('.')
722
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
723
out = self.run_bzr_captured(['add'], retcode=0)[0]
724
# the ordering is not defined at the moment
725
results = sorted(out.rstrip('\n').split('\n'))
726
self.assertEquals(['added dir',
727
'added dir'+os.sep+'sub.txt',
731
def test_add_quiet_is(self):
732
"""add -q does not print the names of added files."""
733
b = Branch.initialize('.')
734
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
735
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
736
# the ordering is not defined at the moment
737
results = sorted(out.rstrip('\n').split('\n'))
738
self.assertEquals([''], results)
740
def test_add_in_unversioned(self):
741
"""Try to add a file in an unversioned directory.
743
"bzr add" should add the parent(s) as necessary.
745
from bzrlib.branch import Branch
746
Branch.initialize('.')
747
self.build_tree(['inertiatic/', 'inertiatic/esp'])
748
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
749
self.run_bzr('add', 'inertiatic/esp')
750
self.assertEquals(self.capture('unknowns'), '')
752
# Multiple unversioned parents
753
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
754
self.assertEquals(self.capture('unknowns'), 'veil\n')
755
self.run_bzr('add', 'veil/cerpin/taxt')
756
self.assertEquals(self.capture('unknowns'), '')
758
# Check whacky paths work
759
self.build_tree(['cicatriz/', 'cicatriz/esp'])
760
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
761
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
762
self.assertEquals(self.capture('unknowns'), '')
764
def test_add_in_versioned(self):
765
"""Try to add a file in a versioned directory.
767
"bzr add" should do this happily.
769
from bzrlib.branch import Branch
770
Branch.initialize('.')
771
self.build_tree(['inertiatic/', 'inertiatic/esp'])
772
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
773
self.run_bzr('add', '--no-recurse', 'inertiatic')
774
self.assertEquals(self.capture('unknowns'), 'inertiatic'+os.sep+'esp\n')
775
self.run_bzr('add', 'inertiatic/esp')
776
self.assertEquals(self.capture('unknowns'), '')
778
def test_subdir_add(self):
779
"""Add in subdirectory should add only things from there down"""
780
from bzrlib.branch import Branch
782
eq = self.assertEqual
786
b = Branch.initialize('.')
788
self.build_tree(['src/', 'README'])
790
eq(sorted(t.unknowns()),
793
self.run_bzr('add', 'src')
795
self.build_tree(['src/foo.c'])
800
self.assertEquals(self.capture('unknowns'), 'README\n')
801
eq(len(t.read_working_inventory()), 3)
805
self.assertEquals(self.capture('unknowns'), '')
806
self.run_bzr('check')
808
def test_unknown_command(self):
809
"""Handling of unknown command."""
810
out, err = self.run_bzr_captured(['fluffy-badger'],
812
self.assertEquals(out, '')
813
err.index('unknown command')
815
def create_conflicts(self):
816
"""Create a conflicted tree"""
819
file('hello', 'wb').write("hi world")
820
file('answer', 'wb').write("42")
823
self.runbzr('commit -m base')
824
self.runbzr('branch . ../other')
825
self.runbzr('branch . ../this')
827
file('hello', 'wb').write("Hello.")
828
file('answer', 'wb').write("Is anyone there?")
829
self.runbzr('commit -m other')
831
file('hello', 'wb').write("Hello, world")
832
self.runbzr('mv answer question')
833
file('question', 'wb').write("What do you get when you multiply six"
835
self.runbzr('commit -m this')
837
def test_remerge(self):
838
"""Remerge command works as expected"""
839
self.create_conflicts()
840
self.runbzr('merge ../other --show-base', retcode=1)
841
conflict_text = file('hello').read()
842
assert '|||||||' in conflict_text
843
assert 'hi world' in conflict_text
844
self.runbzr('remerge', retcode=1)
845
conflict_text = file('hello').read()
846
assert '|||||||' not in conflict_text
847
assert 'hi world' not in conflict_text
848
os.unlink('hello.OTHER')
849
self.runbzr('remerge hello --merge-type weave', retcode=1)
850
assert os.path.exists('hello.OTHER')
851
file_id = self.runbzr('file-id hello')
852
file_id = self.runbzr('file-id hello.THIS', retcode=3)
853
self.runbzr('remerge --merge-type weave', retcode=1)
854
assert os.path.exists('hello.OTHER')
855
assert not os.path.exists('hello.BASE')
856
assert '|||||||' not in conflict_text
857
assert 'hi world' not in conflict_text
858
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
859
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
860
self.runbzr('remerge . --show-base --reprocess', retcode=3)
861
self.runbzr('remerge hello --show-base', retcode=1)
862
self.runbzr('remerge hello --reprocess', retcode=1)
863
self.runbzr('resolve --all')
864
self.runbzr('commit -m done',)
865
self.runbzr('remerge', retcode=3)
868
def test_conflicts(self):
869
"""Handling of merge conflicts"""
870
self.create_conflicts()
871
self.runbzr('merge ../other --show-base', retcode=1)
872
conflict_text = file('hello').read()
873
self.assert_('<<<<<<<' in conflict_text)
874
self.assert_('>>>>>>>' in conflict_text)
875
self.assert_('=======' in conflict_text)
876
self.assert_('|||||||' in conflict_text)
877
self.assert_('hi world' in conflict_text)
878
self.runbzr('revert')
879
self.runbzr('resolve --all')
880
self.runbzr('merge ../other', retcode=1)
881
conflict_text = file('hello').read()
882
self.assert_('|||||||' not in conflict_text)
883
self.assert_('hi world' not in conflict_text)
884
result = self.runbzr('conflicts', backtick=1)
885
self.assertEquals(result, "hello\nquestion\n")
886
result = self.runbzr('status', backtick=1)
887
self.assert_("conflicts:\n hello\n question\n" in result, result)
888
self.runbzr('resolve hello')
889
result = self.runbzr('conflicts', backtick=1)
890
self.assertEquals(result, "question\n")
891
self.runbzr('commit -m conflicts', retcode=3)
892
self.runbzr('resolve --all')
893
result = self.runbzr('conflicts', backtick=1)
894
self.runbzr('commit -m conflicts')
895
self.assertEquals(result, "")
897
def test_resign(self):
898
"""Test re signing of data."""
900
oldstrategy = bzrlib.gpg.GPGStrategy
901
branch = Branch.initialize('.')
902
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
904
# monkey patch gpg signing mechanism
905
from bzrlib.testament import Testament
906
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
907
self.runbzr('re-sign -r revid:A')
908
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
909
branch.revision_store.get('A', 'sig').read())
911
bzrlib.gpg.GPGStrategy = oldstrategy
913
def test_resign_range(self):
915
oldstrategy = bzrlib.gpg.GPGStrategy
916
branch = Branch.initialize('.')
917
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
918
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
919
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
921
# monkey patch gpg signing mechanism
922
from bzrlib.testament import Testament
923
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
924
self.runbzr('re-sign -r 1..')
925
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
926
branch.revision_store.get('A', 'sig').read())
927
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
928
branch.revision_store.get('B', 'sig').read())
929
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
930
branch.revision_store.get('C', 'sig').read())
932
bzrlib.gpg.GPGStrategy = oldstrategy
935
# create a source branch
936
os.mkdir('my-branch')
937
os.chdir('my-branch')
938
self.example_branch()
940
# with no push target, fail
941
self.runbzr('push', retcode=3)
942
# with an explicit target work
943
self.runbzr('push ../output-branch')
944
# with an implicit target work
947
self.runbzr('missing ../output-branch')
948
# advance this branch
949
self.runbzr('commit --unchanged -m unchanged')
951
os.chdir('../output-branch')
952
# should be a diff as we have not pushed the tree
953
self.runbzr('diff', retcode=1)
954
self.runbzr('revert')
957
# diverge the branches
958
self.runbzr('commit --unchanged -m unchanged')
959
os.chdir('../my-branch')
961
self.runbzr('push', retcode=3)
962
# and there are difference
963
self.runbzr('missing ../output-branch', retcode=1)
964
self.runbzr('missing --verbose ../output-branch', retcode=1)
965
# but we can force a push
966
self.runbzr('push --overwrite')
968
self.runbzr('missing ../output-branch')
970
# pushing to a new dir with no parent should fail
971
self.runbzr('push ../missing/new-branch', retcode=3)
972
# unless we provide --create-prefix
973
self.runbzr('push --create-prefix ../missing/new-branch')
975
self.runbzr('missing ../missing/new-branch')
977
def test_external_command(self):
978
"""test that external commands can be run by setting the path"""
979
cmd_name = 'test-command'
980
output = 'Hello from test-command'
981
if sys.platform == 'win32':
987
oldpath = os.environ.get('BZRPATH', None)
992
if os.environ.has_key('BZRPATH'):
993
del os.environ['BZRPATH']
995
f = file(cmd_name, 'wb')
996
if sys.platform == 'win32':
997
f.write('@echo off\n')
999
f.write('#!/bin/sh\n')
1000
f.write('echo Hello from test-command')
1002
os.chmod(cmd_name, 0755)
1004
# It should not find the command in the local
1005
# directory by default, since it is not in my path
1006
bzr(cmd_name, retcode=3)
1008
# Now put it into my path
1009
os.environ['BZRPATH'] = '.'
1012
# The test suite does not capture stdout for external commands
1013
# this is because you have to have a real file object
1014
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
1015
# (just replacing sys.stdout does not change a spawned objects stdout)
1016
#self.assertEquals(bzr(cmd_name), output)
1018
# Make sure empty path elements are ignored
1019
os.environ['BZRPATH'] = os.pathsep
1021
bzr(cmd_name, retcode=3)
1025
os.environ['BZRPATH'] = oldpath
1028
def listdir_sorted(dir):
193
self.assertEquals(list(b.unknowns()), [])
194
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
1034
199
class OldTests(ExternalBase):
1035
"""old tests moved from ./testbzr."""
200
# old tests moved from ./testbzr
1038
202
from os import chdir, mkdir
1039
203
from os.path import exists
1041
206
runbzr = self.runbzr
1042
capture = self.capture
207
backtick = self.backtick
1043
208
progress = self.log
1045
210
progress("basic branch creation")
1056
221
f.write('hello world!\n')
1059
self.assertEquals(capture('unknowns'), 'test.txt\n')
1061
out = capture("status")
1062
self.assertEquals(out, 'unknown:\n test.txt\n')
1064
out = capture("status --all")
1065
self.assertEquals(out, "unknown:\n test.txt\n")
1067
out = capture("status test.txt --all")
1068
self.assertEquals(out, "unknown:\n test.txt\n")
224
out = backtick("bzr unknowns")
225
self.assertEquals(out, 'test.txt\n')
227
out = backtick("bzr status")
228
assert out == 'unknown:\n test.txt\n'
230
out = backtick("bzr status --all")
231
assert out == "unknown:\n test.txt\n"
233
out = backtick("bzr status test.txt --all")
234
assert out == "unknown:\n test.txt\n"
1070
236
f = file('test2.txt', 'wt')
1071
237
f.write('goodbye cruel world...\n')
1074
out = capture("status test.txt")
1075
self.assertEquals(out, "unknown:\n test.txt\n")
240
out = backtick("bzr status test.txt")
241
assert out == "unknown:\n test.txt\n"
1077
out = capture("status")
1078
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
243
out = backtick("bzr status")
244
assert out == ("unknown:\n"
1080
248
os.unlink('test2.txt')
1082
250
progress("command aliases")
1083
out = capture("st --all")
1084
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
251
out = backtick("bzr st --all")
252
assert out == ("unknown:\n"
1086
out = capture("stat")
1087
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
255
out = backtick("bzr stat")
256
assert out == ("unknown:\n"
1089
259
progress("command help")
1090
260
runbzr("help st")
1092
262
runbzr("help commands")
1093
runbzr("help slartibartfast", 3)
263
runbzr("help slartibartfast", 1)
1095
out = capture("help ci")
265
out = backtick("bzr help ci")
1096
266
out.index('aliases: ')
1098
268
progress("can't rename unversioned file")
1099
runbzr("rename test.txt new-test.txt", 3)
269
runbzr("rename test.txt new-test.txt", 1)
1101
271
progress("adding a file")
1103
273
runbzr("add test.txt")
1104
self.assertEquals(capture("unknowns"), '')
1105
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
274
assert backtick("bzr unknowns") == ''
275
assert backtick("bzr status --all") == ("added:\n"
1107
278
progress("rename newly-added file")
1108
279
runbzr("rename test.txt hello.txt")
1109
self.assert_(os.path.exists("hello.txt"))
1110
self.assert_(not os.path.exists("test.txt"))
280
assert os.path.exists("hello.txt")
281
assert not os.path.exists("test.txt")
1112
self.assertEquals(capture("revno"), '0\n')
283
assert backtick("bzr revno") == '0\n'
1114
285
progress("add first revision")
1115
286
runbzr(['commit', '-m', 'add first revision'])
1117
288
progress("more complex renames")
1118
289
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)
290
runbzr("rename hello.txt sub1", 1)
291
runbzr("rename hello.txt sub1/hello.txt", 1)
292
runbzr("move hello.txt sub1", 1)
1123
294
runbzr("add sub1")
1124
295
runbzr("rename sub1 sub2")
1125
296
runbzr("move hello.txt sub2")
1126
self.assertEqual(capture("relpath sub2/hello.txt"),
1127
os.path.join("sub2", "hello.txt\n"))
297
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
1129
self.assert_(exists("sub2"))
1130
self.assert_(exists("sub2/hello.txt"))
1131
self.assert_(not exists("sub1"))
1132
self.assert_(not exists("hello.txt"))
299
assert exists("sub2")
300
assert exists("sub2/hello.txt")
301
assert not exists("sub1")
302
assert not exists("hello.txt")
1134
304
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
1137
307
runbzr('add sub1')
1138
308
runbzr('move sub2/hello.txt sub1')
1139
self.assert_(not exists('sub2/hello.txt'))
1140
self.assert_(exists('sub1/hello.txt'))
309
assert not exists('sub2/hello.txt')
310
assert exists('sub1/hello.txt')
1141
311
runbzr('move sub2 sub1')
1142
self.assert_(not exists('sub2'))
1143
self.assert_(exists('sub1/sub2'))
312
assert not exists('sub2')
313
assert exists('sub1/sub2')
1145
315
runbzr(['commit', '-m', 'rename nested subdirectories'])
1147
317
chdir('sub1/sub2')
1148
self.assertEquals(capture('root')[:-1],
318
self.assertEquals(backtick('bzr root')[:-1],
1149
319
os.path.join(self.test_dir, 'branch1'))
1150
320
runbzr('move ../hello.txt .')
1151
self.assert_(exists('./hello.txt'))
1152
self.assertEquals(capture('relpath hello.txt'),
1153
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
1154
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
321
assert exists('./hello.txt')
322
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
323
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1155
324
runbzr(['commit', '-m', 'move to parent directory'])
1157
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
326
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1159
328
runbzr('move sub2/hello.txt .')
1160
self.assert_(exists('hello.txt'))
329
assert exists('hello.txt')
1162
331
f = file('hello.txt', 'wt')
1163
332
f.write('some nice new content\n')
1166
335
f = file('msg.tmp', 'wt')
1167
f.write('this is my new commit\nand it has multiple lines, for fun')
336
f.write('this is my new commit\n')
1170
339
runbzr('commit -F msg.tmp')
1172
self.assertEquals(capture('revno'), '5\n')
341
assert backtick('bzr revno') == '5\n'
1173
342
runbzr('export -r 5 export-5.tmp')
1174
343
runbzr('export export.tmp')
1177
346
runbzr('log -v')
1178
347
runbzr('log -v --forward')
1179
runbzr('log -m', retcode=3)
1180
log_out = capture('log -m commit')
1181
self.assert_("this is my new commit\n and" in log_out)
1182
self.assert_("rename nested" not in log_out)
1183
self.assert_('revision-id' not in log_out)
1184
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1186
log_out = capture('log --line')
1187
for line in log_out.splitlines():
1188
self.assert_(len(line) <= 79, len(line))
1189
self.assert_("this is my new commit and" in log_out)
348
runbzr('log -m', retcode=1)
349
log_out = backtick('bzr log -m commit')
350
assert "this is my new commit" in log_out
351
assert "rename nested" not in log_out
352
assert 'revision-id' not in log_out
353
assert 'revision-id' in backtick('bzr log --show-ids -m commit')
1192
356
progress("file with spaces in name")
1193
357
mkdir('sub directory')
1194
358
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1196
runbzr('diff', retcode=1)
1197
361
runbzr('commit -m add-spaces')