35
41
def test_05_empty_commit(self):
36
42
"""Commit of tree with no versioned files should fail"""
37
43
# If forced, it should succeed, but this is not tested here.
44
self.make_branch_and_tree('.')
39
45
self.build_tree(['hello.txt'])
40
self.runbzr("commit -m empty", retcode=3)
46
out,err = self.run_bzr('commit -m empty', retcode=3)
47
self.assertEqual('', out)
48
self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
49
' Use --unchanged to commit anyhow.\n')
51
def test_commit_success(self):
52
"""Successful commit should not leave behind a bzr-commit-* file"""
53
self.make_branch_and_tree('.')
54
self.run_bzr('commit --unchanged -m message')
55
self.assertEqual('', self.run_bzr('unknowns')[0])
57
# same for unicode messages
58
self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
59
self.assertEqual('', self.run_bzr('unknowns')[0])
61
def test_commit_with_path(self):
62
"""Commit tree with path of root specified"""
63
a_tree = self.make_branch_and_tree('a')
64
self.build_tree(['a/a_file'])
66
self.run_bzr(['commit', '-m', 'first commit', 'a'])
68
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
69
self.build_tree_contents([('b/a_file', 'changes in b')])
70
self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
72
self.build_tree_contents([('a/a_file', 'new contents')])
73
self.run_bzr(['commit', '-m', 'change in a', 'a'])
75
b_tree.merge_from_branch(a_tree.branch)
76
self.assertEqual(len(b_tree.conflicts()), 1)
77
self.run_bzr('resolved b/a_file')
78
self.run_bzr(['commit', '-m', 'merge into b', 'b'])
42
81
def test_10_verbose_commit(self):
43
82
"""Add one file and examine verbose commit output"""
83
tree = self.make_branch_and_tree('.')
45
84
self.build_tree(['hello.txt'])
46
self.runbzr("add hello.txt")
47
out,err = self.run_bzr("commit", "-m", "added")
48
self.assertEqual('', out)
49
self.assertEqual('added hello.txt\n'
50
'Committed revision 1.\n',
53
def test_15_verbose_commit_with_unknown(self):
86
out,err = self.run_bzr('commit -m added')
87
self.assertEqual('', out)
88
self.assertContainsRe(err, '^Committing to: .*\n'
90
'Committed revision 1.\n$',)
92
def prepare_simple_history(self):
93
"""Prepare and return a working tree with one commit of one file"""
94
# Commit with modified file should say so
95
wt = BzrDir.create_standalone_workingtree('.')
96
self.build_tree(['hello.txt', 'extra.txt'])
98
wt.commit(message='added')
101
def test_verbose_commit_modified(self):
102
# Verbose commit of modified file should say so
103
wt = self.prepare_simple_history()
104
self.build_tree_contents([('hello.txt', 'new contents')])
105
out, err = self.run_bzr('commit -m modified')
106
self.assertEqual('', out)
107
self.assertContainsRe(err, '^Committing to: .*\n'
108
'modified hello\.txt\n'
109
'Committed revision 2\.\n$')
111
def test_unicode_commit_message(self):
112
"""Unicode commit message same as a filename (Bug #563646).
114
file_name = u'\N{euro sign}'
115
self.run_bzr(['init'])
116
open(file_name, 'w').write('hello world')
117
self.run_bzr(['add'])
118
out, err = self.run_bzr(['commit', '-m', file_name])
120
reflags = re.MULTILINE|re.DOTALL|re.UNICODE
121
ue = osutils.get_user_encoding()
122
self.assertContainsRe(err.decode(ue),
123
u'The commit message is a file name: "\N{euro sign}"',
126
def test_warn_about_forgotten_commit_message(self):
127
"""Test that the lack of -m parameter is caught"""
128
wt = self.make_branch_and_tree('.')
129
self.build_tree(['one', 'two'])
131
out, err = self.run_bzr('commit -m one two')
132
self.assertContainsRe(err, "The commit message is a file name")
134
def test_verbose_commit_renamed(self):
135
# Verbose commit of renamed file should say so
136
wt = self.prepare_simple_history()
137
wt.rename_one('hello.txt', 'gutentag.txt')
138
out, err = self.run_bzr('commit -m renamed')
139
self.assertEqual('', out)
140
self.assertContainsRe(err, '^Committing to: .*\n'
141
'renamed hello\.txt => gutentag\.txt\n'
142
'Committed revision 2\.$\n')
144
def test_verbose_commit_moved(self):
145
# Verbose commit of file moved to new directory should say so
146
wt = self.prepare_simple_history()
149
wt.rename_one('hello.txt', 'subdir/hello.txt')
150
out, err = self.run_bzr('commit -m renamed')
151
self.assertEqual('', out)
152
self.assertEqual(set([
153
'Committing to: %s/' % osutils.getcwd(),
155
'renamed hello.txt => subdir/hello.txt',
156
'Committed revision 2.',
158
]), set(err.split('\n')))
160
def test_verbose_commit_with_unknown(self):
54
161
"""Unknown files should not be listed by default in verbose output"""
55
162
# Is that really the best policy?
163
wt = BzrDir.create_standalone_workingtree('.')
57
164
self.build_tree(['hello.txt', 'extra.txt'])
58
self.runbzr("add hello.txt")
59
out,err = self.run_bzr("commit", "-m", "added")
165
wt.add(['hello.txt'])
166
out,err = self.run_bzr('commit -m added')
60
167
self.assertEqual('', out)
61
self.assertEqual('added hello.txt\n'
62
'Committed revision 1.\n',
168
self.assertContainsRe(err, '^Committing to: .*\n'
170
'Committed revision 1\.\n$')
65
def test_16_verbose_commit_with_unchanged(self):
172
def test_verbose_commit_with_unchanged(self):
66
173
"""Unchanged files should not be listed by default in verbose output"""
174
tree = self.make_branch_and_tree('.')
68
175
self.build_tree(['hello.txt', 'unchanged.txt'])
69
self.runbzr('add unchanged.txt')
70
self.runbzr('commit -m unchanged unchanged.txt')
71
self.runbzr("add hello.txt")
72
out,err = self.run_bzr("commit", "-m", "added")
73
self.assertEqual('', out)
74
self.assertEqual('added hello.txt\n'
75
'Committed revision 2.\n',
176
tree.add('unchanged.txt')
177
self.run_bzr('commit -m unchanged unchanged.txt')
178
tree.add("hello.txt")
179
out,err = self.run_bzr('commit -m added')
180
self.assertEqual('', out)
181
self.assertContainsRe(err, '^Committing to: .*\n'
183
'Committed revision 2\.$\n')
185
def test_verbose_commit_includes_master_location(self):
186
"""Location of master is displayed when committing to bound branch"""
187
a_tree = self.make_branch_and_tree('a')
188
self.build_tree(['a/b'])
190
a_tree.commit(message='Initial message')
192
b_tree = a_tree.branch.create_checkout('b')
193
expected = "%s/" % (osutils.abspath('a'), )
194
out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
195
self.assertEqual(err, 'Committing to: %s\n'
196
'Committed revision 2.\n' % expected)
198
def test_commit_sanitizes_CR_in_message(self):
199
# See bug #433779, basically Emacs likes to pass '\r\n' style line
200
# endings to 'bzr commit -m ""' which breaks because we don't allow
201
# '\r' in commit messages. (Mostly because of issues where XML style
202
# formats arbitrarily strip it out of the data while parsing.)
203
# To make life easier for users, we just always translate '\r\n' =>
204
# '\n'. And '\r' => '\n'.
205
a_tree = self.make_branch_and_tree('a')
206
self.build_tree(['a/b'])
208
self.run_bzr(['commit',
209
'-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
211
rev_id = a_tree.branch.last_revision()
212
rev = a_tree.branch.repository.get_revision(rev_id)
213
self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
216
def test_commit_merge_reports_all_modified_files(self):
217
# the commit command should show all the files that are shown by
218
# bzr diff or bzr status when committing, even when they were not
219
# changed by the user but rather through doing a merge.
220
this_tree = self.make_branch_and_tree('this')
221
# we need a bunch of files and dirs, to perform one action on each.
224
'this/dirtoreparent/',
227
'this/filetoreparent',
244
this_tree.commit('create_files')
245
other_dir = this_tree.bzrdir.sprout('other')
246
other_tree = other_dir.open_workingtree()
247
other_tree.lock_write()
248
# perform the needed actions on the files and dirs.
250
other_tree.rename_one('dirtorename', 'renameddir')
251
other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
252
other_tree.rename_one('filetorename', 'renamedfile')
253
other_tree.rename_one('filetoreparent',
254
'renameddir/reparentedfile')
255
other_tree.remove(['dirtoremove', 'filetoremove'])
256
self.build_tree_contents([
258
('other/filetomodify', 'new content'),
259
('other/newfile', 'new file content')])
260
other_tree.add('newfile')
261
other_tree.add('newdir/')
262
other_tree.commit('modify all sample files and dirs.')
265
this_tree.merge_from_branch(other_tree.branch)
267
out,err = self.run_bzr('commit -m added')
268
self.assertEqual('', out)
269
self.assertEqual(set([
270
'Committing to: %s/' % osutils.getcwd(),
271
'modified filetomodify',
274
'renamed dirtorename => renameddir',
275
'renamed filetorename => renamedfile',
276
'renamed dirtoreparent => renameddir/reparenteddir',
277
'renamed filetoreparent => renameddir/reparentedfile',
278
'deleted dirtoremove',
279
'deleted filetoremove',
280
'Committed revision 2.',
282
]), set(err.split('\n')))
78
284
def test_empty_commit_message(self):
80
file('foo.c', 'wt').write('int main() {}')
81
self.runbzr(['add', 'foo.c'])
82
self.runbzr(["commit", "-m", ""] , retcode=3)
285
tree = self.make_branch_and_tree('.')
286
self.build_tree_contents([('foo.c', 'int main() {}')])
288
self.run_bzr('commit -m ""', retcode=3)
290
def test_unsupported_encoding_commit_message(self):
291
if sys.platform == 'win32':
292
raise tests.TestNotApplicable('Win32 parses arguments directly'
293
' as Unicode, so we can\'t pass invalid non-ascii')
294
tree = self.make_branch_and_tree('.')
295
self.build_tree_contents([('foo.c', 'int main() {}')])
297
# LANG env variable has no effect on Windows
298
# but some characters anyway cannot be represented
299
# in default user encoding
300
char = probe_bad_non_ascii(osutils.get_user_encoding())
302
raise TestSkipped('Cannot find suitable non-ascii character'
303
'for user_encoding (%s)' % osutils.get_user_encoding())
304
out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
306
env_changes={'LANG': 'C'})
307
self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
308
'unsupported by the current encoding.')
84
310
def test_other_branch_commit(self):
85
311
# this branch is to ensure consistent behaviour, whether we're run
86
312
# inside a branch, or not.
87
os.mkdir('empty_branch')
88
os.chdir('empty_branch')
93
file('foo.c', 'wt').write('int main() {}')
94
file('bar.c', 'wt').write('int main() {}')
96
self.runbzr(['add', 'branch/foo.c'])
97
self.runbzr(['add', 'branch'])
313
outer_tree = self.make_branch_and_tree('.')
314
inner_tree = self.make_branch_and_tree('branch')
315
self.build_tree_contents([
316
('branch/foo.c', 'int main() {}'),
317
('branch/bar.c', 'int main() {}')])
318
inner_tree.add(['foo.c', 'bar.c'])
98
319
# can't commit files in different trees; sane error
99
self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
100
self.runbzr('commit -m newstuff branch/foo.c')
101
self.runbzr('commit -m newstuff branch')
102
self.runbzr('commit -m newstuff branch', retcode=3)
320
self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
321
# can commit to branch - records foo.c only
322
self.run_bzr('commit -m newstuff branch/foo.c')
323
# can commit to branch - records bar.c
324
self.run_bzr('commit -m newstuff branch')
326
self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
104
328
def test_out_of_date_tree_commit(self):
105
329
# check we get an error code and a clear message committing with an out
106
330
# of date checkout
107
self.make_branch_and_tree('branch')
331
tree = self.make_branch_and_tree('branch')
108
332
# make a checkout
109
self.runbzr('checkout --lightweight branch checkout')
333
checkout = tree.branch.create_checkout('checkout', lightweight=True)
110
334
# commit to the original branch to make the checkout out of date
111
self.runbzr('commit --unchanged -m message branch')
335
tree.commit('message branch', allow_pointless=True)
112
336
# now commit to the checkout should emit
113
337
# ERROR: Out of date with the branch, 'bzr update' is suggested
114
output = self.runbzr('commit --unchanged -m checkout_message '
338
output = self.run_bzr('commit --unchanged -m checkout_message '
115
339
'checkout', retcode=3)
116
340
self.assertEqual(output,
118
"bzr: ERROR: Working tree is out of date, please run "
342
"bzr: ERROR: Working tree is out of date, please "
343
"run 'bzr update'.\n"))
121
345
def test_local_commit_unbound(self):
122
346
# a --local commit on an unbound branch is an error
123
347
self.make_branch_and_tree('.')
124
out, err = self.run_bzr('commit', '--local', retcode=3)
348
out, err = self.run_bzr('commit --local', retcode=3)
125
349
self.assertEqualDiff('', out)
126
350
self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
127
351
'on unbound branches.\n', err)
353
def test_commit_a_text_merge_in_a_checkout(self):
354
# checkouts perform multiple actions in a transaction across bond
355
# branches and their master, and have been observed to fail in the
356
# past. This is a user story reported to fail in bug #43959 where
357
# a merge done in a checkout (using the update command) failed to
359
trunk = self.make_branch_and_tree('trunk')
361
u1 = trunk.branch.create_checkout('u1')
362
self.build_tree_contents([('u1/hosts', 'initial contents\n')])
364
self.run_bzr('commit -m add-hosts u1')
366
u2 = trunk.branch.create_checkout('u2')
367
self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
368
self.run_bzr('commit -m checkin-from-u2 u2')
370
# make an offline commits
371
self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
372
self.run_bzr('commit -m checkin-offline --local u1')
374
# now try to pull in online work from u2, and then commit our offline
376
# retcode 1 as we expect a text conflict
377
self.run_bzr('update u1', retcode=1)
378
self.assertFileEqual('''\
380
first offline change in u1
387
self.run_bzr('resolved u1/hosts')
388
# add a text change here to represent resolving the merge conflicts in
389
# favour of a new version of the file not identical to either the u1
390
# version or the u2 version.
391
self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
392
self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
394
def test_commit_exclude_excludes_modified_files(self):
395
"""Commit -x foo should ignore changes to foo."""
396
tree = self.make_branch_and_tree('.')
397
self.build_tree(['a', 'b', 'c'])
398
tree.smart_add(['.'])
399
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b'])
400
self.assertFalse('added b' in out)
401
self.assertFalse('added b' in err)
402
# If b was excluded it will still be 'added' in status.
403
out, err = self.run_bzr(['added'])
404
self.assertEqual('b\n', out)
405
self.assertEqual('', err)
407
def test_commit_exclude_twice_uses_both_rules(self):
408
"""Commit -x foo -x bar should ignore changes to foo and bar."""
409
tree = self.make_branch_and_tree('.')
410
self.build_tree(['a', 'b', 'c'])
411
tree.smart_add(['.'])
412
out, err = self.run_bzr(['commit', '-m', 'test', '-x', 'b', '-x', 'c'])
413
self.assertFalse('added b' in out)
414
self.assertFalse('added c' in out)
415
self.assertFalse('added b' in err)
416
self.assertFalse('added c' in err)
417
# If b was excluded it will still be 'added' in status.
418
out, err = self.run_bzr(['added'])
419
self.assertTrue('b\n' in out)
420
self.assertTrue('c\n' in out)
421
self.assertEqual('', err)
423
def test_commit_respects_spec_for_removals(self):
424
"""Commit with a file spec should only commit removals that match"""
425
t = self.make_branch_and_tree('.')
426
self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
427
t.add(['file-a', 'dir-a', 'dir-a/file-b'])
429
t.remove(['file-a', 'dir-a/file-b'])
431
result = self.run_bzr('commit . -m removed-file-b')[1]
432
self.assertNotContainsRe(result, 'file-a')
433
result = self.run_bzr('status')[0]
434
self.assertContainsRe(result, 'removed:\n file-a')
436
def test_strict_commit(self):
437
"""Commit with --strict works if everything is known"""
438
ignores._set_user_ignores([])
439
tree = self.make_branch_and_tree('tree')
440
self.build_tree(['tree/a'])
442
# A simple change should just work
443
self.run_bzr('commit --strict -m adding-a',
446
def test_strict_commit_no_changes(self):
447
"""commit --strict gives "no changes" if there is nothing to commit"""
448
tree = self.make_branch_and_tree('tree')
449
self.build_tree(['tree/a'])
451
tree.commit('adding a')
453
# With no changes, it should just be 'no changes'
454
# Make sure that commit is failing because there is nothing to do
455
self.run_bzr_error(['No changes to commit'],
456
'commit --strict -m no-changes',
459
# But --strict doesn't care if you supply --unchanged
460
self.run_bzr('commit --strict --unchanged -m no-changes',
463
def test_strict_commit_unknown(self):
464
"""commit --strict fails if a file is unknown"""
465
tree = self.make_branch_and_tree('tree')
466
self.build_tree(['tree/a'])
468
tree.commit('adding a')
470
# Add one file so there is a change, but forget the other
471
self.build_tree(['tree/b', 'tree/c'])
473
self.run_bzr_error(['Commit refused because there are unknown files'],
474
'commit --strict -m add-b',
477
# --no-strict overrides --strict
478
self.run_bzr('commit --strict -m add-b --no-strict',
481
def test_fixes_bug_output(self):
482
"""commit --fixes=lp:23452 succeeds without output."""
483
tree = self.make_branch_and_tree('tree')
484
self.build_tree(['tree/hello.txt'])
485
tree.add('hello.txt')
486
output, err = self.run_bzr(
487
'commit -m hello --fixes=lp:23452 tree/hello.txt')
488
self.assertEqual('', output)
489
self.assertContainsRe(err, 'Committing to: .*\n'
491
'Committed revision 1\.\n')
493
def test_no_bugs_no_properties(self):
494
"""If no bugs are fixed, the bugs property is not set.
496
see https://beta.launchpad.net/bzr/+bug/109613
498
tree = self.make_branch_and_tree('tree')
499
self.build_tree(['tree/hello.txt'])
500
tree.add('hello.txt')
501
self.run_bzr( 'commit -m hello tree/hello.txt')
502
# Get the revision properties, ignoring the branch-nick property, which
503
# we don't care about for this test.
504
last_rev = tree.branch.repository.get_revision(tree.last_revision())
505
properties = dict(last_rev.properties)
506
del properties['branch-nick']
507
self.assertFalse('bugs' in properties)
509
def test_fixes_bug_sets_property(self):
510
"""commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
511
tree = self.make_branch_and_tree('tree')
512
self.build_tree(['tree/hello.txt'])
513
tree.add('hello.txt')
514
self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
516
# Get the revision properties, ignoring the branch-nick property, which
517
# we don't care about for this test.
518
last_rev = tree.branch.repository.get_revision(tree.last_revision())
519
properties = dict(last_rev.properties)
520
del properties['branch-nick']
522
self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
525
def test_fixes_multiple_bugs_sets_properties(self):
526
"""--fixes can be used more than once to show that bugs are fixed."""
527
tree = self.make_branch_and_tree('tree')
528
self.build_tree(['tree/hello.txt'])
529
tree.add('hello.txt')
530
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
533
# Get the revision properties, ignoring the branch-nick property, which
534
# we don't care about for this test.
535
last_rev = tree.branch.repository.get_revision(tree.last_revision())
536
properties = dict(last_rev.properties)
537
del properties['branch-nick']
540
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
541
'https://launchpad.net/bugs/235 fixed'},
544
def test_fixes_bug_with_alternate_trackers(self):
545
"""--fixes can be used on a properly configured branch to mark bug
546
fixes on multiple trackers.
548
tree = self.make_branch_and_tree('tree')
549
tree.branch.get_config().set_user_option(
550
'trac_twisted_url', 'http://twistedmatrix.com/trac')
551
self.build_tree(['tree/hello.txt'])
552
tree.add('hello.txt')
553
self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
555
# Get the revision properties, ignoring the branch-nick property, which
556
# we don't care about for this test.
557
last_rev = tree.branch.repository.get_revision(tree.last_revision())
558
properties = dict(last_rev.properties)
559
del properties['branch-nick']
562
{'bugs': 'https://launchpad.net/bugs/123 fixed\n'
563
'http://twistedmatrix.com/trac/ticket/235 fixed'},
566
def test_fixes_unknown_bug_prefix(self):
567
tree = self.make_branch_and_tree('tree')
568
self.build_tree(['tree/hello.txt'])
569
tree.add('hello.txt')
571
["Unrecognized bug %s. Commit refused." % 'xxx:123'],
572
'commit -m add-b --fixes=xxx:123',
575
def test_fixes_invalid_bug_number(self):
576
tree = self.make_branch_and_tree('tree')
577
self.build_tree(['tree/hello.txt'])
578
tree.add('hello.txt')
580
["Did not understand bug identifier orange: Must be an integer. "
581
"See \"bzr help bugs\" for more information on this feature.\n"
583
'commit -m add-b --fixes=lp:orange',
586
def test_fixes_invalid_argument(self):
587
"""Raise an appropriate error when the fixes argument isn't tag:id."""
588
tree = self.make_branch_and_tree('tree')
589
self.build_tree(['tree/hello.txt'])
590
tree.add('hello.txt')
592
[r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
593
r"See \"bzr help bugs\" for more information on this feature.\n"
594
r"Commit refused\."],
595
'commit -m add-b --fixes=orange',
598
def test_no_author(self):
599
"""If the author is not specified, the author property is not set."""
600
tree = self.make_branch_and_tree('tree')
601
self.build_tree(['tree/hello.txt'])
602
tree.add('hello.txt')
603
self.run_bzr( 'commit -m hello tree/hello.txt')
604
last_rev = tree.branch.repository.get_revision(tree.last_revision())
605
properties = last_rev.properties
606
self.assertFalse('author' in properties)
608
def test_author_sets_property(self):
609
"""commit --author='John Doe <jdoe@example.com>' sets the author
612
tree = self.make_branch_and_tree('tree')
613
self.build_tree(['tree/hello.txt'])
614
tree.add('hello.txt')
615
self.run_bzr(["commit", '-m', 'hello',
616
'--author', u'John D\xf6 <jdoe@example.com>',
618
last_rev = tree.branch.repository.get_revision(tree.last_revision())
619
properties = last_rev.properties
620
self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
622
def test_author_no_email(self):
623
"""Author's name without an email address is allowed, too."""
624
tree = self.make_branch_and_tree('tree')
625
self.build_tree(['tree/hello.txt'])
626
tree.add('hello.txt')
627
out, err = self.run_bzr("commit -m hello --author='John Doe' "
629
last_rev = tree.branch.repository.get_revision(tree.last_revision())
630
properties = last_rev.properties
631
self.assertEqual('John Doe', properties['authors'])
633
def test_multiple_authors(self):
634
"""Multiple authors can be specyfied, and all are stored."""
635
tree = self.make_branch_and_tree('tree')
636
self.build_tree(['tree/hello.txt'])
637
tree.add('hello.txt')
638
out, err = self.run_bzr("commit -m hello --author='John Doe' "
639
"--author='Jane Rey' tree/hello.txt")
640
last_rev = tree.branch.repository.get_revision(tree.last_revision())
641
properties = last_rev.properties
642
self.assertEqual('John Doe\nJane Rey', properties['authors'])
644
def test_commit_time(self):
645
tree = self.make_branch_and_tree('tree')
646
self.build_tree(['tree/hello.txt'])
647
tree.add('hello.txt')
648
out, err = self.run_bzr("commit -m hello "
649
"--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
650
last_rev = tree.branch.repository.get_revision(tree.last_revision())
652
'Sat 2009-10-10 08:00:00 +0100',
653
osutils.format_date(last_rev.timestamp, last_rev.timezone))
655
def test_commit_time_bad_time(self):
656
tree = self.make_branch_and_tree('tree')
657
self.build_tree(['tree/hello.txt'])
658
tree.add('hello.txt')
659
out, err = self.run_bzr("commit -m hello "
660
"--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
661
self.assertStartsWith(
662
err, "bzr: ERROR: Could not parse --commit-time:")
664
def test_partial_commit_with_renames_in_tree(self):
665
# this test illustrates bug #140419
666
t = self.make_branch_and_tree('.')
667
self.build_tree(['dir/', 'dir/a', 'test'])
668
t.add(['dir/', 'dir/a', 'test'])
669
t.commit('initial commit')
670
# important part: file dir/a should change parent
671
# and should appear before old parent
672
# then during partial commit we have error
673
# parent_id {dir-XXX} not in inventory
674
t.rename_one('dir/a', 'a')
675
self.build_tree_contents([('test', 'changes in test')])
677
out, err = self.run_bzr('commit test -m "partial commit"')
678
self.assertEquals('', out)
679
self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
681
def test_commit_readonly_checkout(self):
682
# https://bugs.edge.launchpad.net/bzr/+bug/129701
683
# "UnlockableTransport error trying to commit in checkout of readonly
685
self.make_branch('master')
686
master = BzrDir.open_from_transport(
687
self.get_readonly_transport('master')).open_branch()
688
master.create_checkout('checkout')
689
out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
691
self.assertContainsRe(err,
692
r'^bzr: ERROR: Cannot lock.*readonly transport')
694
def setup_editor(self):
695
# Test that commit template hooks work
696
if sys.platform == "win32":
697
f = file('fed.bat', 'w')
698
f.write('@rem dummy fed')
700
osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
702
f = file('fed.sh', 'wb')
703
f.write('#!/bin/sh\n')
705
os.chmod('fed.sh', 0755)
706
osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
708
def setup_commit_with_template(self):
710
msgeditor.hooks.install_named_hook("commit_message_template",
711
lambda commit_obj, msg: "save me some typing\n", None)
712
tree = self.make_branch_and_tree('tree')
713
self.build_tree(['tree/hello.txt'])
714
tree.add('hello.txt')
717
def test_commit_hook_template_accepted(self):
718
tree = self.setup_commit_with_template()
719
out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
720
last_rev = tree.branch.repository.get_revision(tree.last_revision())
721
self.assertEqual('save me some typing\n', last_rev.message)
723
def test_commit_hook_template_rejected(self):
724
tree = self.setup_commit_with_template()
725
expected = tree.last_revision()
726
out, err = self.run_bzr_error(["empty commit message"],
727
"commit tree/hello.txt", stdin="n\n")
728
self.assertEqual(expected, tree.last_revision())