38
35
# If forced, it should succeed, but this is not tested here.
39
36
self.run_bzr("init")
40
37
self.build_tree(['hello.txt'])
41
out,err = self.run_bzr('commit -m empty', retcode=3)
38
out,err = self.run_bzr("commit", "-m", "empty", retcode=3)
42
39
self.assertEqual('', out)
43
40
self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
44
41
' use --unchanged to commit anyhow\n')
43
def test_save_commit_message(self):
44
"""Failed commit should save the message in a file"""
46
out,err = self.run_bzr("commit", "-m", "message", retcode=3)
47
self.assertEqual('', out)
48
self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
49
' use --unchanged to commit anyhow\n'
50
'Commit message saved. To reuse the message,'
51
' do\nbzr commit --file ')
52
message_file = re.compile('bzr-commit-\S*').search(err).group()
53
self.check_file_contents(message_file, 'message')
46
55
def test_commit_success(self):
47
56
"""Successful commit should not leave behind a bzr-commit-* file"""
48
57
self.run_bzr("init")
49
self.run_bzr('commit --unchanged -m message')
50
self.assertEqual('', self.run_bzr('unknowns')[0])
58
self.run_bzr("commit", "--unchanged", "-m", "message")
59
self.assertEqual('', self.capture('unknowns'))
52
61
# same for unicode messages
53
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
54
self.assertEqual('', self.run_bzr('unknowns')[0])
62
self.run_bzr("commit", "--unchanged", "-m", u'foo\xb5')
63
self.assertEqual('', self.capture('unknowns'))
56
65
def test_commit_with_path(self):
57
66
"""Commit tree with path of root specified"""
58
self.run_bzr('init a')
67
self.run_bzr('init', 'a')
59
68
self.build_tree(['a/a_file'])
60
self.run_bzr('add a/a_file')
61
self.run_bzr(['commit', '-m', 'first commit', 'a'])
69
self.run_bzr('add', 'a/a_file')
70
self.run_bzr('commit', '-m', 'first commit', 'a')
63
self.run_bzr('branch a b')
72
self.run_bzr('branch', 'a', 'b')
64
73
self.build_tree_contents([('b/a_file', 'changes in b')])
65
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
74
self.run_bzr('commit', '-m', 'first commit in b', 'b')
67
76
self.build_tree_contents([('a/a_file', 'new contents')])
68
self.run_bzr(['commit', '-m', 'change in a', 'a'])
77
self.run_bzr('commit', '-m', 'change in a', 'a')
71
self.run_bzr('merge ../a', retcode=1) # will conflict
80
self.run_bzr('merge', '../a', retcode=1) # will conflict
73
self.run_bzr('resolved b/a_file')
74
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
82
self.run_bzr('resolved', 'b/a_file')
83
self.run_bzr('commit', '-m', 'merge into b', 'b')
77
86
def test_10_verbose_commit(self):
78
87
"""Add one file and examine verbose commit output"""
80
89
self.build_tree(['hello.txt'])
81
self.run_bzr("add hello.txt")
82
out,err = self.run_bzr('commit -m added')
90
self.runbzr("add hello.txt")
91
out,err = self.run_bzr("commit", "-m", "added")
83
92
self.assertEqual('', out)
84
93
self.assertEqual('added hello.txt\n'
85
94
'Committed revision 1.\n',
211
220
'added newfile\n'
212
221
'renamed dirtorename => renameddir\n'
213
'renamed filetorename => renamedfile\n'
214
222
'renamed dirtoreparent => renameddir/reparenteddir\n'
215
223
'renamed filetoreparent => renameddir/reparentedfile\n'
224
'renamed filetorename => renamedfile\n'
216
225
'deleted dirtoremove\n'
217
226
'deleted filetoremove\n'
218
227
'Committed revision 2.\n',
221
230
def test_empty_commit_message(self):
223
232
file('foo.c', 'wt').write('int main() {}')
224
self.run_bzr('add foo.c')
225
self.run_bzr('commit -m ""', retcode=3)
233
self.runbzr(['add', 'foo.c'])
234
self.runbzr(["commit", "-m", ""] , retcode=3)
227
236
def test_other_branch_commit(self):
228
237
# this branch is to ensure consistent behaviour, whether we're run
229
238
# inside a branch, or not.
230
239
os.mkdir('empty_branch')
231
240
os.chdir('empty_branch')
233
242
os.mkdir('branch')
234
243
os.chdir('branch')
236
245
file('foo.c', 'wt').write('int main() {}')
237
246
file('bar.c', 'wt').write('int main() {}')
239
self.run_bzr('add branch/foo.c')
240
self.run_bzr('add branch')
248
self.runbzr(['add', 'branch/foo.c'])
249
self.runbzr(['add', 'branch'])
241
250
# can't commit files in different trees; sane error
242
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
243
self.run_bzr('commit -m newstuff branch/foo.c')
244
self.run_bzr('commit -m newstuff branch')
245
self.run_bzr('commit -m newstuff branch', retcode=3)
251
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
252
self.runbzr('commit -m newstuff branch/foo.c')
253
self.runbzr('commit -m newstuff branch')
254
self.runbzr('commit -m newstuff branch', retcode=3)
247
256
def test_out_of_date_tree_commit(self):
248
257
# check we get an error code and a clear message committing with an out
249
258
# of date checkout
250
259
self.make_branch_and_tree('branch')
251
260
# make a checkout
252
self.run_bzr('checkout --lightweight branch checkout')
261
self.runbzr('checkout --lightweight branch checkout')
253
262
# commit to the original branch to make the checkout out of date
254
self.run_bzr('commit --unchanged -m message branch')
263
self.runbzr('commit --unchanged -m message branch')
255
264
# now commit to the checkout should emit
256
265
# ERROR: Out of date with the branch, 'bzr update' is suggested
257
output = self.run_bzr('commit --unchanged -m checkout_message '
266
output = self.runbzr('commit --unchanged -m checkout_message '
258
267
'checkout', retcode=3)
259
268
self.assertEqual(output,
275
284
# past. This is a user story reported to fail in bug #43959 where
276
285
# a merge done in a checkout (using the update command) failed to
277
286
# commit correctly.
278
self.run_bzr('init trunk')
287
self.run_bzr('init', 'trunk')
280
self.run_bzr('checkout trunk u1')
289
self.run_bzr('checkout', 'trunk', 'u1')
281
290
self.build_tree_contents([('u1/hosts', 'initial contents')])
282
self.run_bzr('add u1/hosts')
283
self.run_bzr('commit -m add-hosts u1')
291
self.run_bzr('add', 'u1/hosts')
292
self.run_bzr('commit', '-m', 'add hosts', 'u1')
285
self.run_bzr('checkout trunk u2')
294
self.run_bzr('checkout', 'trunk', 'u2')
286
295
self.build_tree_contents([('u2/hosts', 'altered in u2')])
287
self.run_bzr('commit -m checkin-from-u2 u2')
296
self.run_bzr('commit', '-m', 'checkin from u2', 'u2')
289
298
# make an offline commits
290
299
self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
291
self.run_bzr('commit -m checkin-offline --local u1')
300
self.run_bzr('commit', '-m', 'checkin offline', '--local', 'u1')
293
302
# now try to pull in online work from u2, and then commit our offline
294
303
# work as a merge
295
304
# retcode 1 as we expect a text conflict
296
self.run_bzr('update u1', retcode=1)
297
self.run_bzr('resolved u1/hosts')
305
self.run_bzr('update', 'u1', retcode=1)
306
self.run_bzr('resolved', 'u1/hosts')
298
307
# add a text change here to represent resolving the merge conflicts in
299
308
# favour of a new version of the file not identical to either the u1
300
309
# version or the u2 version.
301
310
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
302
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
311
self.run_bzr('commit', '-m', 'checkin merge of the offline work from u1', 'u1')
304
313
def test_commit_respects_spec_for_removals(self):
305
314
"""Commit with a file spec should only commit removals that match"""
309
318
t.commit('Create')
310
319
t.remove(['file-a', 'dir-a/file-b'])
311
320
os.chdir('dir-a')
312
result = self.run_bzr('commit . -m removed-file-b')[1]
321
result = self.run_bzr('commit', '.', '-m' 'removed file-b')[1]
313
322
self.assertNotContainsRe(result, 'file-a')
314
323
result = self.run_bzr('status')[0]
315
324
self.assertContainsRe(result, 'removed:\n file-a')
317
def test_strict_commit(self):
318
"""Commit with --strict works if everything is known"""
319
ignores._set_user_ignores([])
320
tree = self.make_branch_and_tree('tree')
321
self.build_tree(['tree/a'])
323
# A simple change should just work
324
self.run_bzr('commit --strict -m adding-a',
327
def test_strict_commit_no_changes(self):
328
"""commit --strict gives "no changes" if there is nothing to commit"""
329
tree = self.make_branch_and_tree('tree')
330
self.build_tree(['tree/a'])
332
tree.commit('adding a')
334
# With no changes, it should just be 'no changes'
335
# Make sure that commit is failing because there is nothing to do
336
self.run_bzr_error(['no changes to commit'],
337
'commit --strict -m no-changes',
340
# But --strict doesn't care if you supply --unchanged
341
self.run_bzr('commit --strict --unchanged -m no-changes',
344
def test_strict_commit_unknown(self):
345
"""commit --strict fails if a file is unknown"""
346
tree = self.make_branch_and_tree('tree')
347
self.build_tree(['tree/a'])
349
tree.commit('adding a')
351
# Add one file so there is a change, but forget the other
352
self.build_tree(['tree/b', 'tree/c'])
354
self.run_bzr_error(['Commit refused because there are unknown files'],
355
'commit --strict -m add-b',
358
# --no-strict overrides --strict
359
self.run_bzr('commit --strict -m add-b --no-strict',
362
def test_fixes_bug_output(self):
363
"""commit --fixes=lp:23452 succeeds without output."""
364
tree = self.make_branch_and_tree('tree')
365
self.build_tree(['tree/hello.txt'])
366
tree.add('hello.txt')
367
output, err = self.run_bzr(
368
'commit -m hello --fixes=lp:23452 tree/hello.txt')
369
self.assertEqual('', output)
370
self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
372
def test_no_bugs_no_properties(self):
373
"""If no bugs are fixed, the bugs property is not set.
375
see https://beta.launchpad.net/bzr/+bug/109613
377
tree = self.make_branch_and_tree('tree')
378
self.build_tree(['tree/hello.txt'])
379
tree.add('hello.txt')
380
self.run_bzr( 'commit -m hello tree/hello.txt')
381
# Get the revision properties, ignoring the branch-nick property, which
382
# we don't care about for this test.
383
last_rev = tree.branch.repository.get_revision(tree.last_revision())
384
properties = dict(last_rev.properties)
385
del properties['branch-nick']
386
self.assertFalse('bugs' in properties)
388
def test_fixes_bug_sets_property(self):
389
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
390
tree = self.make_branch_and_tree('tree')
391
self.build_tree(['tree/hello.txt'])
392
tree.add('hello.txt')
393
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
395
# Get the revision properties, ignoring the branch-nick property, which
396
# we don't care about for this test.
397
last_rev = tree.branch.repository.get_revision(tree.last_revision())
398
properties = dict(last_rev.properties)
399
del properties['branch-nick']
401
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
404
def test_fixes_multiple_bugs_sets_properties(self):
405
"""--fixes can be used more than once to show that bugs are fixed."""
406
tree = self.make_branch_and_tree('tree')
407
self.build_tree(['tree/hello.txt'])
408
tree.add('hello.txt')
409
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
412
# Get the revision properties, ignoring the branch-nick property, which
413
# we don't care about for this test.
414
last_rev = tree.branch.repository.get_revision(tree.last_revision())
415
properties = dict(last_rev.properties)
416
del properties['branch-nick']
419
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
420
'https://launchpad.net/bugs/235 fixed'},
423
def test_fixes_bug_with_alternate_trackers(self):
424
"""--fixes can be used on a properly configured branch to mark bug
425
fixes on multiple trackers.
427
tree = self.make_branch_and_tree('tree')
428
tree.branch.get_config().set_user_option(
429
'trac_twisted_url', 'http://twistedmatrix.com/trac')
430
self.build_tree(['tree/hello.txt'])
431
tree.add('hello.txt')
432
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
434
# Get the revision properties, ignoring the branch-nick property, which
435
# we don't care about for this test.
436
last_rev = tree.branch.repository.get_revision(tree.last_revision())
437
properties = dict(last_rev.properties)
438
del properties['branch-nick']
441
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
442
'http://twistedmatrix.com/trac/ticket/235 fixed'},
445
def test_fixes_unknown_bug_prefix(self):
446
tree = self.make_branch_and_tree('tree')
447
self.build_tree(['tree/hello.txt'])
448
tree.add('hello.txt')
450
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
451
'commit -m add-b --fixes=xxx:123',
454
def test_fixes_invalid_bug_number(self):
455
tree = self.make_branch_and_tree('tree')
456
self.build_tree(['tree/hello.txt'])
457
tree.add('hello.txt')
459
["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
460
'commit -m add-b --fixes=lp:orange',
463
def test_fixes_invalid_argument(self):
464
"""Raise an appropriate error when the fixes argument isn't tag:id."""
465
tree = self.make_branch_and_tree('tree')
466
self.build_tree(['tree/hello.txt'])
467
tree.add('hello.txt')
469
[r"Invalid bug orange. Must be in the form of 'tag:id'\. "
470
r"Commit refused\."],
471
'commit -m add-b --fixes=orange',