15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# Mr. Smoketoomuch: I'm sorry?
19
# Mr. Bounder: You'd better cut down a little then.
20
# Mr. Smoketoomuch: Oh, I see! Smoke too much so I'd better cut down a little
23
19
"""Black-box tests for bzr.
25
21
These check that it behaves properly when it's invoked through the regular
26
command-line interface. This doesn't actually run a new interpreter but
27
rather starts again from the run_bzr function.
22
command-line interface.
24
This always reinvokes bzr through a new Python interpreter, which is a
25
bit inefficient but arguably tests in a way more representative of how
26
it's normally invoked.
31
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
32
# Note: Please don't add new tests here, it's too big and bulky. Instead add
33
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
34
# UI command/aspect that is being tested.
37
from cStringIO import StringIO
43
from bzrlib.branch import Branch
44
from bzrlib.clone import copy_branch
45
from bzrlib.errors import BzrCommandError
46
from bzrlib.osutils import has_symlinks, pathjoin
47
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
48
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
49
from bzrlib.tests.blackbox import ExternalBase
51
class TestCommands(ExternalBase):
53
def test_help_commands(self):
56
self.runbzr('help commands')
57
self.runbzr('help help')
58
self.runbzr('commit -h')
60
def test_init_branch(self):
63
# Can it handle subdirectories as well?
64
self.runbzr('init subdir1')
65
self.assert_(os.path.exists('subdir1'))
66
self.assert_(os.path.exists('subdir1/.bzr'))
68
self.runbzr('init subdir2/nothere', retcode=3)
71
self.runbzr('init subdir2')
72
self.runbzr('init subdir2', retcode=3)
74
self.runbzr('init subdir2/subsubdir1')
75
self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
77
def test_whoami(self):
78
# this should always identify something, if only "john@localhost"
80
self.runbzr("whoami --email")
82
self.assertEquals(self.runbzr("whoami --email",
83
backtick=True).count('@'), 1)
85
def test_whoami_branch(self):
86
"""branch specific user identity works."""
88
f = file('.bzr/email', 'wt')
89
f.write('Branch Identity <branch@identi.ty>')
91
bzr_email = os.environ.get('BZREMAIL')
92
if bzr_email is not None:
93
del os.environ['BZREMAIL']
94
whoami = self.runbzr("whoami",backtick=True)
95
whoami_email = self.runbzr("whoami --email",backtick=True)
96
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
97
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
98
# Verify that the environment variable overrides the value
100
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
101
whoami = self.runbzr("whoami",backtick=True)
102
whoami_email = self.runbzr("whoami --email",backtick=True)
103
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
104
self.assertTrue(whoami_email.startswith('other@environ.ment'))
105
if bzr_email is not None:
106
os.environ['BZREMAIL'] = bzr_email
108
def test_nick_command(self):
109
"""bzr nick for viewing, setting nicknames"""
113
nick = self.runbzr("nick",backtick=True)
114
self.assertEqual(nick, 'me.dev\n')
115
nick = self.runbzr("nick moo")
116
nick = self.runbzr("nick",backtick=True)
117
self.assertEqual(nick, 'moo\n')
120
def test_invalid_commands(self):
121
self.runbzr("pants", retcode=3)
122
self.runbzr("--pants off", retcode=3)
123
self.runbzr("diff --message foo", retcode=3)
125
def test_empty_commit(self):
127
self.build_tree(['hello.txt'])
128
self.runbzr("commit -m empty", retcode=3)
129
self.runbzr("add hello.txt")
130
self.runbzr("commit -m added")
132
def test_empty_commit_message(self):
134
file('foo.c', 'wt').write('int main() {}')
135
self.runbzr(['add', 'foo.c'])
136
self.runbzr(["commit", "-m", ""] , retcode=3)
138
def test_remove_deleted(self):
140
self.build_tree(['a'])
141
self.runbzr(['add', 'a'])
142
self.runbzr(['commit', '-m', 'added a'])
144
self.runbzr(['remove', 'a'])
146
def test_other_branch_commit(self):
147
# this branch is to ensure consistent behaviour, whether we're run
148
# inside a branch, or not.
149
os.mkdir('empty_branch')
150
os.chdir('empty_branch')
155
file('foo.c', 'wt').write('int main() {}')
156
file('bar.c', 'wt').write('int main() {}')
158
self.runbzr(['add', 'branch/foo.c'])
159
self.runbzr(['add', 'branch'])
160
# can't commit files in different trees; sane error
161
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
162
self.runbzr('commit -m newstuff branch/foo.c')
163
self.runbzr('commit -m newstuff branch')
164
self.runbzr('commit -m newstuff branch', retcode=3)
166
def test_ignore_patterns(self):
167
from bzrlib.branch import Branch
168
Branch.initialize('.')
169
self.assertEquals(self.capture('unknowns'), '')
171
file('foo.tmp', 'wt').write('tmp files are ignored')
172
self.assertEquals(self.capture('unknowns'), '')
174
file('foo.c', 'wt').write('int main() {}')
175
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
177
self.runbzr(['add', 'foo.c'])
178
self.assertEquals(self.capture('unknowns'), '')
180
# 'ignore' works when creating the .bzignore file
181
file('foo.blah', 'wt').write('blah')
182
self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
183
self.runbzr('ignore *.blah')
184
self.assertEquals(self.capture('unknowns'), '')
185
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
187
# 'ignore' works when then .bzrignore file already exists
188
file('garh', 'wt').write('garh')
189
self.assertEquals(self.capture('unknowns'), 'garh\n')
190
self.runbzr('ignore garh')
191
self.assertEquals(self.capture('unknowns'), '')
192
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
194
def test_revert(self):
197
file('hello', 'wt').write('foo')
198
self.runbzr('add hello')
199
self.runbzr('commit -m setup hello')
201
file('goodbye', 'wt').write('baz')
202
self.runbzr('add goodbye')
203
self.runbzr('commit -m setup goodbye')
205
file('hello', 'wt').write('bar')
206
file('goodbye', 'wt').write('qux')
207
self.runbzr('revert hello')
208
self.check_file_contents('hello', 'foo')
209
self.check_file_contents('goodbye', 'qux')
210
self.runbzr('revert')
211
self.check_file_contents('goodbye', 'baz')
213
os.mkdir('revertdir')
214
self.runbzr('add revertdir')
215
self.runbzr('commit -m f')
216
os.rmdir('revertdir')
217
self.runbzr('revert')
220
os.symlink('/unlikely/to/exist', 'symlink')
221
self.runbzr('add symlink')
222
self.runbzr('commit -m f')
224
self.runbzr('revert')
225
self.failUnlessExists('symlink')
227
os.symlink('a-different-path', 'symlink')
228
self.runbzr('revert')
229
self.assertEqual('/unlikely/to/exist',
230
os.readlink('symlink'))
232
self.log("skipping revert symlink tests")
234
file('hello', 'wt').write('xyz')
235
self.runbzr('commit -m xyz hello')
236
self.runbzr('revert -r 1 hello')
237
self.check_file_contents('hello', 'foo')
238
self.runbzr('revert hello')
239
self.check_file_contents('hello', 'xyz')
240
os.chdir('revertdir')
241
self.runbzr('revert')
244
def test_status(self):
246
self.build_tree(['hello.txt'])
247
result = self.runbzr("status")
248
self.assert_("unknown:\n hello.txt\n" in result, result)
249
self.runbzr("add hello.txt")
250
result = self.runbzr("status")
251
self.assert_("added:\n hello.txt\n" in result, result)
252
self.runbzr("commit -m added")
253
result = self.runbzr("status -r 0..1")
254
self.assert_("added:\n hello.txt\n" in result, result)
255
self.build_tree(['world.txt'])
256
result = self.runbzr("status -r 0")
257
self.assert_("added:\n hello.txt\n" \
258
"unknown:\n world.txt\n" in result, result)
260
def test_mv_modes(self):
261
"""Test two modes of operation for mv"""
262
from bzrlib.branch import Branch
263
b = Branch.initialize('.')
264
self.build_tree(['a', 'c', 'subdir/'])
265
self.run_bzr_captured(['add', self.test_dir])
266
self.run_bzr_captured(['mv', 'a', 'b'])
267
self.run_bzr_captured(['mv', 'b', 'subdir'])
268
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
269
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
270
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
272
def test_main_version(self):
273
"""Check output from version command and master option is reasonable"""
29
# this code was previously in testbzr
31
from unittest import TestCase
32
from bzrlib.selftest import TestBase, InTempDir
34
class TestVersion(TestBase):
274
36
# output is intentionally passed through to stdout so that we
275
37
# can see the version being tested
276
output = self.runbzr('version', backtick=1)
277
self.log('bzr version output:')
279
self.assert_(output.startswith('bzr (bazaar-ng) '))
280
self.assertNotEqual(output.index('Canonical'), -1)
281
# make sure --version is consistent
282
tmp_output = self.runbzr('--version', backtick=1)
283
self.log('bzr --version output:')
285
self.assertEquals(output, tmp_output)
287
def example_branch(test):
289
file('hello', 'wt').write('foo')
290
test.runbzr('add hello')
291
test.runbzr('commit -m setup hello')
292
file('goodbye', 'wt').write('baz')
293
test.runbzr('add goodbye')
294
test.runbzr('commit -m setup goodbye')
296
def test_export(self):
299
self.example_branch()
300
self.runbzr('export ../latest')
301
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
302
self.runbzr('export ../first -r 1')
303
self.assert_(not os.path.exists('../first/goodbye'))
304
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
305
self.runbzr('export ../first.gz -r 1')
306
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
307
self.runbzr('export ../first.bz2 -r 1')
308
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
310
from tarfile import TarFile
311
self.runbzr('export ../first.tar -r 1')
312
self.assert_(os.path.isfile('../first.tar'))
313
tf = TarFile('../first.tar')
314
self.assert_('first/hello' in tf.getnames(), tf.getnames())
315
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
316
self.runbzr('export ../first.tar.gz -r 1')
317
self.assert_(os.path.isfile('../first.tar.gz'))
318
self.runbzr('export ../first.tbz2 -r 1')
319
self.assert_(os.path.isfile('../first.tbz2'))
320
self.runbzr('export ../first.tar.bz2 -r 1')
321
self.assert_(os.path.isfile('../first.tar.bz2'))
322
self.runbzr('export ../first.tar.tbz2 -r 1')
323
self.assert_(os.path.isfile('../first.tar.tbz2'))
325
from bz2 import BZ2File
326
tf = TarFile('../first.tar.tbz2',
327
fileobj=BZ2File('../first.tar.tbz2', 'r'))
328
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
329
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
330
self.runbzr('export ../first2.tar -r 1 --root pizza')
331
tf = TarFile('../first2.tar')
332
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
334
from zipfile import ZipFile
335
self.runbzr('export ../first.zip -r 1')
336
self.failUnlessExists('../first.zip')
337
zf = ZipFile('../first.zip')
338
self.assert_('first/hello' in zf.namelist(), zf.namelist())
339
self.assertEqual(zf.read('first/hello'), 'foo')
341
self.runbzr('export ../first2.zip -r 1 --root pizza')
342
zf = ZipFile('../first2.zip')
343
self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
345
self.runbzr('export ../first-zip --format=zip -r 1')
346
zf = ZipFile('../first-zip')
347
self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
349
def test_branch(self):
350
"""Branch from one branch to another."""
353
self.example_branch()
355
self.runbzr('branch a b')
356
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
357
self.runbzr('branch a c -r 1')
359
self.runbzr('commit -m foo --unchanged')
361
# naughty - abstraction violations RBC 20050928
362
print "test_branch used to delete the stores, how is this meant to work ?"
363
#shutil.rmtree('a/.bzr/revision-store')
364
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
365
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
366
self.runbzr('branch a d --basis b')
368
def test_merge(self):
369
from bzrlib.branch import Branch
373
self.example_branch()
375
self.runbzr('branch a b')
377
file('goodbye', 'wt').write('quux')
378
self.runbzr(['commit', '-m', "more u's are always good"])
381
file('hello', 'wt').write('quuux')
382
# We can't merge when there are in-tree changes
383
self.runbzr('merge ../b', retcode=3)
384
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
385
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
387
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
388
self.runbzr('revert --no-backup')
389
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
390
self.runbzr('revert --no-backup')
391
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
392
self.runbzr('revert --no-backup')
393
self.runbzr('merge ../b -r last:1')
394
self.check_file_contents('goodbye', 'quux')
395
# Merging a branch pulls its revision into the tree
397
b = Branch.open('../b')
398
a.get_revision_xml(b.last_revision())
399
self.log('pending merges: %s', a.working_tree().pending_merges())
400
self.assertEquals(a.working_tree().pending_merges(),
402
self.runbzr('commit -m merged')
403
self.runbzr('merge ../b -r last:1')
404
self.assertEqual(Branch.open('.').working_tree().pending_merges(), [])
406
def test_merge_with_missing_file(self):
407
"""Merge handles missing file conflicts"""
411
print >> file('sub/a.txt', 'wb'), "hello"
412
print >> file('b.txt', 'wb'), "hello"
413
print >> file('sub/c.txt', 'wb'), "hello"
416
self.runbzr(('commit', '-m', 'added a'))
417
self.runbzr('branch . ../b')
418
print >> file('sub/a.txt', 'ab'), "there"
419
print >> file('b.txt', 'ab'), "there"
420
print >> file('sub/c.txt', 'ab'), "there"
421
self.runbzr(('commit', '-m', 'Added there'))
422
os.unlink('sub/a.txt')
423
os.unlink('sub/c.txt')
426
self.runbzr(('commit', '-m', 'Removed a.txt'))
428
print >> file('sub/a.txt', 'ab'), "something"
429
print >> file('b.txt', 'ab'), "something"
430
print >> file('sub/c.txt', 'ab'), "something"
431
self.runbzr(('commit', '-m', 'Modified a.txt'))
432
self.runbzr('merge ../a/', retcode=1)
433
self.assert_(os.path.exists('sub/a.txt.THIS'))
434
self.assert_(os.path.exists('sub/a.txt.BASE'))
436
self.runbzr('merge ../b/', retcode=1)
437
self.assert_(os.path.exists('sub/a.txt.OTHER'))
438
self.assert_(os.path.exists('sub/a.txt.BASE'))
440
def test_inventory(self):
442
def output_equals(value, *args):
443
out = self.runbzr(['inventory'] + list(args), backtick=True)
444
self.assertEquals(out, value)
447
open('a', 'wb').write('hello\n')
453
output_equals('a\n', '--kind', 'file')
454
output_equals('b\n', '--kind', 'directory')
457
"""Test the abilities of 'bzr ls'"""
459
def bzrout(*args, **kwargs):
460
kwargs['backtick'] = True
461
return self.runbzr(*args, **kwargs)
463
def ls_equals(value, *args):
464
out = self.runbzr(['ls'] + list(args), backtick=True)
465
self.assertEquals(out, value)
468
open('a', 'wb').write('hello\n')
471
bzr('ls --verbose --null', retcode=3)
474
ls_equals('? a\n', '--verbose')
475
ls_equals('a\n', '--unknown')
476
ls_equals('', '--ignored')
477
ls_equals('', '--versioned')
478
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
479
ls_equals('', '--ignored', '--versioned')
480
ls_equals('a\0', '--null')
483
ls_equals('V a\n', '--verbose')
490
open('subdir/b', 'wb').write('b\n')
496
bzr('commit -m subdir')
504
, '--verbose', '--non-recursive')
506
# Check what happens in a sub-directory
518
, '--from-root', '--null')
521
, '--from-root', '--non-recursive')
525
# Check what happens when we supply a specific revision
526
ls_equals('a\n', '--revision', '1')
528
, '--verbose', '--revision', '1')
531
ls_equals('', '--revision', '1')
533
# Now try to do ignored files.
535
open('blah.py', 'wb').write('unknown\n')
536
open('blah.pyo', 'wb').write('ignored\n')
548
ls_equals('blah.pyo\n'
550
ls_equals('blah.py\n'
557
def test_pull_verbose(self):
558
"""Pull changes from one branch to another and watch the output."""
564
self.example_branch()
569
open('b', 'wb').write('else\n')
571
bzr(['commit', '-m', 'added b'])
574
out = bzr('pull --verbose ../b', backtick=True)
575
self.failIfEqual(out.find('Added Revisions:'), -1)
576
self.failIfEqual(out.find('message:\n added b'), -1)
577
self.failIfEqual(out.find('added b'), -1)
579
# Check that --overwrite --verbose prints out the removed entries
580
bzr('commit -m foo --unchanged')
582
bzr('commit -m baz --unchanged')
583
bzr('pull ../a', retcode=3)
584
out = bzr('pull --overwrite --verbose ../a', backtick=1)
586
remove_loc = out.find('Removed Revisions:')
587
self.failIfEqual(remove_loc, -1)
588
added_loc = out.find('Added Revisions:')
589
self.failIfEqual(added_loc, -1)
591
removed_message = out.find('message:\n baz')
592
self.failIfEqual(removed_message, -1)
593
self.failUnless(remove_loc < removed_message < added_loc)
595
added_message = out.find('message:\n foo')
596
self.failIfEqual(added_message, -1)
597
self.failUnless(added_loc < added_message)
599
def test_locations(self):
600
"""Using and remembering different locations"""
604
self.runbzr('commit -m unchanged --unchanged')
605
self.runbzr('pull', retcode=3)
606
self.runbzr('merge', retcode=3)
607
self.runbzr('branch . ../b')
610
self.runbzr('branch . ../c')
611
self.runbzr('pull ../c')
614
self.runbzr('pull ../b')
616
self.runbzr('pull ../c')
617
self.runbzr('branch ../c ../d')
618
shutil.rmtree('../c')
623
self.runbzr('pull', retcode=3)
624
self.runbzr('pull ../a --remember')
627
def test_add_reports(self):
628
"""add command prints the names of added files."""
629
b = Branch.initialize('.')
630
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt', 'CVS'])
631
out = self.run_bzr_captured(['add'], retcode=0)[0]
632
# the ordering is not defined at the moment
633
results = sorted(out.rstrip('\n').split('\n'))
634
self.assertEquals(['If you wish to add some of these files, please'\
635
' add them by name.',
639
'ignored 1 file(s) matching "CVS"'],
641
out = self.run_bzr_captured(['add', '-v'], retcode=0)[0]
642
results = sorted(out.rstrip('\n').split('\n'))
643
self.assertEquals(['If you wish to add some of these files, please'\
644
' add them by name.',
645
'ignored CVS matching "CVS"'],
648
def test_add_quiet_is(self):
649
"""add -q does not print the names of added files."""
650
b = Branch.initialize('.')
651
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
652
out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
653
# the ordering is not defined at the moment
654
results = sorted(out.rstrip('\n').split('\n'))
655
self.assertEquals([''], results)
657
def test_add_in_unversioned(self):
658
"""Try to add a file in an unversioned directory.
660
"bzr add" should add the parent(s) as necessary.
662
from bzrlib.branch import Branch
663
Branch.initialize('.')
664
self.build_tree(['inertiatic/', 'inertiatic/esp'])
665
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
666
self.run_bzr('add', 'inertiatic/esp')
667
self.assertEquals(self.capture('unknowns'), '')
669
# Multiple unversioned parents
670
self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
671
self.assertEquals(self.capture('unknowns'), 'veil\n')
672
self.run_bzr('add', 'veil/cerpin/taxt')
673
self.assertEquals(self.capture('unknowns'), '')
675
# Check whacky paths work
676
self.build_tree(['cicatriz/', 'cicatriz/esp'])
677
self.assertEquals(self.capture('unknowns'), 'cicatriz\n')
678
self.run_bzr('add', 'inertiatic/../cicatriz/esp')
679
self.assertEquals(self.capture('unknowns'), '')
681
def test_add_in_versioned(self):
682
"""Try to add a file in a versioned directory.
684
"bzr add" should do this happily.
686
from bzrlib.branch import Branch
687
Branch.initialize('.')
688
self.build_tree(['inertiatic/', 'inertiatic/esp'])
689
self.assertEquals(self.capture('unknowns'), 'inertiatic\n')
690
self.run_bzr('add', '--no-recurse', 'inertiatic')
691
self.assertEquals(self.capture('unknowns'), 'inertiatic/esp\n')
692
self.run_bzr('add', 'inertiatic/esp')
693
self.assertEquals(self.capture('unknowns'), '')
695
def test_subdir_add(self):
696
"""Add in subdirectory should add only things from there down"""
697
from bzrlib.branch import Branch
699
eq = self.assertEqual
703
b = Branch.initialize('.')
705
self.build_tree(['src/', 'README'])
707
eq(sorted(t.unknowns()),
710
self.run_bzr('add', 'src')
712
self.build_tree(['src/foo.c'])
717
self.assertEquals(self.capture('unknowns'), 'README\n')
718
eq(len(t.read_working_inventory()), 3)
722
self.assertEquals(self.capture('unknowns'), '')
723
self.run_bzr('check')
725
def test_unknown_command(self):
726
"""Handling of unknown command."""
727
out, err = self.run_bzr_captured(['fluffy-badger'],
729
self.assertEquals(out, '')
730
err.index('unknown command')
732
def create_conflicts(self):
733
"""Create a conflicted tree"""
736
file('hello', 'wb').write("hi world")
737
file('answer', 'wb').write("42")
740
self.runbzr('commit -m base')
741
self.runbzr('branch . ../other')
742
self.runbzr('branch . ../this')
744
file('hello', 'wb').write("Hello.")
745
file('answer', 'wb').write("Is anyone there?")
746
self.runbzr('commit -m other')
748
file('hello', 'wb').write("Hello, world")
749
self.runbzr('mv answer question')
750
file('question', 'wb').write("What do you get when you multiply six"
752
self.runbzr('commit -m this')
754
def test_remerge(self):
755
"""Remerge command works as expected"""
756
self.create_conflicts()
757
self.runbzr('merge ../other --show-base', retcode=1)
758
conflict_text = file('hello').read()
759
assert '|||||||' in conflict_text
760
assert 'hi world' in conflict_text
761
self.runbzr('remerge', retcode=1)
762
conflict_text = file('hello').read()
763
assert '|||||||' not in conflict_text
764
assert 'hi world' not in conflict_text
765
os.unlink('hello.OTHER')
766
self.runbzr('remerge hello --merge-type weave', retcode=1)
767
assert os.path.exists('hello.OTHER')
768
file_id = self.runbzr('file-id hello')
769
file_id = self.runbzr('file-id hello.THIS', retcode=3)
770
self.runbzr('remerge --merge-type weave', retcode=1)
771
assert os.path.exists('hello.OTHER')
772
assert not os.path.exists('hello.BASE')
773
assert '|||||||' not in conflict_text
774
assert 'hi world' not in conflict_text
775
self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
776
self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
777
self.runbzr('remerge . --show-base --reprocess', retcode=3)
778
self.runbzr('remerge hello --show-base', retcode=1)
779
self.runbzr('remerge hello --reprocess', retcode=1)
780
self.runbzr('resolve --all')
781
self.runbzr('commit -m done',)
782
self.runbzr('remerge', retcode=3)
785
def test_conflicts(self):
786
"""Handling of merge conflicts"""
787
self.create_conflicts()
788
self.runbzr('merge ../other --show-base', retcode=1)
789
conflict_text = file('hello').read()
790
self.assert_('<<<<<<<' in conflict_text)
791
self.assert_('>>>>>>>' in conflict_text)
792
self.assert_('=======' in conflict_text)
793
self.assert_('|||||||' in conflict_text)
794
self.assert_('hi world' in conflict_text)
795
self.runbzr('revert')
796
self.runbzr('resolve --all')
797
self.runbzr('merge ../other', retcode=1)
798
conflict_text = file('hello').read()
799
self.assert_('|||||||' not in conflict_text)
800
self.assert_('hi world' not in conflict_text)
801
result = self.runbzr('conflicts', backtick=1)
802
self.assertEquals(result, "hello\nquestion\n")
803
result = self.runbzr('status', backtick=1)
804
self.assert_("conflicts:\n hello\n question\n" in result, result)
805
self.runbzr('resolve hello')
806
result = self.runbzr('conflicts', backtick=1)
807
self.assertEquals(result, "question\n")
808
self.runbzr('commit -m conflicts', retcode=3)
809
self.runbzr('resolve --all')
810
result = self.runbzr('conflicts', backtick=1)
811
self.runbzr('commit -m conflicts')
812
self.assertEquals(result, "")
814
def test_resign(self):
815
"""Test re signing of data."""
817
oldstrategy = bzrlib.gpg.GPGStrategy
818
branch = Branch.initialize('.')
819
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
821
# monkey patch gpg signing mechanism
822
from bzrlib.testament import Testament
823
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
824
self.runbzr('re-sign -r revid:A')
825
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
826
branch.revision_store.get('A', 'sig').read())
828
bzrlib.gpg.GPGStrategy = oldstrategy
830
def test_resign_range(self):
832
oldstrategy = bzrlib.gpg.GPGStrategy
833
branch = Branch.initialize('.')
834
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
835
branch.working_tree().commit("base", allow_pointless=True, rev_id='B')
836
branch.working_tree().commit("base", allow_pointless=True, rev_id='C')
838
# monkey patch gpg signing mechanism
839
from bzrlib.testament import Testament
840
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
841
self.runbzr('re-sign -r 1..')
842
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
843
branch.revision_store.get('A', 'sig').read())
844
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
845
branch.revision_store.get('B', 'sig').read())
846
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
847
branch.revision_store.get('C', 'sig').read())
849
bzrlib.gpg.GPGStrategy = oldstrategy
852
# create a source branch
853
os.mkdir('my-branch')
854
os.chdir('my-branch')
855
self.example_branch()
857
# with no push target, fail
858
self.runbzr('push', retcode=3)
859
# with an explicit target work
860
self.runbzr('push ../output-branch')
861
# with an implicit target work
864
self.runbzr('missing ../output-branch')
865
# advance this branch
866
self.runbzr('commit --unchanged -m unchanged')
868
os.chdir('../output-branch')
869
# There is no longer a difference as long as we have
870
# access to the working tree
873
# But we should be missing a revision
874
self.runbzr('missing ../my-branch', retcode=1)
876
# diverge the branches
877
self.runbzr('commit --unchanged -m unchanged')
878
os.chdir('../my-branch')
880
self.runbzr('push', retcode=3)
881
# and there are difference
882
self.runbzr('missing ../output-branch', retcode=1)
883
self.runbzr('missing --verbose ../output-branch', retcode=1)
884
# but we can force a push
885
self.runbzr('push --overwrite')
887
self.runbzr('missing ../output-branch')
889
# pushing to a new dir with no parent should fail
890
self.runbzr('push ../missing/new-branch', retcode=3)
891
# unless we provide --create-prefix
892
self.runbzr('push --create-prefix ../missing/new-branch')
894
self.runbzr('missing ../missing/new-branch')
896
def test_external_command(self):
897
"""test that external commands can be run by setting the path"""
898
cmd_name = 'test-command'
899
output = 'Hello from test-command'
900
if sys.platform == 'win32':
906
oldpath = os.environ.get('BZRPATH', None)
911
if os.environ.has_key('BZRPATH'):
912
del os.environ['BZRPATH']
914
f = file(cmd_name, 'wb')
915
if sys.platform == 'win32':
916
f.write('@echo off\n')
918
f.write('#!/bin/sh\n')
919
f.write('echo Hello from test-command')
921
os.chmod(cmd_name, 0755)
923
# It should not find the command in the local
924
# directory by default, since it is not in my path
925
bzr(cmd_name, retcode=3)
927
# Now put it into my path
928
os.environ['BZRPATH'] = '.'
931
# The test suite does not capture stdout for external commands
932
# this is because you have to have a real file object
933
# to pass to Popen(stdout=FOO), and StringIO is not one of those.
934
# (just replacing sys.stdout does not change a spawned objects stdout)
935
#self.assertEquals(bzr(cmd_name), output)
937
# Make sure empty path elements are ignored
938
os.environ['BZRPATH'] = os.pathsep
940
bzr(cmd_name, retcode=3)
944
os.environ['BZRPATH'] = oldpath
947
def listdir_sorted(dir):
953
class OldTests(ExternalBase):
954
"""old tests moved from ./testbzr."""
38
self.runcmd(['bzr', 'version'])
42
class HelpCommands(TestBase):
44
self.runcmd('bzr --help')
45
self.runcmd('bzr help')
46
self.runcmd('bzr help commands')
47
self.runcmd('bzr help help')
48
self.runcmd('bzr commit -h')
51
class InitBranch(InTempDir):
54
self.runcmd(['bzr', 'init'])
58
class UserIdentity(InTempDir):
60
# this should always identify something, if only "john@localhost"
61
self.runcmd("bzr whoami")
62
self.runcmd("bzr whoami --email")
63
self.assertEquals(self.backtick("bzr whoami --email").count('@'),
67
class InvalidCommands(InTempDir):
69
self.runcmd("bzr pants", retcode=1)
70
self.runcmd("bzr --pants off", retcode=1)
71
self.runcmd("bzr diff --message foo", retcode=1)
75
class OldTests(InTempDir):
76
# old tests moved from ./testbzr
957
78
from os import chdir, mkdir
958
79
from os.path import exists
961
capture = self.capture
83
backtick = self.backtick
962
84
progress = self.log
964
86
progress("basic branch creation")
87
runcmd(['mkdir', 'branch1'])
969
self.assertEquals(capture('root').rstrip(),
970
pathjoin(self.test_dir, 'branch1'))
91
self.assertEquals(backtick('bzr root').rstrip(),
92
os.path.join(self.test_dir, 'branch1'))
972
94
progress("status of new file")
975
97
f.write('hello world!\n')
978
self.assertEquals(capture('unknowns'), 'test.txt\n')
980
out = capture("status")
981
self.assertEquals(out, 'unknown:\n test.txt\n')
983
out = capture("status --all")
984
self.assertEquals(out, "unknown:\n test.txt\n")
986
out = capture("status test.txt --all")
987
self.assertEquals(out, "unknown:\n test.txt\n")
100
out = backtick("bzr unknowns")
101
self.assertEquals(out, 'test.txt\n')
103
out = backtick("bzr status")
104
assert out == 'unknown:\n test.txt\n'
106
out = backtick("bzr status --all")
107
assert out == "unknown:\n test.txt\n"
109
out = backtick("bzr status test.txt --all")
110
assert out == "unknown:\n test.txt\n"
989
112
f = file('test2.txt', 'wt')
990
113
f.write('goodbye cruel world...\n')
993
out = capture("status test.txt")
994
self.assertEquals(out, "unknown:\n test.txt\n")
116
out = backtick("bzr status test.txt")
117
assert out == "unknown:\n test.txt\n"
996
out = capture("status")
997
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
119
out = backtick("bzr status")
120
assert out == ("unknown:\n"
999
124
os.unlink('test2.txt')
1001
126
progress("command aliases")
1002
out = capture("st --all")
1003
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
127
out = backtick("bzr st --all")
128
assert out == ("unknown:\n"
1005
out = capture("stat")
1006
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
131
out = backtick("bzr stat")
132
assert out == ("unknown:\n"
1008
135
progress("command help")
1011
runbzr("help commands")
1012
runbzr("help slartibartfast", 3)
136
runcmd("bzr help st")
138
runcmd("bzr help commands")
139
runcmd("bzr help slartibartfast", 1)
1014
out = capture("help ci")
141
out = backtick("bzr help ci")
1015
142
out.index('aliases: ')
1017
144
progress("can't rename unversioned file")
1018
runbzr("rename test.txt new-test.txt", 3)
145
runcmd("bzr rename test.txt new-test.txt", 1)
1020
147
progress("adding a file")
1022
runbzr("add test.txt")
1023
self.assertEquals(capture("unknowns"), '')
1024
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
149
runcmd("bzr add test.txt")
150
assert backtick("bzr unknowns") == ''
151
assert backtick("bzr status --all") == ("added:\n"
1026
154
progress("rename newly-added file")
1027
runbzr("rename test.txt hello.txt")
1028
self.assert_(os.path.exists("hello.txt"))
1029
self.assert_(not os.path.exists("test.txt"))
155
runcmd("bzr rename test.txt hello.txt")
156
assert os.path.exists("hello.txt")
157
assert not os.path.exists("test.txt")
1031
self.assertEquals(capture("revno"), '0\n')
159
assert backtick("bzr revno") == '0\n'
1033
161
progress("add first revision")
1034
runbzr(['commit', '-m', 'add first revision'])
162
runcmd(["bzr", "commit", "-m", 'add first revision'])
1036
164
progress("more complex renames")
1037
165
os.mkdir("sub1")
1038
runbzr("rename hello.txt sub1", 3)
1039
runbzr("rename hello.txt sub1/hello.txt", 3)
1040
runbzr("move hello.txt sub1", 3)
1043
runbzr("rename sub1 sub2")
1044
runbzr("move hello.txt sub2")
1045
self.assertEqual(capture("relpath sub2/hello.txt"),
1046
pathjoin("sub2", "hello.txt\n"))
1048
self.assert_(exists("sub2"))
1049
self.assert_(exists("sub2/hello.txt"))
1050
self.assert_(not exists("sub1"))
1051
self.assert_(not exists("hello.txt"))
1053
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
166
runcmd("bzr rename hello.txt sub1", 1)
167
runcmd("bzr rename hello.txt sub1/hello.txt", 1)
168
runcmd("bzr move hello.txt sub1", 1)
170
runcmd("bzr add sub1")
171
runcmd("bzr rename sub1 sub2")
172
runcmd("bzr move hello.txt sub2")
173
assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
175
assert exists("sub2")
176
assert exists("sub2/hello.txt")
177
assert not exists("sub1")
178
assert not exists("hello.txt")
180
runcmd(['bzr', 'commit', '-m', 'commit with some things moved to subdirs'])
1057
runbzr('move sub2/hello.txt sub1')
1058
self.assert_(not exists('sub2/hello.txt'))
1059
self.assert_(exists('sub1/hello.txt'))
1060
runbzr('move sub2 sub1')
1061
self.assert_(not exists('sub2'))
1062
self.assert_(exists('sub1/sub2'))
183
runcmd('bzr add sub1')
184
runcmd('bzr move sub2/hello.txt sub1')
185
assert not exists('sub2/hello.txt')
186
assert exists('sub1/hello.txt')
187
runcmd('bzr move sub2 sub1')
188
assert not exists('sub2')
189
assert exists('sub1/sub2')
1064
runbzr(['commit', '-m', 'rename nested subdirectories'])
191
runcmd(['bzr', 'commit', '-m', 'rename nested subdirectories'])
1066
193
chdir('sub1/sub2')
1067
self.assertEquals(capture('root')[:-1],
1068
pathjoin(self.test_dir, 'branch1'))
1069
runbzr('move ../hello.txt .')
1070
self.assert_(exists('./hello.txt'))
1071
self.assertEquals(capture('relpath hello.txt'),
1072
pathjoin('sub1', 'sub2', 'hello.txt') + '\n')
1073
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
1074
runbzr(['commit', '-m', 'move to parent directory'])
194
self.assertEquals(backtick('bzr root')[:-1],
195
os.path.join(self.test_dir, 'branch1'))
196
runcmd('bzr move ../hello.txt .')
197
assert exists('./hello.txt')
198
assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
199
assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
200
runcmd(['bzr', 'commit', '-m', 'move to parent directory'])
1076
self.assertEquals(capture('relpath sub2/hello.txt'), pathjoin('sub1', 'sub2', 'hello.txt\n'))
202
assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
1078
runbzr('move sub2/hello.txt .')
1079
self.assert_(exists('hello.txt'))
204
runcmd('bzr move sub2/hello.txt .')
205
assert exists('hello.txt')
1081
207
f = file('hello.txt', 'wt')
1082
208
f.write('some nice new content\n')
1085
211
f = file('msg.tmp', 'wt')
1086
f.write('this is my new commit\nand it has multiple lines, for fun')
212
f.write('this is my new commit\n')
1089
runbzr('commit -F msg.tmp')
1091
self.assertEquals(capture('revno'), '5\n')
1092
runbzr('export -r 5 export-5.tmp')
1093
runbzr('export export.tmp')
1097
runbzr('log -v --forward')
1098
runbzr('log -m', retcode=3)
1099
log_out = capture('log -m commit')
1100
self.assert_("this is my new commit\n and" in log_out)
1101
self.assert_("rename nested" not in log_out)
1102
self.assert_('revision-id' not in log_out)
1103
self.assert_('revision-id' in capture('log --show-ids -m commit'))
1105
log_out = capture('log --line')
1106
for line in log_out.splitlines():
1107
self.assert_(len(line) <= 79, len(line))
1108
self.assert_("this is my new commit and" in log_out)
215
runcmd('bzr commit -F msg.tmp')
217
assert backtick('bzr revno') == '5\n'
218
runcmd('bzr export -r 5 export-5.tmp')
219
runcmd('bzr export export.tmp')
1111
226
progress("file with spaces in name")
1112
227
mkdir('sub directory')
1113
228
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
1115
runbzr('diff', retcode=1)
1116
runbzr('commit -m add-spaces')
1120
runbzr('log --forward')
1125
progress("symlinks")
1129
os.symlink("NOWHERE1", "link1")
1131
self.assertEquals(self.capture('unknowns'), '')
1132
runbzr(['commit', '-m', '1: added symlink link1'])
1136
self.assertEquals(self.capture('unknowns'), '')
1137
os.symlink("NOWHERE2", "d1/link2")
1138
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
1139
# is d1/link2 found when adding d1
1141
self.assertEquals(self.capture('unknowns'), '')
1142
os.symlink("NOWHERE3", "d1/link3")
1143
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
1144
runbzr(['commit', '-m', '2: added dir, symlink'])
1146
runbzr('rename d1 d2')
1147
runbzr('move d2/link2 .')
1148
runbzr('move link1 d2')
1149
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
1150
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1151
runbzr('add d2/link3')
1152
runbzr('diff', retcode=1)
1153
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
1156
os.symlink("TARGET 2", "link2")
1157
os.unlink("d2/link1")
1158
os.symlink("TARGET 1", "d2/link1")
1159
runbzr('diff', retcode=1)
1160
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
1161
runbzr(['commit', '-m', '4: retarget of two links'])
1163
runbzr('remove d2/link1')
1164
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1165
runbzr(['commit', '-m', '5: remove d2/link1'])
1166
# try with the rm alias
1167
runbzr('add d2/link1')
1168
runbzr(['commit', '-m', '6: add d2/link1'])
1169
runbzr('rm d2/link1')
1170
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1171
runbzr(['commit', '-m', '7: remove d2/link1'])
1175
runbzr('rename d2/link3 d1/link3new')
1176
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
1177
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
1181
runbzr(['export', '-r', '1', 'exp1.tmp'])
1183
self.assertEquals(listdir_sorted("."), [ "link1" ])
1184
self.assertEquals(os.readlink("link1"), "NOWHERE1")
1187
runbzr(['export', '-r', '2', 'exp2.tmp'])
1189
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
1192
runbzr(['export', '-r', '3', 'exp3.tmp'])
1194
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1195
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1196
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
1197
self.assertEquals(os.readlink("link2") , "NOWHERE2")
1200
runbzr(['export', '-r', '4', 'exp4.tmp'])
1202
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1203
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
1204
self.assertEquals(os.readlink("link2") , "TARGET 2")
1205
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
1208
runbzr(['export', '-r', '5', 'exp5.tmp'])
1210
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
1211
self.assert_(os.path.islink("link2"))
1212
self.assert_(listdir_sorted("d2")== [ "link3" ])
1215
runbzr(['export', '-r', '8', 'exp6.tmp'])
1217
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
1218
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])
1219
self.assertEquals(listdir_sorted("d2"), [])
1220
self.assertEquals(os.readlink("d1/link3new"), "NOWHERE3")
1223
progress("skipping symlink tests")
1226
class RemoteTests(object):
1227
"""Test bzr ui commands against remote branches."""
1229
def test_branch(self):
1231
branch = Branch.initialize('from')
1232
branch.working_tree().commit('empty commit for nonsense', allow_pointless=True)
1233
url = self.get_remote_url('from')
1234
self.run_bzr('branch', url, 'to')
1235
branch = Branch.open('to')
1236
self.assertEqual(1, len(branch.revision_history()))
1239
self.build_tree(['branch/', 'branch/file'])
1240
branch = Branch.initialize('branch')
1241
branch.working_tree().add(['file'])
1242
branch.working_tree().commit('add file', rev_id='A')
1243
url = self.get_remote_url('branch/file')
1244
output = self.capture('log %s' % url)
1245
self.assertEqual(8, len(output.split('\n')))
1247
def test_check(self):
1248
self.build_tree(['branch/', 'branch/file'])
1249
branch = Branch.initialize('branch')
1250
branch.working_tree().add(['file'])
1251
branch.working_tree().commit('add file', rev_id='A')
1252
url = self.get_remote_url('branch/')
1253
self.run_bzr('check', url)
1256
class HTTPTests(TestCaseWithWebserver, RemoteTests):
1257
"""Test various commands against a HTTP server."""
1260
class SFTPTestsAbsolute(TestCaseWithSFTPServer, RemoteTests):
1261
"""Test various commands against a SFTP server using abs paths."""
1264
class SFTPTestsAbsoluteSibling(TestCaseWithSFTPServer, RemoteTests):
1265
"""Test various commands against a SFTP server using abs paths."""
1268
super(SFTPTestsAbsoluteSibling, self).setUp()
1269
self._override_home = '/dev/noone/runs/tests/here'
1272
class SFTPTestsRelative(TestCaseWithSFTPServer, RemoteTests):
1273
"""Test various commands against a SFTP server using homedir rel paths."""
1276
super(SFTPTestsRelative, self).setUp()
1277
self._get_remote_is_absolute = False
231
runcmd('bzr commit -m add-spaces')
235
runcmd('bzr log --forward')
247
# Can't create a branch if it already exists
248
runcmd('bzr branch branch1', retcode=1)
249
# Can't create a branch if its parent doesn't exist
250
runcmd('bzr branch /unlikely/to/exist', retcode=1)
251
runcmd('bzr branch branch1 branch2')
255
runcmd('bzr pull', retcode=1)
256
runcmd('bzr pull ../branch2')
259
runcmd('bzr commit -m empty')
261
chdir('../../branch2')
263
runcmd('bzr commit -m empty')
265
runcmd('bzr commit -m empty')
266
runcmd('bzr pull', retcode=1)
269
progress('status after remove')
270
mkdir('status-after-remove')
271
# see mail from William Dodé, 2005-05-25
272
# $ bzr init; touch a; bzr add a; bzr commit -m "add a"
273
# * looking for changes...
278
# bzr: local variable 'kind' referenced before assignment
279
# at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
280
# see ~/.bzr.log for debug information
281
chdir('status-after-remove')
283
file('a', 'w').write('foo')
285
runcmd(['bzr', 'commit', '-m', 'add a'])
286
runcmd('bzr remove a')
291
progress('ignore patterns')
292
mkdir('ignorebranch')
293
chdir('ignorebranch')
295
assert backtick('bzr unknowns') == ''
297
file('foo.tmp', 'wt').write('tmp files are ignored')
298
assert backtick('bzr unknowns') == ''
300
file('foo.c', 'wt').write('int main() {}')
301
assert backtick('bzr unknowns') == 'foo.c\n'
302
runcmd('bzr add foo.c')
303
assert backtick('bzr unknowns') == ''
305
# 'ignore' works when creating the .bzignore file
306
file('foo.blah', 'wt').write('blah')
307
assert backtick('bzr unknowns') == 'foo.blah\n'
308
runcmd('bzr ignore *.blah')
309
assert backtick('bzr unknowns') == ''
310
assert file('.bzrignore', 'rb').read() == '*.blah\n'
312
# 'ignore' works when then .bzrignore file already exists
313
file('garh', 'wt').write('garh')
314
assert backtick('bzr unknowns') == 'garh\n'
315
runcmd('bzr ignore garh')
316
assert backtick('bzr unknowns') == ''
317
assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
324
progress("recursive and non-recursive add")
329
fp = os.path.join('foo', 'test.txt')
333
runcmd('bzr add --no-recurse foo')
334
runcmd('bzr file-id foo')
335
runcmd('bzr file-id ' + fp, 1) # not versioned yet
336
runcmd('bzr commit -m add-dir-only')
338
runcmd('bzr file-id ' + fp, 1) # still not versioned
340
runcmd('bzr add foo')
341
runcmd('bzr file-id ' + fp)
342
runcmd('bzr commit -m add-sub-file')
348
class RevertCommand(InTempDir):
350
self.runcmd('bzr init')
352
file('hello', 'wt').write('foo')
353
self.runcmd('bzr add hello')
354
self.runcmd('bzr commit -m setup hello')
356
file('hello', 'wt').write('bar')
357
self.runcmd('bzr revert hello')
358
self.check_file_contents('hello', 'foo')
364
# lists all tests from this module in the best order to run them. we
365
# do it this way rather than just discovering them all because it
366
# allows us to test more basic functions first where failures will be
367
# easiest to understand.
368
TEST_CLASSES = [TestVersion,