1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2006-2012 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for the commit CLI of bzr."""
24
from bzrlib.branch import Branch
25
from bzrlib.bzrdir import BzrDir
26
from bzrlib.errors import BzrCommandError
27
from bzrlib.tests.blackbox import ExternalBase
28
from bzrlib.workingtree import WorkingTree
31
class TestCommit(ExternalBase):
25
from testtools.matchers import DocTestMatches
33
from bzrlib.controldir import ControlDir
34
from bzrlib.tests import (
38
from bzrlib.tests import TestCaseWithTransport
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
42
class TestCommit(TestCaseWithTransport):
33
44
def test_05_empty_commit(self):
34
45
"""Commit of tree with no versioned files should fail"""
35
46
# If forced, it should succeed, but this is not tested here.
47
self.make_branch_and_tree('.')
37
48
self.build_tree(['hello.txt'])
38
self.runbzr("commit -m empty", retcode=3)
49
out,err = self.run_bzr('commit -m empty', retcode=3)
50
self.assertEqual('', out)
52
# 1) We really don't want 'aborting commit write group' anymore.
53
# 2) bzr: ERROR: is a really long line, so we wrap it with '\'
58
bzr: ERROR: No changes to commit.\
59
Please 'bzr add' the files you want to commit,\
60
or use --unchanged to force an empty commit.
61
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
63
def test_commit_success(self):
64
"""Successful commit should not leave behind a bzr-commit-* file"""
65
self.make_branch_and_tree('.')
66
self.run_bzr('commit --unchanged -m message')
67
self.assertEqual('', self.run_bzr('unknowns')[0])
69
# same for unicode messages
70
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
71
self.assertEqual('', self.run_bzr('unknowns')[0])
73
def test_commit_lossy_native(self):
74
"""A --lossy option to commit is supported."""
75
self.make_branch_and_tree('.')
76
self.run_bzr('commit --lossy --unchanged -m message')
77
self.assertEqual('', self.run_bzr('unknowns')[0])
79
def test_commit_lossy_foreign(self):
80
test_foreign.register_dummy_foreign_for_test(self)
81
self.make_branch_and_tree('.',
82
format=test_foreign.DummyForeignVcsDirFormat())
83
self.run_bzr('commit --lossy --unchanged -m message')
84
output = self.run_bzr('revision-info')[0]
85
self.assertTrue(output.startswith('1 dummy-'))
40
87
def test_commit_with_path(self):
41
88
"""Commit tree with path of root specified"""
42
self.run_bzr('init', 'a')
89
a_tree = self.make_branch_and_tree('a')
43
90
self.build_tree(['a/a_file'])
44
self.run_bzr('add', 'a/a_file')
45
self.run_bzr('commit', '-m', 'first commit', 'a')
92
self.run_bzr(['commit', '-m', 'first commit', 'a'])
47
self.run_bzr('branch', 'a', 'b')
94
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
48
95
self.build_tree_contents([('b/a_file', 'changes in b')])
49
self.run_bzr('commit', '-m', 'first commit in b', 'b')
96
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
51
98
self.build_tree_contents([('a/a_file', 'new contents')])
52
self.run_bzr('commit', '-m', 'change in a', 'a')
55
self.run_bzr('merge', '../a', retcode=1) # will conflict
57
self.run_bzr('resolved', 'b/a_file')
58
self.run_bzr('commit', '-m', 'merge into b', 'b')
99
self.run_bzr(['commit', '-m', 'change in a', 'a'])
101
b_tree.merge_from_branch(a_tree.branch)
102
self.assertEqual(len(b_tree.conflicts()), 1)
103
self.run_bzr('resolved b/a_file')
104
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
61
106
def test_10_verbose_commit(self):
62
107
"""Add one file and examine verbose commit output"""
108
tree = self.make_branch_and_tree('.')
64
109
self.build_tree(['hello.txt'])
65
self.runbzr("add hello.txt")
66
out,err = self.run_bzr("commit", "-m", "added")
110
tree.add("hello.txt")
111
out,err = self.run_bzr('commit -m added')
67
112
self.assertEqual('', out)
68
self.assertEqual('added hello.txt\n'
69
'Committed revision 1.\n',
113
self.assertContainsRe(err, '^Committing to: .*\n'
115
'Committed revision 1.\n$',)
72
117
def prepare_simple_history(self):
73
118
"""Prepare and return a working tree with one commit of one file"""
74
119
# Commit with modified file should say so
75
wt = BzrDir.create_standalone_workingtree('.')
120
wt = ControlDir.create_standalone_workingtree('.')
76
121
self.build_tree(['hello.txt', 'extra.txt'])
77
122
wt.add(['hello.txt'])
78
123
wt.commit(message='added')
82
127
# Verbose commit of modified file should say so
83
128
wt = self.prepare_simple_history()
84
129
self.build_tree_contents([('hello.txt', 'new contents')])
85
out, err = self.run_bzr("commit", "-m", "modified")
130
out, err = self.run_bzr('commit -m modified')
86
131
self.assertEqual('', out)
87
self.assertEqual('modified hello.txt\n'
88
'Committed revision 2.\n',
132
self.assertContainsRe(err, '^Committing to: .*\n'
133
'modified hello\.txt\n'
134
'Committed revision 2\.\n$')
136
def test_unicode_commit_message_is_filename(self):
137
"""Unicode commit message same as a filename (Bug #563646).
139
self.requireFeature(features.UnicodeFilenameFeature)
140
file_name = u'\N{euro sign}'
141
self.run_bzr(['init'])
142
with open(file_name, 'w') as f: f.write('hello world')
143
self.run_bzr(['add'])
144
out, err = self.run_bzr(['commit', '-m', file_name])
145
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
146
te = osutils.get_terminal_encoding()
147
self.assertContainsRe(err.decode(te),
148
u'The commit message is a file name:',
151
# Run same test with a filename that causes encode
152
# error for the terminal encoding. We do this
153
# by forcing terminal encoding of ascii for
154
# osutils.get_terminal_encoding which is used
155
# by ui.text.show_warning
156
default_get_terminal_enc = osutils.get_terminal_encoding
158
osutils.get_terminal_encoding = lambda trace=None: 'ascii'
159
file_name = u'foo\u1234'
160
with open(file_name, 'w') as f: f.write('hello world')
161
self.run_bzr(['add'])
162
out, err = self.run_bzr(['commit', '-m', file_name])
163
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
164
te = osutils.get_terminal_encoding()
165
self.assertContainsRe(err.decode(te, 'replace'),
166
u'The commit message is a file name:',
169
osutils.get_terminal_encoding = default_get_terminal_enc
171
def test_non_ascii_file_unversioned_utf8(self):
172
self.requireFeature(features.UnicodeFilenameFeature)
173
tree = self.make_branch_and_tree(".")
174
self.build_tree(["f"])
176
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
177
encoding="utf-8", retcode=3)
178
self.assertContainsRe(err, "(?m)not versioned: \"\xc2\xa7\"$")
180
def test_non_ascii_file_unversioned_iso_8859_5(self):
181
self.requireFeature(features.UnicodeFilenameFeature)
182
tree = self.make_branch_and_tree(".")
183
self.build_tree(["f"])
185
out, err = self.run_bzr(["commit", "-m", "Wrong filename", u"\xa7"],
186
encoding="iso-8859-5", retcode=3)
187
self.expectFailure("Error messages are always written as UTF-8",
188
self.assertNotContainsString, err, "\xc2\xa7")
189
self.assertContainsRe(err, "(?m)not versioned: \"\xfd\"$")
191
def test_warn_about_forgotten_commit_message(self):
192
"""Test that the lack of -m parameter is caught"""
193
wt = self.make_branch_and_tree('.')
194
self.build_tree(['one', 'two'])
196
out, err = self.run_bzr('commit -m one two')
197
self.assertContainsRe(err, "The commit message is a file name")
91
199
def test_verbose_commit_renamed(self):
92
200
# Verbose commit of renamed file should say so
93
201
wt = self.prepare_simple_history()
94
202
wt.rename_one('hello.txt', 'gutentag.txt')
95
out, err = self.run_bzr("commit", "-m", "renamed")
203
out, err = self.run_bzr('commit -m renamed')
96
204
self.assertEqual('', out)
97
self.assertEqual('renamed hello.txt => gutentag.txt\n'
98
'Committed revision 2.\n',
205
self.assertContainsRe(err, '^Committing to: .*\n'
206
'renamed hello\.txt => gutentag\.txt\n'
207
'Committed revision 2\.$\n')
101
209
def test_verbose_commit_moved(self):
102
210
# Verbose commit of file moved to new directory should say so
184
327
other_tree.commit('modify all sample files and dirs.')
186
329
other_tree.unlock()
187
self.merge(other_tree.branch, this_tree)
189
out,err = self.run_bzr("commit", "-m", "added")
330
this_tree.merge_from_branch(other_tree.branch)
331
out, err = self.run_bzr('commit -m added', working_dir='this')
191
332
self.assertEqual('', out)
192
self.assertEqualDiff(
193
'modified filetomodify\n'
196
'renamed dirtorename => renameddir\n'
197
'renamed dirtoreparent => renameddir/reparenteddir\n'
198
'renamed filetoreparent => renameddir/reparentedfile\n'
199
'renamed filetorename => renamedfile\n'
200
'deleted dirtoremove\n'
201
'deleted filetoremove\n'
202
'Committed revision 2.\n',
333
self.assertEqual(set([
334
'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
335
'modified filetomodify',
338
'renamed dirtorename => renameddir',
339
'renamed filetorename => renamedfile',
340
'renamed dirtoreparent => renameddir/reparenteddir',
341
'renamed filetoreparent => renameddir/reparentedfile',
342
'deleted dirtoremove',
343
'deleted filetoremove',
344
'Committed revision 2.',
346
]), set(err.split('\n')))
205
348
def test_empty_commit_message(self):
207
file('foo.c', 'wt').write('int main() {}')
208
self.runbzr(['add', 'foo.c'])
209
self.runbzr(["commit", "-m", ""] , retcode=3)
349
tree = self.make_branch_and_tree('.')
350
self.build_tree_contents([('foo.c', 'int main() {}')])
352
self.run_bzr('commit -m ""')
211
354
def test_other_branch_commit(self):
212
355
# this branch is to ensure consistent behaviour, whether we're run
213
356
# inside a branch, or not.
214
os.mkdir('empty_branch')
215
os.chdir('empty_branch')
220
file('foo.c', 'wt').write('int main() {}')
221
file('bar.c', 'wt').write('int main() {}')
223
self.runbzr(['add', 'branch/foo.c'])
224
self.runbzr(['add', 'branch'])
357
outer_tree = self.make_branch_and_tree('.')
358
inner_tree = self.make_branch_and_tree('branch')
359
self.build_tree_contents([
360
('branch/foo.c', 'int main() {}'),
361
('branch/bar.c', 'int main() {}')])
362
inner_tree.add(['foo.c', 'bar.c'])
225
363
# can't commit files in different trees; sane error
226
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
227
self.runbzr('commit -m newstuff branch/foo.c')
228
self.runbzr('commit -m newstuff branch')
229
self.runbzr('commit -m newstuff branch', retcode=3)
364
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
365
# can commit to branch - records foo.c only
366
self.run_bzr('commit -m newstuff branch/foo.c')
367
# can commit to branch - records bar.c
368
self.run_bzr('commit -m newstuff branch')
370
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
231
372
def test_out_of_date_tree_commit(self):
232
373
# check we get an error code and a clear message committing with an out
233
374
# of date checkout
234
self.make_branch_and_tree('branch')
375
tree = self.make_branch_and_tree('branch')
235
376
# make a checkout
236
self.runbzr('checkout --lightweight branch checkout')
377
checkout = tree.branch.create_checkout('checkout', lightweight=True)
237
378
# commit to the original branch to make the checkout out of date
238
self.runbzr('commit --unchanged -m message branch')
379
tree.commit('message branch', allow_pointless=True)
239
380
# now commit to the checkout should emit
240
381
# ERROR: Out of date with the branch, 'bzr update' is suggested
241
output = self.runbzr('commit --unchanged -m checkout_message '
382
output = self.run_bzr('commit --unchanged -m checkout_message '
242
383
'checkout', retcode=3)
243
384
self.assertEqual(output,
245
"bzr: ERROR: Working tree is out of date, please run "
386
"bzr: ERROR: Working tree is out of date, please "
387
"run 'bzr update'.\n"))
248
389
def test_local_commit_unbound(self):
249
390
# a --local commit on an unbound branch is an error
250
391
self.make_branch_and_tree('.')
251
out, err = self.run_bzr('commit', '--local', retcode=3)
392
out, err = self.run_bzr('commit --local', retcode=3)
252
393
self.assertEqualDiff('', out)
253
394
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
254
395
'on unbound branches.\n', err)
256
397
def test_commit_a_text_merge_in_a_checkout(self):
257
398
# checkouts perform multiple actions in a transaction across bond
258
399
# branches and their master, and have been observed to fail in the
259
# past. This is a user story reported to fail in bug #43959 where
400
# past. This is a user story reported to fail in bug #43959 where
260
401
# a merge done in a checkout (using the update command) failed to
261
402
# commit correctly.
262
self.run_bzr('init', 'trunk')
264
self.run_bzr('checkout', 'trunk', 'u1')
265
self.build_tree_contents([('u1/hosts', 'initial contents')])
266
self.run_bzr('add', 'u1/hosts')
267
self.run_bzr('commit', '-m', 'add hosts', 'u1')
269
self.run_bzr('checkout', 'trunk', 'u2')
270
self.build_tree_contents([('u2/hosts', 'altered in u2')])
271
self.run_bzr('commit', '-m', 'checkin from u2', 'u2')
403
trunk = self.make_branch_and_tree('trunk')
405
u1 = trunk.branch.create_checkout('u1')
406
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
408
self.run_bzr('commit -m add-hosts u1')
410
u2 = trunk.branch.create_checkout('u2')
411
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
412
self.run_bzr('commit -m checkin-from-u2 u2')
273
414
# make an offline commits
274
self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
275
self.run_bzr('commit', '-m', 'checkin offline', '--local', 'u1')
415
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
416
self.run_bzr('commit -m checkin-offline --local u1')
277
418
# now try to pull in online work from u2, and then commit our offline
278
419
# work as a merge
279
420
# retcode 1 as we expect a text conflict
280
self.run_bzr('update', 'u1', retcode=1)
281
self.run_bzr('resolved', 'u1/hosts')
421
self.run_bzr('update u1', retcode=1)
422
self.assertFileEqual('''\
424
first offline change in u1
431
self.run_bzr('resolved u1/hosts')
282
432
# add a text change here to represent resolving the merge conflicts in
283
433
# favour of a new version of the file not identical to either the u1
284
434
# version or the u2 version.
285
435
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
286
self.run_bzr('commit', '-m', 'checkin merge of the offline work from u1', 'u1')
436
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
438
def test_commit_exclude_excludes_modified_files(self):
439
"""Commit -x foo should ignore changes to foo."""
440
tree = self.make_branch_and_tree('.')
441
self.build_tree(['a', 'b', 'c'])
442
tree.smart_add(['.'])
443
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
444
self.assertFalse('added b' in out)
445
self.assertFalse('added b' in err)
446
# If b was excluded it will still be 'added' in status.
447
out, err = self.run_bzr(['added'])
448
self.assertEqual('b\n', out)
449
self.assertEqual('', err)
451
def test_commit_exclude_twice_uses_both_rules(self):
452
"""Commit -x foo -x bar should ignore changes to foo and bar."""
453
tree = self.make_branch_and_tree('.')
454
self.build_tree(['a', 'b', 'c'])
455
tree.smart_add(['.'])
456
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
457
self.assertFalse('added b' in out)
458
self.assertFalse('added c' in out)
459
self.assertFalse('added b' in err)
460
self.assertFalse('added c' in err)
461
# If b was excluded it will still be 'added' in status.
462
out, err = self.run_bzr(['added'])
463
self.assertTrue('b\n' in out)
464
self.assertTrue('c\n' in out)
465
self.assertEqual('', err)
467
def test_commit_respects_spec_for_removals(self):
468
"""Commit with a file spec should only commit removals that match"""
469
t = self.make_branch_and_tree('.')
470
self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
471
t.add(['file-a', 'dir-a', 'dir-a/file-b'])
473
t.remove(['file-a', 'dir-a/file-b'])
474
result = self.run_bzr('commit . -m removed-file-b',
475
working_dir='dir-a')[1]
476
self.assertNotContainsRe(result, 'file-a')
477
result = self.run_bzr('status', working_dir='dir-a')[0]
478
self.assertContainsRe(result, 'removed:\n file-a')
480
def test_strict_commit(self):
481
"""Commit with --strict works if everything is known"""
482
ignores._set_user_ignores([])
483
tree = self.make_branch_and_tree('tree')
484
self.build_tree(['tree/a'])
486
# A simple change should just work
487
self.run_bzr('commit --strict -m adding-a', working_dir='tree')
489
def test_strict_commit_no_changes(self):
490
"""commit --strict gives "no changes" if there is nothing to commit"""
491
tree = self.make_branch_and_tree('tree')
492
self.build_tree(['tree/a'])
494
tree.commit('adding a')
496
# With no changes, it should just be 'no changes'
497
# Make sure that commit is failing because there is nothing to do
498
self.run_bzr_error(['No changes to commit'],
499
'commit --strict -m no-changes',
502
# But --strict doesn't care if you supply --unchanged
503
self.run_bzr('commit --strict --unchanged -m no-changes',
506
def test_strict_commit_unknown(self):
507
"""commit --strict fails if a file is unknown"""
508
tree = self.make_branch_and_tree('tree')
509
self.build_tree(['tree/a'])
511
tree.commit('adding a')
513
# Add one file so there is a change, but forget the other
514
self.build_tree(['tree/b', 'tree/c'])
516
self.run_bzr_error(['Commit refused because there are unknown files'],
517
'commit --strict -m add-b',
520
# --no-strict overrides --strict
521
self.run_bzr('commit --strict -m add-b --no-strict',
524
def test_fixes_bug_output(self):
525
"""commit --fixes=lp:23452 succeeds without output."""
526
tree = self.make_branch_and_tree('tree')
527
self.build_tree(['tree/hello.txt'])
528
tree.add('hello.txt')
529
output, err = self.run_bzr(
530
'commit -m hello --fixes=lp:23452 tree/hello.txt')
531
self.assertEqual('', output)
532
self.assertContainsRe(err, 'Committing to: .*\n'
534
'Committed revision 1\.\n')
536
def test_no_bugs_no_properties(self):
537
"""If no bugs are fixed, the bugs property is not set.
539
see https://beta.launchpad.net/bzr/+bug/109613
541
tree = self.make_branch_and_tree('tree')
542
self.build_tree(['tree/hello.txt'])
543
tree.add('hello.txt')
544
self.run_bzr( 'commit -m hello tree/hello.txt')
545
# Get the revision properties, ignoring the branch-nick property, which
546
# we don't care about for this test.
547
last_rev = tree.branch.repository.get_revision(tree.last_revision())
548
properties = dict(last_rev.properties)
549
del properties['branch-nick']
550
self.assertFalse('bugs' in properties)
552
def test_fixes_bug_sets_property(self):
553
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
554
tree = self.make_branch_and_tree('tree')
555
self.build_tree(['tree/hello.txt'])
556
tree.add('hello.txt')
557
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
559
# Get the revision properties, ignoring the branch-nick property, which
560
# we don't care about for this test.
561
last_rev = tree.branch.repository.get_revision(tree.last_revision())
562
properties = dict(last_rev.properties)
563
del properties['branch-nick']
565
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
568
def test_fixes_multiple_bugs_sets_properties(self):
569
"""--fixes can be used more than once to show that bugs are fixed."""
570
tree = self.make_branch_and_tree('tree')
571
self.build_tree(['tree/hello.txt'])
572
tree.add('hello.txt')
573
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
576
# Get the revision properties, ignoring the branch-nick property, which
577
# we don't care about for this test.
578
last_rev = tree.branch.repository.get_revision(tree.last_revision())
579
properties = dict(last_rev.properties)
580
del properties['branch-nick']
583
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
584
'https://launchpad.net/bugs/235 fixed'},
587
def test_fixes_bug_with_alternate_trackers(self):
588
"""--fixes can be used on a properly configured branch to mark bug
589
fixes on multiple trackers.
591
tree = self.make_branch_and_tree('tree')
592
tree.branch.get_config().set_user_option(
593
'trac_twisted_url', 'http://twistedmatrix.com/trac')
594
self.build_tree(['tree/hello.txt'])
595
tree.add('hello.txt')
596
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
598
# Get the revision properties, ignoring the branch-nick property, which
599
# we don't care about for this test.
600
last_rev = tree.branch.repository.get_revision(tree.last_revision())
601
properties = dict(last_rev.properties)
602
del properties['branch-nick']
605
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
606
'http://twistedmatrix.com/trac/ticket/235 fixed'},
609
def test_fixes_unknown_bug_prefix(self):
610
tree = self.make_branch_and_tree('tree')
611
self.build_tree(['tree/hello.txt'])
612
tree.add('hello.txt')
614
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
615
'commit -m add-b --fixes=xxx:123',
618
def test_fixes_bug_with_default_tracker(self):
619
"""commit --fixes=234 uses the default bug tracker."""
620
tree = self.make_branch_and_tree('tree')
621
self.build_tree(['tree/hello.txt'])
622
tree.add('hello.txt')
624
["bzr: ERROR: No tracker specified for bug 123. Use the form "
625
"'tracker:id' or specify a default bug tracker using the "
626
"`bugtracker` option.\n"
627
"See \"bzr help bugs\" for more information on this feature. "
629
'commit -m add-b --fixes=123',
631
tree.branch.get_config_stack().set("bugtracker", "lp")
632
self.run_bzr('commit -m hello --fixes=234 tree/hello.txt')
633
last_rev = tree.branch.repository.get_revision(tree.last_revision())
634
self.assertEqual('https://launchpad.net/bugs/234 fixed',
635
last_rev.properties['bugs'])
637
def test_fixes_invalid_bug_number(self):
638
tree = self.make_branch_and_tree('tree')
639
self.build_tree(['tree/hello.txt'])
640
tree.add('hello.txt')
642
["Did not understand bug identifier orange: Must be an integer. "
643
"See \"bzr help bugs\" for more information on this feature.\n"
645
'commit -m add-b --fixes=lp:orange',
648
def test_fixes_invalid_argument(self):
649
"""Raise an appropriate error when the fixes argument isn't tag:id."""
650
tree = self.make_branch_and_tree('tree')
651
self.build_tree(['tree/hello.txt'])
652
tree.add('hello.txt')
654
[r"Invalid bug orange:apples:bananas. Must be in the form of "
655
r"'tracker:id'\. See \"bzr help bugs\" for more information on "
656
r"this feature.\nCommit refused\."],
657
'commit -m add-b --fixes=orange:apples:bananas',
660
def test_no_author(self):
661
"""If the author is not specified, the author property is not set."""
662
tree = self.make_branch_and_tree('tree')
663
self.build_tree(['tree/hello.txt'])
664
tree.add('hello.txt')
665
self.run_bzr( 'commit -m hello tree/hello.txt')
666
last_rev = tree.branch.repository.get_revision(tree.last_revision())
667
properties = last_rev.properties
668
self.assertFalse('author' in properties)
670
def test_author_sets_property(self):
671
"""commit --author='John Doe <jdoe@example.com>' sets the author
674
tree = self.make_branch_and_tree('tree')
675
self.build_tree(['tree/hello.txt'])
676
tree.add('hello.txt')
677
self.run_bzr(["commit", '-m', 'hello',
678
'--author', u'John D\xf6 <jdoe@example.com>',
680
last_rev = tree.branch.repository.get_revision(tree.last_revision())
681
properties = last_rev.properties
682
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
684
def test_author_no_email(self):
685
"""Author's name without an email address is allowed, too."""
686
tree = self.make_branch_and_tree('tree')
687
self.build_tree(['tree/hello.txt'])
688
tree.add('hello.txt')
689
out, err = self.run_bzr("commit -m hello --author='John Doe' "
691
last_rev = tree.branch.repository.get_revision(tree.last_revision())
692
properties = last_rev.properties
693
self.assertEqual('John Doe', properties['authors'])
695
def test_multiple_authors(self):
696
"""Multiple authors can be specyfied, and all are stored."""
697
tree = self.make_branch_and_tree('tree')
698
self.build_tree(['tree/hello.txt'])
699
tree.add('hello.txt')
700
out, err = self.run_bzr("commit -m hello --author='John Doe' "
701
"--author='Jane Rey' tree/hello.txt")
702
last_rev = tree.branch.repository.get_revision(tree.last_revision())
703
properties = last_rev.properties
704
self.assertEqual('John Doe\nJane Rey', properties['authors'])
706
def test_commit_time(self):
707
tree = self.make_branch_and_tree('tree')
708
self.build_tree(['tree/hello.txt'])
709
tree.add('hello.txt')
710
out, err = self.run_bzr("commit -m hello "
711
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
712
last_rev = tree.branch.repository.get_revision(tree.last_revision())
714
'Sat 2009-10-10 08:00:00 +0100',
715
osutils.format_date(last_rev.timestamp, last_rev.timezone))
717
def test_commit_time_bad_time(self):
718
tree = self.make_branch_and_tree('tree')
719
self.build_tree(['tree/hello.txt'])
720
tree.add('hello.txt')
721
out, err = self.run_bzr("commit -m hello "
722
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
723
self.assertStartsWith(
724
err, "bzr: ERROR: Could not parse --commit-time:")
726
def test_commit_time_missing_tz(self):
727
tree = self.make_branch_and_tree('tree')
728
self.build_tree(['tree/hello.txt'])
729
tree.add('hello.txt')
730
out, err = self.run_bzr("commit -m hello "
731
"--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
732
self.assertStartsWith(
733
err, "bzr: ERROR: Could not parse --commit-time:")
734
# Test that it is actually checking and does not simply crash with
735
# some other exception
736
self.assertContainsString(err, "missing a timezone offset")
738
def test_partial_commit_with_renames_in_tree(self):
739
# this test illustrates bug #140419
740
t = self.make_branch_and_tree('.')
741
self.build_tree(['dir/', 'dir/a', 'test'])
742
t.add(['dir/', 'dir/a', 'test'])
743
t.commit('initial commit')
744
# important part: file dir/a should change parent
745
# and should appear before old parent
746
# then during partial commit we have error
747
# parent_id {dir-XXX} not in inventory
748
t.rename_one('dir/a', 'a')
749
self.build_tree_contents([('test', 'changes in test')])
751
out, err = self.run_bzr('commit test -m "partial commit"')
752
self.assertEquals('', out)
753
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
755
def test_commit_readonly_checkout(self):
756
# https://bugs.launchpad.net/bzr/+bug/129701
757
# "UnlockableTransport error trying to commit in checkout of readonly
759
self.make_branch('master')
760
master = ControlDir.open_from_transport(
761
self.get_readonly_transport('master')).open_branch()
762
master.create_checkout('checkout')
763
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
765
self.assertContainsRe(err,
766
r'^bzr: ERROR: Cannot lock.*readonly transport')
768
def setup_editor(self):
769
# Test that commit template hooks work
770
if sys.platform == "win32":
771
f = file('fed.bat', 'w')
772
f.write('@rem dummy fed')
774
self.overrideEnv('BZR_EDITOR', "fed.bat")
776
f = file('fed.sh', 'wb')
777
f.write('#!/bin/sh\n')
779
os.chmod('fed.sh', 0755)
780
self.overrideEnv('BZR_EDITOR', "./fed.sh")
782
def setup_commit_with_template(self):
784
msgeditor.hooks.install_named_hook("commit_message_template",
785
lambda commit_obj, msg: "save me some typing\n", None)
786
tree = self.make_branch_and_tree('tree')
787
self.build_tree(['tree/hello.txt'])
788
tree.add('hello.txt')
791
def test_edit_empty_message(self):
792
tree = self.make_branch_and_tree('tree')
794
self.build_tree(['tree/hello.txt'])
795
tree.add('hello.txt')
796
out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
798
self.assertContainsRe(err,
799
"bzr: ERROR: Empty commit message specified")
801
def test_commit_hook_template_accepted(self):
802
tree = self.setup_commit_with_template()
803
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
804
last_rev = tree.branch.repository.get_revision(tree.last_revision())
805
self.assertEqual('save me some typing\n', last_rev.message)
807
def test_commit_hook_template_rejected(self):
808
tree = self.setup_commit_with_template()
809
expected = tree.last_revision()
810
out, err = self.run_bzr_error(["Empty commit message specified."
811
" Please specify a commit message with either"
812
" --message or --file or leave a blank message"
813
" with --message \"\"."],
814
"commit tree/hello.txt", stdin="n\n")
815
self.assertEqual(expected, tree.last_revision())
817
def test_set_commit_message(self):
818
msgeditor.hooks.install_named_hook("set_commit_message",
819
lambda commit_obj, msg: "save me some typing\n", None)
820
tree = self.make_branch_and_tree('tree')
821
self.build_tree(['tree/hello.txt'])
822
tree.add('hello.txt')
823
out, err = self.run_bzr("commit tree/hello.txt")
824
last_rev = tree.branch.repository.get_revision(tree.last_revision())
825
self.assertEqual('save me some typing\n', last_rev.message)
827
def test_commit_without_username(self):
828
"""Ensure commit error if username is not set.
830
self.run_bzr(['init', 'foo'])
831
with open('foo/foo.txt', 'w') as f:
833
self.run_bzr(['add'], working_dir='foo')
834
self.overrideEnv('EMAIL', None)
835
self.overrideEnv('BZR_EMAIL', None)
836
# Also, make sure that it's not inferred from mailname.
837
self.overrideAttr(config, '_auto_user_id',
838
lambda: (None, None))
840
['Unable to determine your name'],
841
['commit', '-m', 'initial'], working_dir='foo')
843
def test_commit_recursive_checkout(self):
844
"""Ensure that a commit to a recursive checkout fails cleanly.
846
self.run_bzr(['init', 'test_branch'])
847
self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
848
self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
849
with open('test_checkout/foo.txt', 'w') as f:
851
self.run_bzr(['add'], working_dir='test_checkout')
852
out, err = self.run_bzr_error(
853
['Branch.*test_checkout.*appears to be bound to itself'],
854
['commit', '-m', 'addedfoo'], working_dir='test_checkout')
856
def test_mv_dirs_non_ascii(self):
857
"""Move directory with non-ascii name and containing files.
859
Regression test for bug 185211.
861
tree = self.make_branch_and_tree('.')
862
self.build_tree([u'abc\xa7/', u'abc\xa7/foo'])
864
tree.add([u'abc\xa7/', u'abc\xa7/foo'])
865
tree.commit('checkin')
867
tree.rename_one(u'abc\xa7','abc')
869
self.run_bzr('ci -m "non-ascii mv"')
872
class TestSmartServerCommit(TestCaseWithTransport):
874
def test_commit_to_lightweight(self):
875
self.setup_smart_server_with_call_log()
876
t = self.make_branch_and_tree('from')
877
for count in range(9):
878
t.commit(message='commit %d' % count)
879
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
881
self.reset_smart_call_log()
882
self.build_tree(['target/afile'])
883
self.run_bzr(['add', 'target/afile'])
884
out, err = self.run_bzr(['commit', '-m', 'do something', 'target'])
885
# This figure represent the amount of work to perform this use case. It
886
# is entirely ok to reduce this number if a test fails due to rpc_count
887
# being too low. If rpc_count increases, more network roundtrips have
888
# become necessary for this use case. Please do not adjust this number
889
# upwards without agreement from bzr's network support maintainers.
890
self.assertLength(211, self.hpss_calls)
891
self.assertLength(2, self.hpss_connections)
892
self.expectFailure("commit still uses VFS calls",
893
self.assertThat, self.hpss_calls, ContainsNoVfsCalls)