30
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
31
# Note: Please don't add new tests here, it's too big and bulky. Instead add
32
# them into small suites in bzrlib.tests.blackbox.test_FOO for the particular
33
# UI command/aspect that is being tested.
36
27
from cStringIO import StringIO
45
33
from bzrlib.branch import Branch
34
from bzrlib.clone import copy_branch
46
35
from bzrlib.errors import BzrCommandError
47
from bzrlib.osutils import (
52
from bzrlib.tests.http_utils import TestCaseWithWebserver
53
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
54
from bzrlib.tests.blackbox import ExternalBase
55
from bzrlib.workingtree import WorkingTree
36
from bzrlib.osutils import has_symlinks
37
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
38
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
41
class ExternalBase(TestCaseInTempDir):
43
def runbzr(self, args, retcode=0, backtick=False):
44
if isinstance(args, basestring):
48
return self.run_bzr_captured(args, retcode=retcode)[0]
50
return self.run_bzr_captured(args, retcode=retcode)
58
53
class TestCommands(ExternalBase):
55
def test_help_commands(self):
58
self.runbzr('help commands')
59
self.runbzr('help help')
60
self.runbzr('commit -h')
62
def test_init_branch(self):
65
# Can it handle subdirectories as well?
66
self.runbzr('init subdir1')
67
self.assert_(os.path.exists('subdir1'))
68
self.assert_(os.path.exists('subdir1/.bzr'))
70
self.runbzr('init subdir2/nothere', retcode=2)
73
self.runbzr('init subdir2')
74
self.runbzr('init subdir2', retcode=1)
76
self.runbzr('init subdir2/subsubdir1')
77
self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
79
def test_whoami(self):
80
# this should always identify something, if only "john@localhost"
82
self.runbzr("whoami --email")
84
self.assertEquals(self.runbzr("whoami --email",
85
backtick=True).count('@'), 1)
87
def test_whoami_branch(self):
88
"""branch specific user identity works."""
90
f = file('.bzr/email', 'wt')
91
f.write('Branch Identity <branch@identi.ty>')
93
bzr_email = os.environ.get('BZREMAIL')
94
if bzr_email is not None:
95
del os.environ['BZREMAIL']
96
whoami = self.runbzr("whoami",backtick=True)
97
whoami_email = self.runbzr("whoami --email",backtick=True)
98
self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
99
self.assertTrue(whoami_email.startswith('branch@identi.ty'))
100
# Verify that the environment variable overrides the value
102
os.environ['BZREMAIL'] = 'Different ID <other@environ.ment>'
103
whoami = self.runbzr("whoami",backtick=True)
104
whoami_email = self.runbzr("whoami --email",backtick=True)
105
self.assertTrue(whoami.startswith('Different ID <other@environ.ment>'))
106
self.assertTrue(whoami_email.startswith('other@environ.ment'))
107
if bzr_email is not None:
108
os.environ['BZREMAIL'] = bzr_email
60
110
def test_invalid_commands(self):
61
self.run_bzr("pants", retcode=3)
62
self.run_bzr("--pants off", retcode=3)
63
self.run_bzr("diff --message foo", retcode=3)
111
self.runbzr("pants", retcode=1)
112
self.runbzr("--pants off", retcode=1)
113
self.runbzr("diff --message foo", retcode=1)
115
def test_empty_commit(self):
117
self.build_tree(['hello.txt'])
118
self.runbzr("commit -m empty", retcode=1)
119
self.runbzr("add hello.txt")
120
self.runbzr("commit -m added")
122
def test_empty_commit_message(self):
124
file('foo.c', 'wt').write('int main() {}')
125
self.runbzr(['add', 'foo.c'])
126
self.runbzr(["commit", "-m", ""] , retcode=1)
128
def test_other_branch_commit(self):
129
# this branch is to ensure consistent behaviour, whether we're run
130
# inside a branch, or not.
131
os.mkdir('empty_branch')
132
os.chdir('empty_branch')
137
file('foo.c', 'wt').write('int main() {}')
138
file('bar.c', 'wt').write('int main() {}')
140
self.runbzr(['add', 'branch/foo.c'])
141
self.runbzr(['add', 'branch'])
142
# can't commit files in different trees; sane error
143
self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
144
self.runbzr('commit -m newstuff branch/foo.c')
145
self.runbzr('commit -m newstuff branch')
146
self.runbzr('commit -m newstuff branch', retcode=1)
149
def test_ignore_patterns(self):
150
from bzrlib.branch import Branch
152
b = Branch.initialize('.')
153
self.assertEquals(list(b.unknowns()), [])
155
file('foo.tmp', 'wt').write('tmp files are ignored')
156
self.assertEquals(list(b.unknowns()), [])
157
self.assertEquals(self.capture('unknowns'), '')
159
file('foo.c', 'wt').write('int main() {}')
160
self.assertEquals(list(b.unknowns()), ['foo.c'])
161
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
163
self.runbzr(['add', 'foo.c'])
164
self.assertEquals(self.capture('unknowns'), '')
166
# 'ignore' works when creating the .bzignore file
167
file('foo.blah', 'wt').write('blah')
168
self.assertEquals(list(b.unknowns()), ['foo.blah'])
169
self.runbzr('ignore *.blah')
170
self.assertEquals(list(b.unknowns()), [])
171
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\n')
173
# 'ignore' works when then .bzrignore file already exists
174
file('garh', 'wt').write('garh')
175
self.assertEquals(list(b.unknowns()), ['garh'])
176
self.assertEquals(self.capture('unknowns'), 'garh\n')
177
self.runbzr('ignore garh')
178
self.assertEquals(list(b.unknowns()), [])
179
self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
65
181
def test_revert(self):
68
184
file('hello', 'wt').write('foo')
69
self.run_bzr('add hello')
70
self.run_bzr('commit -m setup hello')
185
self.runbzr('add hello')
186
self.runbzr('commit -m setup hello')
72
188
file('goodbye', 'wt').write('baz')
73
self.run_bzr('add goodbye')
74
self.run_bzr('commit -m setup goodbye')
189
self.runbzr('add goodbye')
190
self.runbzr('commit -m setup goodbye')
76
192
file('hello', 'wt').write('bar')
77
193
file('goodbye', 'wt').write('qux')
78
self.run_bzr('revert hello')
194
self.runbzr('revert hello')
79
195
self.check_file_contents('hello', 'foo')
80
196
self.check_file_contents('goodbye', 'qux')
81
self.run_bzr('revert')
197
self.runbzr('revert')
82
198
self.check_file_contents('goodbye', 'baz')
84
200
os.mkdir('revertdir')
85
self.run_bzr('add revertdir')
86
self.run_bzr('commit -m f')
201
self.runbzr('add revertdir')
202
self.runbzr('commit -m f')
87
203
os.rmdir('revertdir')
88
self.run_bzr('revert')
204
self.runbzr('revert')
91
os.symlink('/unlikely/to/exist', 'symlink')
92
self.run_bzr('add symlink')
93
self.run_bzr('commit -m f')
95
self.run_bzr('revert')
96
self.failUnlessExists('symlink')
98
os.symlink('a-different-path', 'symlink')
99
self.run_bzr('revert')
100
self.assertEqual('/unlikely/to/exist',
101
os.readlink('symlink'))
103
self.log("skipping revert symlink tests")
206
os.symlink('/unlikely/to/exist', 'symlink')
207
self.runbzr('add symlink')
208
self.runbzr('commit -m f')
210
self.runbzr('revert')
211
self.failUnlessExists('symlink')
213
os.symlink('a-different-path', 'symlink')
214
self.runbzr('revert')
215
self.assertEqual('/unlikely/to/exist',
216
os.readlink('symlink'))
105
218
file('hello', 'wt').write('xyz')
106
self.run_bzr('commit -m xyz hello')
107
self.run_bzr('revert -r 1 hello')
219
self.runbzr('commit -m xyz hello')
220
self.runbzr('revert -r 1 hello')
108
221
self.check_file_contents('hello', 'foo')
109
self.run_bzr('revert hello')
222
self.runbzr('revert hello')
110
223
self.check_file_contents('hello', 'xyz')
111
224
os.chdir('revertdir')
112
self.run_bzr('revert')
225
self.runbzr('revert')
229
def test_mv_modes(self):
230
"""Test two modes of operation for mv"""
231
from bzrlib.branch import Branch
232
b = Branch.initialize('.')
233
self.build_tree(['a', 'c', 'subdir/'])
234
self.run_bzr_captured(['add', self.test_dir])
235
self.run_bzr_captured(['mv', 'a', 'b'])
236
self.run_bzr_captured(['mv', 'b', 'subdir'])
237
self.run_bzr_captured(['mv', 'subdir/b', 'a'])
238
self.run_bzr_captured(['mv', 'a', 'c', 'subdir'])
239
self.run_bzr_captured(['mv', 'subdir/a', 'subdir/newa'])
115
241
def test_main_version(self):
116
242
"""Check output from version command and master option is reasonable"""
117
243
# output is intentionally passed through to stdout so that we
118
244
# can see the version being tested
119
output = self.run_bzr('version')[0]
245
output = self.runbzr('version', backtick=1)
120
246
self.log('bzr version output:')
122
self.assert_(output.startswith('Bazaar (bzr) '))
248
self.assert_(output.startswith('bzr (bazaar-ng) '))
123
249
self.assertNotEqual(output.index('Canonical'), -1)
124
250
# make sure --version is consistent
125
tmp_output = self.run_bzr('--version')[0]
251
tmp_output = self.runbzr('--version', backtick=1)
252
self.log('bzr --version output:')
126
254
self.assertEquals(output, tmp_output)
128
256
def example_branch(test):
130
258
file('hello', 'wt').write('foo')
131
test.run_bzr('add hello')
132
test.run_bzr('commit -m setup hello')
259
test.runbzr('add hello')
260
test.runbzr('commit -m setup hello')
133
261
file('goodbye', 'wt').write('baz')
134
test.run_bzr('add goodbye')
135
test.run_bzr('commit -m setup goodbye')
137
def test_pull_verbose(self):
138
"""Pull changes from one branch to another and watch the output."""
143
self.example_branch()
146
self.run_bzr('branch a b')
148
open('b', 'wb').write('else\n')
149
self.run_bzr('add b')
150
self.run_bzr(['commit', '-m', 'added b'])
153
out = self.run_bzr('pull --verbose ../b')[0]
154
self.failIfEqual(out.find('Added Revisions:'), -1)
155
self.failIfEqual(out.find('message:\n added b'), -1)
156
self.failIfEqual(out.find('added b'), -1)
158
# Check that --overwrite --verbose prints out the removed entries
159
self.run_bzr('commit -m foo --unchanged')
161
self.run_bzr('commit -m baz --unchanged')
162
self.run_bzr('pull ../a', retcode=3)
163
out = self.run_bzr('pull --overwrite --verbose ../a')[0]
165
remove_loc = out.find('Removed Revisions:')
166
self.failIfEqual(remove_loc, -1)
167
added_loc = out.find('Added Revisions:')
168
self.failIfEqual(added_loc, -1)
170
removed_message = out.find('message:\n baz')
171
self.failIfEqual(removed_message, -1)
172
self.failUnless(remove_loc < removed_message < added_loc)
174
added_message = out.find('message:\n foo')
175
self.failIfEqual(added_message, -1)
176
self.failUnless(added_loc < added_message)
262
test.runbzr('add goodbye')
263
test.runbzr('commit -m setup goodbye')
265
def test_export(self):
268
self.example_branch()
269
self.runbzr('export ../latest')
270
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
271
self.runbzr('export ../first -r 1')
272
self.assert_(not os.path.exists('../first/goodbye'))
273
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
274
self.runbzr('export ../first.gz -r 1')
275
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
276
self.runbzr('export ../first.bz2 -r 1')
277
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
278
self.runbzr('export ../first.tar -r 1')
279
self.assert_(os.path.isfile('../first.tar'))
280
from tarfile import TarFile
281
tf = TarFile('../first.tar')
282
self.assert_('first/hello' in tf.getnames(), tf.getnames())
283
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
284
self.runbzr('export ../first.tar.gz -r 1')
285
self.assert_(os.path.isfile('../first.tar.gz'))
286
self.runbzr('export ../first.tbz2 -r 1')
287
self.assert_(os.path.isfile('../first.tbz2'))
288
self.runbzr('export ../first.tar.bz2 -r 1')
289
self.assert_(os.path.isfile('../first.tar.bz2'))
290
self.runbzr('export ../first.tar.tbz2 -r 1')
291
self.assert_(os.path.isfile('../first.tar.tbz2'))
292
from bz2 import BZ2File
293
tf = TarFile('../first.tar.tbz2',
294
fileobj=BZ2File('../first.tar.tbz2', 'r'))
295
self.assert_('first.tar/hello' in tf.getnames(), tf.getnames())
296
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
297
self.runbzr('export ../first2.tar -r 1 --root pizza')
298
tf = TarFile('../first2.tar')
299
self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
302
self.example_branch()
303
file('hello', 'wt').write('hello world!')
304
self.runbzr('commit -m fixing hello')
305
output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
306
self.assert_('\n+hello world!' in output)
307
output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
308
self.assert_('\n+baz' in output)
310
def test_diff_branches(self):
311
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
312
branch = Branch.initialize('branch1')
314
branch.commit('add file')
315
copy_branch(branch, 'branch2')
316
print >> open('branch2/file', 'w'), 'new content'
317
branch2 = Branch.open('branch2')
318
branch2.commit('update file')
319
# should open branch1 and diff against branch2,
320
output = self.run_bzr_captured(['diff', '-r', 'branch:branch2',
323
self.assertEquals(("=== modified file 'file'\n"
328
"+contents of branch1/file\n"
331
def test_branch(self):
332
"""Branch from one branch to another."""
335
self.example_branch()
337
self.runbzr('branch a b')
338
self.assertFileEqual('b\n', 'b/.bzr/branch-name')
339
self.runbzr('branch a c -r 1')
341
self.runbzr('commit -m foo --unchanged')
343
# naughty - abstraction violations RBC 20050928
344
print "test_branch used to delete the stores, how is this meant to work ?"
345
#shutil.rmtree('a/.bzr/revision-store')
346
#shutil.rmtree('a/.bzr/inventory-store', ignore_errors=True)
347
#shutil.rmtree('a/.bzr/text-store', ignore_errors=True)
348
self.runbzr('branch a d --basis b')
350
def test_merge(self):
351
from bzrlib.branch import Branch
355
self.example_branch()
357
self.runbzr('branch a b')
359
file('goodbye', 'wt').write('quux')
360
self.runbzr(['commit', '-m', "more u's are always good"])
363
file('hello', 'wt').write('quuux')
364
# We can't merge when there are in-tree changes
365
self.runbzr('merge ../b', retcode=1)
366
self.runbzr(['commit', '-m', "Like an epidemic of u's"])
367
self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
369
self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
370
self.runbzr('revert --no-backup')
371
self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
372
self.runbzr('revert --no-backup')
373
self.runbzr('merge ../b -r last:1..last:1 --reprocess')
374
self.runbzr('revert --no-backup')
375
self.runbzr('merge ../b -r last:1')
376
self.check_file_contents('goodbye', 'quux')
377
# Merging a branch pulls its revision into the tree
379
b = Branch.open('../b')
380
a.get_revision_xml(b.last_revision())
381
self.log('pending merges: %s', a.pending_merges())
382
self.assertEquals(a.pending_merges(), [b.last_revision()])
383
self.runbzr('commit -m merged')
384
self.runbzr('merge ../b -r last:1')
385
self.assertEqual(Branch.open('.').pending_merges(), [])
388
def test_merge_with_missing_file(self):
389
"""Merge handles missing file conflicts"""
393
print >> file('sub/a.txt', 'wb'), "hello"
394
print >> file('b.txt', 'wb'), "hello"
395
print >> file('sub/c.txt', 'wb'), "hello"
398
self.runbzr(('commit', '-m', 'added a'))
399
self.runbzr('branch . ../b')
400
print >> file('sub/a.txt', 'ab'), "there"
401
print >> file('b.txt', 'ab'), "there"
402
print >> file('sub/c.txt', 'ab'), "there"
403
self.runbzr(('commit', '-m', 'Added there'))
404
os.unlink('sub/a.txt')
405
os.unlink('sub/c.txt')
408
self.runbzr(('commit', '-m', 'Removed a.txt'))
410
print >> file('sub/a.txt', 'ab'), "something"
411
print >> file('b.txt', 'ab'), "something"
412
print >> file('sub/c.txt', 'ab'), "something"
413
self.runbzr(('commit', '-m', 'Modified a.txt'))
414
self.runbzr('merge ../a/', retcode=1)
415
self.assert_(os.path.exists('sub/a.txt.THIS'))
416
self.assert_(os.path.exists('sub/a.txt.BASE'))
418
self.runbzr('merge ../b/', retcode=1)
419
self.assert_(os.path.exists('sub/a.txt.OTHER'))
420
self.assert_(os.path.exists('sub/a.txt.BASE'))
423
"""Pull changes from one branch to another."""
427
self.example_branch()
428
self.runbzr('pull', retcode=1)
429
self.runbzr('missing', retcode=1)
430
self.runbzr('missing .')
431
self.runbzr('missing')
433
self.runbzr('pull /', retcode=1)
437
self.runbzr('branch a b')
441
self.runbzr('add subdir')
442
self.runbzr('commit -m blah --unchanged')
445
b = Branch.open('../b')
446
self.assertEquals(a.revision_history(), b.revision_history()[:-1])
447
self.runbzr('pull ../b')
448
self.assertEquals(a.revision_history(), b.revision_history())
449
self.runbzr('commit -m blah2 --unchanged')
451
self.runbzr('commit -m blah3 --unchanged')
453
self.runbzr('pull ../a', retcode=1)
455
self.runbzr('branch b overwriteme')
456
os.chdir('overwriteme')
457
self.runbzr('pull --overwrite ../a')
458
overwritten = Branch.open('.')
459
self.assertEqual(overwritten.revision_history(),
460
a.revision_history())
462
self.runbzr('merge ../b')
463
self.runbzr('commit -m blah4 --unchanged')
464
os.chdir('../b/subdir')
465
self.runbzr('pull ../../a')
466
self.assertEquals(a.revision_history()[-1], b.revision_history()[-1])
467
self.runbzr('commit -m blah5 --unchanged')
468
self.runbzr('commit -m blah6 --unchanged')
470
self.runbzr('pull ../a')
472
self.runbzr('commit -m blah7 --unchanged')
473
self.runbzr('merge ../b')
474
self.runbzr('commit -m blah8 --unchanged')
475
self.runbzr('pull ../b')
476
self.runbzr('pull ../b')
479
"""Test the abilities of 'bzr ls'"""
481
def bzrout(*args, **kwargs):
482
kwargs['backtick'] = True
483
return self.runbzr(*args, **kwargs)
485
def ls_equals(value, *args):
486
out = self.runbzr(['ls'] + list(args), backtick=True)
487
self.assertEquals(out, value)
490
open('a', 'wb').write('hello\n')
493
bzr('ls --verbose --null', retcode=1)
496
ls_equals('? a\n', '--verbose')
497
ls_equals('a\n', '--unknown')
498
ls_equals('', '--ignored')
499
ls_equals('', '--versioned')
500
ls_equals('a\n', '--unknown', '--ignored', '--versioned')
501
ls_equals('', '--ignored', '--versioned')
502
ls_equals('a\0', '--null')
505
ls_equals('V a\n', '--verbose')
512
open('subdir/b', 'wb').write('b\n')
518
bzr('commit -m subdir')
526
, '--verbose', '--non-recursive')
528
# Check what happens in a sub-directory
540
, '--from-root', '--null')
543
, '--from-root', '--non-recursive')
547
# Check what happens when we supply a specific revision
548
ls_equals('a\n', '--revision', '1')
550
, '--verbose', '--revision', '1')
553
ls_equals('', '--revision', '1')
555
# Now try to do ignored files.
557
open('blah.py', 'wb').write('unknown\n')
558
open('blah.pyo', 'wb').write('ignored\n')
570
ls_equals('blah.pyo\n'
572
ls_equals('blah.py\n'
178
580
def test_locations(self):
179
581
"""Using and remembering different locations"""
183
self.run_bzr('commit -m unchanged --unchanged')
184
self.run_bzr('pull', retcode=3)
185
self.run_bzr('merge', retcode=3)
186
self.run_bzr('branch . ../b')
585
self.runbzr('commit -m unchanged --unchanged')
586
self.runbzr('pull', retcode=1)
587
self.runbzr('merge', retcode=1)
588
self.runbzr('branch . ../b')
189
self.run_bzr('branch . ../c')
190
self.run_bzr('pull ../c')
191
self.run_bzr('merge')
591
self.runbzr('branch . ../c')
592
self.runbzr('pull ../c')
193
self.run_bzr('pull ../b')
195
self.run_bzr('pull ../c')
196
self.run_bzr('branch ../c ../d')
197
osutils.rmtree('../c')
595
self.runbzr('pull ../b')
597
self.runbzr('pull ../c')
598
self.runbzr('branch ../c ../d')
599
shutil.rmtree('../c')
202
self.run_bzr('pull', retcode=3)
203
self.run_bzr('pull ../a --remember')
604
self.runbzr('pull', retcode=1)
605
self.runbzr('pull ../a --remember')
608
def test_add_reports(self):
609
"""add command prints the names of added files."""
610
b = Branch.initialize('.')
611
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
612
out = self.run_bzr_captured(['add'], retcode = 0)[0]
613
# the ordering is not defined at the moment
614
results = sorted(out.rstrip('\n').split('\n'))
615
self.assertEquals(['added dir',
616
'added dir'+os.sep+'sub.txt',
620
def test_add_quiet_is(self):
621
"""add -q does not print the names of added files."""
622
b = Branch.initialize('.')
623
self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
624
out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
625
# the ordering is not defined at the moment
626
results = sorted(out.rstrip('\n').split('\n'))
627
self.assertEquals([''], results)
206
629
def test_unknown_command(self):
207
630
"""Handling of unknown command."""
208
out, err = self.run_bzr('fluffy-badger', retcode=3)
631
out, err = self.run_bzr_captured(['fluffy-badger'],
209
633
self.assertEquals(out, '')
210
634
err.index('unknown command')
212
def create_conflicts(self):
213
"""Create a conflicted tree"""
636
def test_conflicts(self):
637
"""Handling of merge conflicts"""
216
640
file('hello', 'wb').write("hi world")
217
641
file('answer', 'wb').write("42")
220
self.run_bzr('commit -m base')
221
self.run_bzr('branch . ../other')
222
self.run_bzr('branch . ../this')
644
self.runbzr('commit -m base')
645
self.runbzr('branch . ../other')
646
self.runbzr('branch . ../this')
223
647
os.chdir('../other')
224
648
file('hello', 'wb').write("Hello.")
225
649
file('answer', 'wb').write("Is anyone there?")
226
self.run_bzr('commit -m other')
650
self.runbzr('commit -m other')
227
651
os.chdir('../this')
228
652
file('hello', 'wb').write("Hello, world")
229
self.run_bzr('mv answer question')
653
self.runbzr('mv answer question')
230
654
file('question', 'wb').write("What do you get when you multiply six"
232
self.run_bzr('commit -m this')
234
def test_status(self):
238
self.run_bzr('commit --unchanged --message f')
239
self.run_bzr('branch . ../branch2')
240
self.run_bzr('branch . ../branch3')
241
self.run_bzr('commit --unchanged --message peter')
242
os.chdir('../branch2')
243
self.run_bzr('merge ../branch1')
244
self.run_bzr('commit --unchanged --message pumpkin')
245
os.chdir('../branch3')
246
self.run_bzr('merge ../branch2')
247
message = self.run_bzr('status')[0]
250
def test_conflicts(self):
251
"""Handling of merge conflicts"""
252
self.create_conflicts()
253
self.run_bzr('merge ../other --show-base', retcode=1)
656
self.runbzr('commit -m this')
657
self.runbzr('merge ../other --show-base', retcode=1)
254
658
conflict_text = file('hello').read()
255
659
self.assert_('<<<<<<<' in conflict_text)
256
660
self.assert_('>>>>>>>' in conflict_text)
257
661
self.assert_('=======' in conflict_text)
258
662
self.assert_('|||||||' in conflict_text)
259
663
self.assert_('hi world' in conflict_text)
260
self.run_bzr('revert')
261
self.run_bzr('resolve --all')
262
self.run_bzr('merge ../other', retcode=1)
664
self.runbzr('revert')
665
self.runbzr('resolve --all')
666
self.runbzr('merge ../other', retcode=1)
263
667
conflict_text = file('hello').read()
264
668
self.assert_('|||||||' not in conflict_text)
265
669
self.assert_('hi world' not in conflict_text)
266
result = self.run_bzr('conflicts')[0]
267
self.assertEquals(result, "Text conflict in hello\nText conflict in"
269
result = self.run_bzr('status')[0]
270
self.assert_("conflicts:\n Text conflict in hello\n"
271
" Text conflict in question\n" in result, result)
272
self.run_bzr('resolve hello')
273
result = self.run_bzr('conflicts')[0]
274
self.assertEquals(result, "Text conflict in question\n")
275
self.run_bzr('commit -m conflicts', retcode=3)
276
self.run_bzr('resolve --all')
277
result = self.run_bzr('conflicts')[0]
278
self.run_bzr('commit -m conflicts')
670
result = self.runbzr('conflicts', backtick=1)
671
self.assertEquals(result, "hello\nquestion\n")
672
result = self.runbzr('status', backtick=1)
673
self.assert_("conflicts:\n hello\n question\n" in result, result)
674
self.runbzr('resolve hello')
675
result = self.runbzr('conflicts', backtick=1)
676
self.assertEquals(result, "question\n")
677
self.runbzr('commit -m conflicts', retcode=1)
678
self.runbzr('resolve --all')
679
result = self.runbzr('conflicts', backtick=1)
680
self.runbzr('commit -m conflicts')
279
681
self.assertEquals(result, "")
683
def test_resign(self):
684
"""Test re signing of data."""
686
oldstrategy = bzrlib.gpg.GPGStrategy
687
branch = Branch.initialize('.')
688
branch.commit("base", allow_pointless=True, rev_id='A')
690
# monkey patch gpg signing mechanism
691
from bzrlib.testament import Testament
692
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
693
self.runbzr('re-sign -r revid:A')
694
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
695
branch.revision_store.get('A', 'sig').read())
697
bzrlib.gpg.GPGStrategy = oldstrategy
699
def test_resign_range(self):
701
oldstrategy = bzrlib.gpg.GPGStrategy
702
branch = Branch.initialize('.')
703
branch.commit("base", allow_pointless=True, rev_id='A')
704
branch.commit("base", allow_pointless=True, rev_id='B')
705
branch.commit("base", allow_pointless=True, rev_id='C')
707
# monkey patch gpg signing mechanism
708
from bzrlib.testament import Testament
709
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
710
self.runbzr('re-sign -r 1..')
711
self.assertEqual(Testament.from_revision(branch,'A').as_short_text(),
712
branch.revision_store.get('A', 'sig').read())
713
self.assertEqual(Testament.from_revision(branch,'B').as_short_text(),
714
branch.revision_store.get('B', 'sig').read())
715
self.assertEqual(Testament.from_revision(branch,'C').as_short_text(),
716
branch.revision_store.get('C', 'sig').read())
718
bzrlib.gpg.GPGStrategy = oldstrategy
281
720
def test_push(self):
282
721
# create a source branch
283
722
os.mkdir('my-branch')
395
791
f.write('hello world!\n')
398
self.assertEquals(self.run_bzr('unknowns')[0], 'test.txt\n')
794
self.assertEquals(capture('unknowns'), 'test.txt\n')
400
out = self.run_bzr("status")[0]
796
out = capture("status")
401
797
self.assertEquals(out, 'unknown:\n test.txt\n')
799
out = capture("status --all")
800
self.assertEquals(out, "unknown:\n test.txt\n")
802
out = capture("status test.txt --all")
803
self.assertEquals(out, "unknown:\n test.txt\n")
403
805
f = file('test2.txt', 'wt')
404
806
f.write('goodbye cruel world...\n')
407
out = self.run_bzr("status test.txt")[0]
809
out = capture("status test.txt")
408
810
self.assertEquals(out, "unknown:\n test.txt\n")
410
out = self.run_bzr("status")[0]
812
out = capture("status")
411
813
self.assertEquals(out, ("unknown:\n" " test.txt\n" " test2.txt\n"))
413
815
os.unlink('test2.txt')
415
817
progress("command aliases")
416
out = self.run_bzr("st")[0]
818
out = capture("st --all")
417
819
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
419
out = self.run_bzr("stat")[0]
821
out = capture("stat")
420
822
self.assertEquals(out, ("unknown:\n" " test.txt\n"))
422
824
progress("command help")
423
self.run_bzr("help st")
425
self.run_bzr("help commands")
426
self.run_bzr("help slartibartfast", retcode=3)
428
out = self.run_bzr("help ci")[0]
429
out.index('Aliases: ci, checkin\n')
827
runbzr("help commands")
828
runbzr("help slartibartfast", 1)
830
out = capture("help ci")
831
out.index('aliases: ')
833
progress("can't rename unversioned file")
834
runbzr("rename test.txt new-test.txt", 1)
836
progress("adding a file")
838
runbzr("add test.txt")
839
self.assertEquals(capture("unknowns"), '')
840
self.assertEquals(capture("status --all"), ("added:\n" " test.txt\n"))
842
progress("rename newly-added file")
843
runbzr("rename test.txt hello.txt")
844
self.assert_(os.path.exists("hello.txt"))
845
self.assert_(not os.path.exists("test.txt"))
847
self.assertEquals(capture("revno"), '0\n')
849
progress("add first revision")
850
runbzr(['commit', '-m', 'add first revision'])
852
progress("more complex renames")
854
runbzr("rename hello.txt sub1", 1)
855
runbzr("rename hello.txt sub1/hello.txt", 1)
856
runbzr("move hello.txt sub1", 1)
859
runbzr("rename sub1 sub2")
860
runbzr("move hello.txt sub2")
861
self.assertEqual(capture("relpath sub2/hello.txt"),
862
os.path.join("sub2", "hello.txt\n"))
864
self.assert_(exists("sub2"))
865
self.assert_(exists("sub2/hello.txt"))
866
self.assert_(not exists("sub1"))
867
self.assert_(not exists("hello.txt"))
869
runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
873
runbzr('move sub2/hello.txt sub1')
874
self.assert_(not exists('sub2/hello.txt'))
875
self.assert_(exists('sub1/hello.txt'))
876
runbzr('move sub2 sub1')
877
self.assert_(not exists('sub2'))
878
self.assert_(exists('sub1/sub2'))
880
runbzr(['commit', '-m', 'rename nested subdirectories'])
883
self.assertEquals(capture('root')[:-1],
884
os.path.join(self.test_dir, 'branch1'))
885
runbzr('move ../hello.txt .')
886
self.assert_(exists('./hello.txt'))
887
self.assertEquals(capture('relpath hello.txt'),
888
os.path.join('sub1', 'sub2', 'hello.txt') + '\n')
889
self.assertEquals(capture('relpath ../../sub1/sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
890
runbzr(['commit', '-m', 'move to parent directory'])
892
self.assertEquals(capture('relpath sub2/hello.txt'), os.path.join('sub1', 'sub2', 'hello.txt\n'))
894
runbzr('move sub2/hello.txt .')
895
self.assert_(exists('hello.txt'))
431
897
f = file('hello.txt', 'wt')
432
898
f.write('some nice new content\n')
435
self.run_bzr("add hello.txt")
437
901
f = file('msg.tmp', 'wt')
438
902
f.write('this is my new commit\nand it has multiple lines, for fun')
441
self.run_bzr('commit -F msg.tmp')
443
self.assertEquals(self.run_bzr('revno')[0], '1\n')
444
self.run_bzr('export -r 1 export-1.tmp')
445
self.run_bzr('export export.tmp')
448
self.run_bzr('log -v')
449
self.run_bzr('log -v --forward')
450
self.run_bzr('log -m', retcode=3)
451
log_out = self.run_bzr('log -m commit')[0]
905
runbzr('commit -F msg.tmp')
907
self.assertEquals(capture('revno'), '5\n')
908
runbzr('export -r 5 export-5.tmp')
909
runbzr('export export.tmp')
913
runbzr('log -v --forward')
914
runbzr('log -m', retcode=1)
915
log_out = capture('log -m commit')
452
916
self.assert_("this is my new commit\n and" in log_out)
453
917
self.assert_("rename nested" not in log_out)
454
918
self.assert_('revision-id' not in log_out)
455
self.assert_('revision-id' in self.run_bzr('log --show-ids -m commit')[0])
919
self.assert_('revision-id' in capture('log --show-ids -m commit'))
457
log_out = self.run_bzr('log --line')[0]
458
# determine the widest line we want
459
max_width = terminal_width() - 1
921
log_out = capture('log --line')
460
922
for line in log_out.splitlines():
461
self.assert_(len(line) <= max_width, len(line))
462
self.assert_("this is my new commit and" not in log_out)
463
self.assert_("this is my new commit" in log_out)
923
self.assert_(len(line) <= 79, len(line))
924
self.assert_("this is my new commit and" in log_out)
465
927
progress("file with spaces in name")
466
928
mkdir('sub directory')
467
929
file('sub directory/file with spaces ', 'wt').write('see how this works\n')
468
self.run_bzr('add .')
469
self.run_bzr('diff', retcode=1)
470
self.run_bzr('commit -m add-spaces')
471
self.run_bzr('check')
474
self.run_bzr('log --forward')
931
runbzr('diff', retcode=1)
932
runbzr('commit -m add-spaces')
936
runbzr('log --forward')
478
940
if has_symlinks():
479
941
progress("symlinks")
480
942
mkdir('symlinks')
481
943
chdir('symlinks')
483
945
os.symlink("NOWHERE1", "link1")
484
self.run_bzr('add link1')
485
self.assertEquals(self.run_bzr('unknowns')[0], '')
486
self.run_bzr(['commit', '-m', '1: added symlink link1'])
947
self.assertEquals(self.capture('unknowns'), '')
948
runbzr(['commit', '-m', '1: added symlink link1'])
489
self.run_bzr('add d1')
490
self.assertEquals(self.run_bzr('unknowns')[0], '')
952
self.assertEquals(self.capture('unknowns'), '')
491
953
os.symlink("NOWHERE2", "d1/link2")
492
self.assertEquals(self.run_bzr('unknowns')[0], 'd1/link2\n')
954
self.assertEquals(self.capture('unknowns'), 'd1/link2\n')
493
955
# is d1/link2 found when adding d1
494
self.run_bzr('add d1')
495
self.assertEquals(self.run_bzr('unknowns')[0], '')
957
self.assertEquals(self.capture('unknowns'), '')
496
958
os.symlink("NOWHERE3", "d1/link3")
497
self.assertEquals(self.run_bzr('unknowns')[0], 'd1/link3\n')
498
self.run_bzr(['commit', '-m', '2: added dir, symlink'])
500
self.run_bzr('rename d1 d2')
501
self.run_bzr('move d2/link2 .')
502
self.run_bzr('move link1 d2')
959
self.assertEquals(self.capture('unknowns'), 'd1/link3\n')
960
runbzr(['commit', '-m', '2: added dir, symlink'])
962
runbzr('rename d1 d2')
963
runbzr('move d2/link2 .')
964
runbzr('move link1 d2')
503
965
self.assertEquals(os.readlink("./link2"), "NOWHERE2")
504
966
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
505
self.run_bzr('add d2/link3')
506
self.run_bzr('diff', retcode=1)
507
self.run_bzr(['commit', '-m',
508
'3: rename of dir, move symlinks, add link3'])
967
runbzr('add d2/link3')
968
runbzr('diff', retcode=1)
969
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
510
971
os.unlink("link2")
511
972
os.symlink("TARGET 2", "link2")
512
973
os.unlink("d2/link1")
513
974
os.symlink("TARGET 1", "d2/link1")
514
self.run_bzr('diff', retcode=1)
515
self.assertEquals(self.run_bzr("relpath d2/link1")[0], "d2/link1\n")
516
self.run_bzr(['commit', '-m', '4: retarget of two links'])
518
self.run_bzr('remove --keep d2/link1')
519
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
520
self.run_bzr(['commit', '-m', '5: remove d2/link1'])
975
runbzr('diff', retcode=1)
976
self.assertEquals(self.capture("relpath d2/link1"), "d2/link1\n")
977
runbzr(['commit', '-m', '4: retarget of two links'])
979
runbzr('remove d2/link1')
980
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
981
runbzr(['commit', '-m', '5: remove d2/link1'])
521
982
# try with the rm alias
522
self.run_bzr('add d2/link1')
523
self.run_bzr(['commit', '-m', '6: add d2/link1'])
524
self.run_bzr('rm --keep d2/link1')
525
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
526
self.run_bzr(['commit', '-m', '7: remove d2/link1'])
983
runbzr('add d2/link1')
984
runbzr(['commit', '-m', '6: add d2/link1'])
985
runbzr('rm d2/link1')
986
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
987
runbzr(['commit', '-m', '7: remove d2/link1'])
529
self.run_bzr('add d1')
530
self.run_bzr('rename d2/link3 d1/link3new')
531
self.assertEquals(self.run_bzr('unknowns')[0], 'd2/link1\n')
532
self.run_bzr(['commit', '-m',
533
'8: remove d2/link1, move/rename link3'])
535
self.run_bzr('check')
537
self.run_bzr('export -r 1 exp1.tmp')
991
runbzr('rename d2/link3 d1/link3new')
992
self.assertEquals(self.capture('unknowns'), 'd2/link1\n')
993
runbzr(['commit', '-m', '8: remove d2/link1, move/rename link3'])
997
runbzr(['export', '-r', '1', 'exp1.tmp'])
538
998
chdir("exp1.tmp")
539
999
self.assertEquals(listdir_sorted("."), [ "link1" ])
540
1000
self.assertEquals(os.readlink("link1"), "NOWHERE1")
543
self.run_bzr('export -r 2 exp2.tmp')
1003
runbzr(['export', '-r', '2', 'exp2.tmp'])
544
1004
chdir("exp2.tmp")
545
1005
self.assertEquals(listdir_sorted("."), [ "d1", "link1" ])
548
self.run_bzr('export -r 3 exp3.tmp')
1008
runbzr(['export', '-r', '3', 'exp3.tmp'])
549
1009
chdir("exp3.tmp")
550
1010
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
551
1011
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
552
1012
self.assertEquals(os.readlink("d2/link1"), "NOWHERE1")
553
1013
self.assertEquals(os.readlink("link2") , "NOWHERE2")
556
self.run_bzr('export -r 4 exp4.tmp')
1016
runbzr(['export', '-r', '4', 'exp4.tmp'])
557
1017
chdir("exp4.tmp")
558
1018
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
559
1019
self.assertEquals(os.readlink("d2/link1"), "TARGET 1")
560
1020
self.assertEquals(os.readlink("link2") , "TARGET 2")
561
1021
self.assertEquals(listdir_sorted("d2"), [ "link1", "link3" ])
564
self.run_bzr('export -r 5 exp5.tmp')
1024
runbzr(['export', '-r', '5', 'exp5.tmp'])
565
1025
chdir("exp5.tmp")
566
1026
self.assertEquals(listdir_sorted("."), [ "d2", "link2" ])
567
1027
self.assert_(os.path.islink("link2"))
568
1028
self.assert_(listdir_sorted("d2")== [ "link3" ])
571
self.run_bzr('export -r 8 exp6.tmp')
1031
runbzr(['export', '-r', '8', 'exp6.tmp'])
572
1032
chdir("exp6.tmp")
573
1033
self.assertEqual(listdir_sorted("."), [ "d1", "d2", "link2"])
574
1034
self.assertEquals(listdir_sorted("d1"), [ "link3new" ])