/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_commit.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
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
24
24
 
25
25
from testtools.matchers import DocTestMatches
26
26
 
27
 
from bzrlib import (
 
27
from ... import (
28
28
    config,
29
29
    osutils,
30
30
    ignores,
31
31
    msgeditor,
32
32
    )
33
 
from bzrlib.controldir import ControlDir
34
 
from bzrlib.tests import (
 
33
from ...controldir import ControlDir
 
34
from .. import (
35
35
    test_foreign,
36
36
    features,
37
37
    )
38
 
from bzrlib.tests import TestCaseWithTransport
39
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
38
from .. import TestCaseWithTransport
 
39
from ..test_bedding import override_whoami
40
40
 
41
41
 
42
42
class TestCommit(TestCaseWithTransport):
46
46
        # If forced, it should succeed, but this is not tested here.
47
47
        self.make_branch_and_tree('.')
48
48
        self.build_tree(['hello.txt'])
49
 
        out,err = self.run_bzr('commit -m empty', retcode=3)
 
49
        out, err = self.run_bzr('commit -m empty', retcode=3)
50
50
        self.assertEqual('', out)
51
51
        # Two ugly bits here.
52
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 '\'
 
53
        # 2) brz: ERROR: is a really long line, so we wrap it with '\'
54
54
        self.assertThat(
55
55
            err,
56
56
            DocTestMatches("""\
57
57
Committing to: ...
58
 
bzr: ERROR: No changes to commit.\
59
 
 Please 'bzr add' the files you want to commit,\
 
58
brz: ERROR: No changes to commit.\
 
59
 Please 'brz add' the files you want to commit,\
60
60
 or use --unchanged to force an empty commit.
61
 
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
 
61
""", flags=doctest.ELLIPSIS | doctest.REPORT_UDIFF))
62
62
 
63
63
    def test_commit_success(self):
64
64
        """Successful commit should not leave behind a bzr-commit-* file"""
79
79
    def test_commit_lossy_foreign(self):
80
80
        test_foreign.register_dummy_foreign_for_test(self)
81
81
        self.make_branch_and_tree('.',
82
 
            format=test_foreign.DummyForeignVcsDirFormat())
 
82
                                  format=test_foreign.DummyForeignVcsDirFormat())
83
83
        self.run_bzr('commit --lossy --unchanged -m message')
84
84
        output = self.run_bzr('revision-info')[0]
85
85
        self.assertTrue(output.startswith('1 dummy-'))
91
91
        a_tree.add('a_file')
92
92
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
93
93
 
94
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
95
 
        self.build_tree_contents([('b/a_file', 'changes in b')])
 
94
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
 
95
        self.build_tree_contents([('b/a_file', b'changes in b')])
96
96
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
97
97
 
98
 
        self.build_tree_contents([('a/a_file', 'new contents')])
 
98
        self.build_tree_contents([('a/a_file', b'new contents')])
99
99
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
100
100
 
101
101
        b_tree.merge_from_branch(a_tree.branch)
108
108
        tree = self.make_branch_and_tree('.')
109
109
        self.build_tree(['hello.txt'])
110
110
        tree.add("hello.txt")
111
 
        out,err = self.run_bzr('commit -m added')
 
111
        out, err = self.run_bzr('commit -m added')
112
112
        self.assertEqual('', out)
113
113
        self.assertContainsRe(err, '^Committing to: .*\n'
114
114
                              'added hello.txt\n'
126
126
    def test_verbose_commit_modified(self):
127
127
        # Verbose commit of modified file should say so
128
128
        wt = self.prepare_simple_history()
129
 
        self.build_tree_contents([('hello.txt', 'new contents')])
 
129
        self.build_tree_contents([('hello.txt', b'new contents')])
130
130
        out, err = self.run_bzr('commit -m modified')
131
131
        self.assertEqual('', out)
132
132
        self.assertContainsRe(err, '^Committing to: .*\n'
133
 
                              'modified hello\.txt\n'
134
 
                              'Committed revision 2\.\n$')
 
133
                              'modified hello\\.txt\n'
 
134
                              'Committed revision 2\\.\n$')
135
135
 
136
136
    def test_unicode_commit_message_is_filename(self):
137
137
        """Unicode commit message same as a filename (Bug #563646).
139
139
        self.requireFeature(features.UnicodeFilenameFeature)
140
140
        file_name = u'\N{euro sign}'
141
141
        self.run_bzr(['init'])
142
 
        with open(file_name, 'w') as f: f.write('hello world')
 
142
        with open(file_name, 'w') as f:
 
143
            f.write('hello world')
143
144
        self.run_bzr(['add'])
144
145
        out, err = self.run_bzr(['commit', '-m', file_name])
145
 
        reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
146
        reflags = re.MULTILINE | re.DOTALL | re.UNICODE
146
147
        te = osutils.get_terminal_encoding()
147
 
        self.assertContainsRe(err.decode(te),
148
 
            u'The commit message is a file name:',
149
 
            flags=reflags)
 
148
        self.assertContainsRe(err,
 
149
                              u'The commit message is a file name:',
 
150
                              flags=reflags)
150
151
 
151
152
        # Run same test with a filename that causes encode
152
153
        # error for the terminal encoding. We do this
157
158
        try:
158
159
            osutils.get_terminal_encoding = lambda trace=None: 'ascii'
159
160
            file_name = u'foo\u1234'
160
 
            with open(file_name, 'w') as f: f.write('hello world')
 
161
            with open(file_name, 'w') as f:
 
162
                f.write('hello world')
161
163
            self.run_bzr(['add'])
162
164
            out, err = self.run_bzr(['commit', '-m', file_name])
163
 
            reflags = re.MULTILINE|re.DOTALL|re.UNICODE
 
165
            reflags = re.MULTILINE | re.DOTALL | re.UNICODE
164
166
            te = osutils.get_terminal_encoding()
165
 
            self.assertContainsRe(err.decode(te, 'replace'),
166
 
                u'The commit message is a file name:',
167
 
                flags=reflags)
 
167
            self.assertContainsRe(err,
 
168
                                  u'The commit message is a file name:',
 
169
                                  flags=reflags)
168
170
        finally:
169
171
            osutils.get_terminal_encoding = default_get_terminal_enc
170
172
 
173
175
        tree = self.make_branch_and_tree(".")
174
176
        self.build_tree(["f"])
175
177
        tree.add(["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\"$")
 
178
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
 
179
                                    encoding="utf-8", retcode=3)
 
180
        self.assertContainsRe(err, b"(?m)not versioned: \"\xc2\xa7\"$")
179
181
 
180
182
    def test_non_ascii_file_unversioned_iso_8859_5(self):
181
183
        self.requireFeature(features.UnicodeFilenameFeature)
182
184
        tree = self.make_branch_and_tree(".")
183
185
        self.build_tree(["f"])
184
186
        tree.add(["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\"$")
 
187
        out, err = self.run_bzr_raw(["commit", "-m", "Wrong filename", u"\xa7"],
 
188
                                    encoding="iso-8859-5", retcode=3)
 
189
        self.assertNotContainsString(err, b"\xc2\xa7")
 
190
        self.assertContainsRe(err, b"(?m)not versioned: \"\xfd\"$")
190
191
 
191
192
    def test_warn_about_forgotten_commit_message(self):
192
193
        """Test that the lack of -m parameter is caught"""
203
204
        out, err = self.run_bzr('commit -m renamed')
204
205
        self.assertEqual('', out)
205
206
        self.assertContainsRe(err, '^Committing to: .*\n'
206
 
                              'renamed hello\.txt => gutentag\.txt\n'
207
 
                              'Committed revision 2\.$\n')
 
207
                              'renamed hello\\.txt => gutentag\\.txt\n'
 
208
                              'Committed revision 2\\.$\n')
208
209
 
209
210
    def test_verbose_commit_moved(self):
210
211
        # Verbose commit of file moved to new directory should say so
214
215
        wt.rename_one('hello.txt', 'subdir/hello.txt')
215
216
        out, err = self.run_bzr('commit -m renamed')
216
217
        self.assertEqual('', out)
217
 
        self.assertEqual(set([
 
218
        self.assertEqual({
218
219
            'Committing to: %s/' % osutils.getcwd(),
219
220
            'added subdir',
220
221
            'renamed hello.txt => subdir/hello.txt',
221
222
            'Committed revision 2.',
222
223
            '',
223
 
            ]), set(err.split('\n')))
 
224
            }, set(err.split('\n')))
224
225
 
225
226
    def test_verbose_commit_with_unknown(self):
226
227
        """Unknown files should not be listed by default in verbose output"""
228
229
        wt = ControlDir.create_standalone_workingtree('.')
229
230
        self.build_tree(['hello.txt', 'extra.txt'])
230
231
        wt.add(['hello.txt'])
231
 
        out,err = self.run_bzr('commit -m added')
 
232
        out, err = self.run_bzr('commit -m added')
232
233
        self.assertEqual('', out)
233
234
        self.assertContainsRe(err, '^Committing to: .*\n'
234
 
                              'added hello\.txt\n'
235
 
                              'Committed revision 1\.\n$')
 
235
                              'added hello\\.txt\n'
 
236
                              'Committed revision 1\\.\n$')
236
237
 
237
238
    def test_verbose_commit_with_unchanged(self):
238
239
        """Unchanged files should not be listed by default in verbose output"""
241
242
        tree.add('unchanged.txt')
242
243
        self.run_bzr('commit -m unchanged unchanged.txt')
243
244
        tree.add("hello.txt")
244
 
        out,err = self.run_bzr('commit -m added')
 
245
        out, err = self.run_bzr('commit -m added')
245
246
        self.assertEqual('', out)
246
247
        self.assertContainsRe(err, '^Committing to: .*\n'
247
 
                              'added hello\.txt\n'
248
 
                              'Committed revision 2\.$\n')
 
248
                              'added hello\\.txt\n'
 
249
                              'Committed revision 2\\.$\n')
249
250
 
250
251
    def test_verbose_commit_includes_master_location(self):
251
252
        """Location of master is displayed when committing to bound branch"""
262
263
 
263
264
    def test_commit_sanitizes_CR_in_message(self):
264
265
        # See bug #433779, basically Emacs likes to pass '\r\n' style line
265
 
        # endings to 'bzr commit -m ""' which breaks because we don't allow
 
266
        # endings to 'brz commit -m ""' which breaks because we don't allow
266
267
        # '\r' in commit messages. (Mostly because of issues where XML style
267
268
        # formats arbitrarily strip it out of the data while parsing.)
268
269
        # To make life easier for users, we just always translate '\r\n' =>
280
281
 
281
282
    def test_commit_merge_reports_all_modified_files(self):
282
283
        # the commit command should show all the files that are shown by
283
 
        # bzr diff or bzr status when committing, even when they were not
 
284
        # brz diff or brz status when committing, even when they were not
284
285
        # changed by the user but rather through doing a merge.
285
286
        this_tree = self.make_branch_and_tree('this')
286
287
        # we need a bunch of files and dirs, to perform one action on each.
307
308
            'filetoleave']
308
309
            )
309
310
        this_tree.commit('create_files')
310
 
        other_dir = this_tree.bzrdir.sprout('other')
 
311
        other_dir = this_tree.controldir.sprout('other')
311
312
        other_tree = other_dir.open_workingtree()
312
 
        other_tree.lock_write()
313
 
        # perform the needed actions on the files and dirs.
314
 
        try:
 
313
        with other_tree.lock_write():
 
314
            # perform the needed actions on the files and dirs.
315
315
            other_tree.rename_one('dirtorename', 'renameddir')
316
316
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
317
317
            other_tree.rename_one('filetorename', 'renamedfile')
320
320
            other_tree.remove(['dirtoremove', 'filetoremove'])
321
321
            self.build_tree_contents([
322
322
                ('other/newdir/',),
323
 
                ('other/filetomodify', 'new content'),
324
 
                ('other/newfile', 'new file content')])
 
323
                ('other/filetomodify', b'new content'),
 
324
                ('other/newfile', b'new file content')])
325
325
            other_tree.add('newfile')
326
326
            other_tree.add('newdir/')
327
327
            other_tree.commit('modify all sample files and dirs.')
328
 
        finally:
329
 
            other_tree.unlock()
330
328
        this_tree.merge_from_branch(other_tree.branch)
331
329
        out, err = self.run_bzr('commit -m added', working_dir='this')
332
330
        self.assertEqual('', out)
333
 
        self.assertEqual(set([
 
331
        self.assertEqual({
334
332
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
335
333
            'modified filetomodify',
336
334
            'added newdir',
343
341
            'deleted filetoremove',
344
342
            'Committed revision 2.',
345
343
            ''
346
 
            ]), set(err.split('\n')))
 
344
            }, set(err.split('\n')))
347
345
 
348
346
    def test_empty_commit_message(self):
349
347
        tree = self.make_branch_and_tree('.')
350
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
348
        self.build_tree_contents([('foo.c', b'int main() {}')])
351
349
        tree.add('foo.c')
352
350
        self.run_bzr('commit -m ""')
353
351
 
357
355
        outer_tree = self.make_branch_and_tree('.')
358
356
        inner_tree = self.make_branch_and_tree('branch')
359
357
        self.build_tree_contents([
360
 
            ('branch/foo.c', 'int main() {}'),
361
 
            ('branch/bar.c', 'int main() {}')])
 
358
            ('branch/foo.c', b'int main() {}'),
 
359
            ('branch/bar.c', b'int main() {}')])
362
360
        inner_tree.add(['foo.c', 'bar.c'])
363
361
        # can't commit files in different trees; sane error
364
362
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
367
365
        # can commit to branch - records bar.c
368
366
        self.run_bzr('commit -m newstuff branch')
369
367
        # No changes left
370
 
        self.run_bzr_error(["No changes to commit"], 'commit -m newstuff branch')
 
368
        self.run_bzr_error(["No changes to commit"],
 
369
                           'commit -m newstuff branch')
371
370
 
372
371
    def test_out_of_date_tree_commit(self):
373
372
        # check we get an error code and a clear message committing with an out
378
377
        # commit to the original branch to make the checkout out of date
379
378
        tree.commit('message branch', allow_pointless=True)
380
379
        # now commit to the checkout should emit
381
 
        # ERROR: Out of date with the branch, 'bzr update' is suggested
 
380
        # ERROR: Out of date with the branch, 'brz update' is suggested
382
381
        output = self.run_bzr('commit --unchanged -m checkout_message '
383
 
                             'checkout', retcode=3)
 
382
                              'checkout', retcode=3)
384
383
        self.assertEqual(output,
385
384
                         ('',
386
 
                          "bzr: ERROR: Working tree is out of date, please "
387
 
                          "run 'bzr update'.\n"))
 
385
                          "brz: ERROR: Working tree is out of date, please "
 
386
                          "run 'brz update'.\n"))
388
387
 
389
388
    def test_local_commit_unbound(self):
390
389
        # a --local commit on an unbound branch is an error
391
390
        self.make_branch_and_tree('.')
392
391
        out, err = self.run_bzr('commit --local', retcode=3)
393
392
        self.assertEqualDiff('', out)
394
 
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
 
393
        self.assertEqualDiff('brz: ERROR: Cannot perform local-only commits '
395
394
                             'on unbound branches.\n', err)
396
395
 
397
396
    def test_commit_a_text_merge_in_a_checkout(self):
403
402
        trunk = self.make_branch_and_tree('trunk')
404
403
 
405
404
        u1 = trunk.branch.create_checkout('u1')
406
 
        self.build_tree_contents([('u1/hosts', 'initial contents\n')])
 
405
        self.build_tree_contents([('u1/hosts', b'initial contents\n')])
407
406
        u1.add('hosts')
408
407
        self.run_bzr('commit -m add-hosts u1')
409
408
 
410
409
        u2 = trunk.branch.create_checkout('u2')
411
 
        self.build_tree_contents([('u2/hosts', 'altered in u2\n')])
 
410
        self.build_tree_contents([('u2/hosts', b'altered in u2\n')])
412
411
        self.run_bzr('commit -m checkin-from-u2 u2')
413
412
 
414
413
        # make an offline commits
415
 
        self.build_tree_contents([('u1/hosts', 'first offline change in u1\n')])
 
414
        self.build_tree_contents(
 
415
            [('u1/hosts', b'first offline change in u1\n')])
416
416
        self.run_bzr('commit -m checkin-offline --local u1')
417
417
 
418
418
        # now try to pull in online work from u2, and then commit our offline
419
419
        # work as a merge
420
420
        # retcode 1 as we expect a text conflict
421
421
        self.run_bzr('update u1', retcode=1)
422
 
        self.assertFileEqual('''\
 
422
        self.assertFileEqual(b'''\
423
423
<<<<<<< TREE
424
424
first offline change in u1
425
425
=======
432
432
        # add a text change here to represent resolving the merge conflicts in
433
433
        # favour of a new version of the file not identical to either the u1
434
434
        # version or the u2 version.
435
 
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
 
435
        self.build_tree_contents([('u1/hosts', b'merge resolution\n')])
436
436
        self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
437
437
 
438
438
    def test_commit_exclude_excludes_modified_files(self):
530
530
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
531
531
        self.assertEqual('', output)
532
532
        self.assertContainsRe(err, 'Committing to: .*\n'
533
 
                              'added hello\.txt\n'
534
 
                              'Committed revision 1\.\n')
 
533
                              'added hello\\.txt\n'
 
534
                              'Committed revision 1\\.\n')
 
535
 
 
536
    def test_fixes_bug_unicode(self):
 
537
        """commit --fixes=lp:unicode succeeds without output."""
 
538
        tree = self.make_branch_and_tree('tree')
 
539
        self.build_tree(['tree/hello.txt'])
 
540
        tree.add('hello.txt')
 
541
        output, err = self.run_bzr_raw(
 
542
            ['commit', '-m', 'hello',
 
543
             u'--fixes=generic:\u20ac', 'tree/hello.txt'],
 
544
            encoding='utf-8', retcode=3)
 
545
        self.assertEqual(b'', output)
 
546
        self.assertContainsRe(err,
 
547
                              b'brz: ERROR: Unrecognized bug generic:\xe2\x82\xac\\. Commit refused.\n')
535
548
 
536
549
    def test_no_bugs_no_properties(self):
537
550
        """If no bugs are fixed, the bugs property is not set.
541
554
        tree = self.make_branch_and_tree('tree')
542
555
        self.build_tree(['tree/hello.txt'])
543
556
        tree.add('hello.txt')
544
 
        self.run_bzr( 'commit -m hello tree/hello.txt')
 
557
        self.run_bzr('commit -m hello tree/hello.txt')
545
558
        # Get the revision properties, ignoring the branch-nick property, which
546
559
        # we don't care about for this test.
547
560
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
549
562
        del properties['branch-nick']
550
563
        self.assertFalse('bugs' in properties)
551
564
 
 
565
    def test_bugs_sets_property(self):
 
566
        """commit --bugs=lp:234 sets the lp:234 revprop to 'related'."""
 
567
        tree = self.make_branch_and_tree('tree')
 
568
        self.build_tree(['tree/hello.txt'])
 
569
        tree.add('hello.txt')
 
570
        self.run_bzr('commit -m hello --bugs=lp:234 tree/hello.txt')
 
571
 
 
572
        # Get the revision properties, ignoring the branch-nick property, which
 
573
        # we don't care about for this test.
 
574
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
575
        properties = dict(last_rev.properties)
 
576
        del properties[u'branch-nick']
 
577
 
 
578
        self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 related'},
 
579
                         properties)
 
580
 
552
581
    def test_fixes_bug_sets_property(self):
553
582
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
554
583
        tree = self.make_branch_and_tree('tree')
560
589
        # we don't care about for this test.
561
590
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
562
591
        properties = dict(last_rev.properties)
563
 
        del properties['branch-nick']
 
592
        del properties[u'branch-nick']
564
593
 
565
 
        self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
 
594
        self.assertEqual({u'bugs': 'https://launchpad.net/bugs/234 fixed'},
566
595
                         properties)
567
596
 
568
597
    def test_fixes_multiple_bugs_sets_properties(self):
580
609
        del properties['branch-nick']
581
610
 
582
611
        self.assertEqual(
583
 
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
584
 
                     'https://launchpad.net/bugs/235 fixed'},
 
612
            {u'bugs': 'https://launchpad.net/bugs/123 fixed\n'
 
613
             'https://launchpad.net/bugs/235 fixed'},
585
614
            properties)
586
615
 
587
616
    def test_fixes_bug_with_alternate_trackers(self):
593
622
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
594
623
        self.build_tree(['tree/hello.txt'])
595
624
        tree.add('hello.txt')
596
 
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
 
625
        self.run_bzr(
 
626
            'commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
597
627
 
598
628
        # Get the revision properties, ignoring the branch-nick property, which
599
629
        # we don't care about for this test.
621
651
        self.build_tree(['tree/hello.txt'])
622
652
        tree.add('hello.txt')
623
653
        self.run_bzr_error(
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. "
628
 
            "Commit refused."],
 
654
            ["brz: ERROR: No tracker specified for bug 123. Use the form "
 
655
             "'tracker:id' or specify a default bug tracker using the "
 
656
             "`bugtracker` option.\n"
 
657
             "See \"brz help bugs\" for more information on this feature. "
 
658
             "Commit refused."],
629
659
            'commit -m add-b --fixes=123',
630
660
            working_dir='tree')
631
661
        tree.branch.get_config_stack().set("bugtracker", "lp")
640
670
        tree.add('hello.txt')
641
671
        self.run_bzr_error(
642
672
            ["Did not understand bug identifier orange: Must be an integer. "
643
 
             "See \"bzr help bugs\" for more information on this feature.\n"
 
673
             "See \"brz help bugs\" for more information on this feature.\n"
644
674
             "Commit refused."],
645
675
            'commit -m add-b --fixes=lp:orange',
646
676
            working_dir='tree')
652
682
        tree.add('hello.txt')
653
683
        self.run_bzr_error(
654
684
            [r"Invalid bug orange:apples:bananas. Must be in the form of "
655
 
             r"'tracker:id'\. See \"bzr help bugs\" for more information on "
 
685
             r"'tracker:id'\. See \"brz help bugs\" for more information on "
656
686
             r"this feature.\nCommit refused\."],
657
687
            'commit -m add-b --fixes=orange:apples:bananas',
658
688
            working_dir='tree')
662
692
        tree = self.make_branch_and_tree('tree')
663
693
        self.build_tree(['tree/hello.txt'])
664
694
        tree.add('hello.txt')
665
 
        self.run_bzr( 'commit -m hello tree/hello.txt')
 
695
        self.run_bzr('commit -m hello tree/hello.txt')
666
696
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
667
697
        properties = last_rev.properties
668
698
        self.assertFalse('author' in properties)
676
706
        tree.add('hello.txt')
677
707
        self.run_bzr(["commit", '-m', 'hello',
678
708
                      '--author', u'John D\xf6 <jdoe@example.com>',
679
 
                     "tree/hello.txt"])
 
709
                      "tree/hello.txt"])
680
710
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
681
711
        properties = last_rev.properties
682
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
 
712
        self.assertEqual(u'John D\xf6 <jdoe@example.com>',
 
713
                         properties['authors'])
683
714
 
684
715
    def test_author_no_email(self):
685
716
        """Author's name without an email address is allowed, too."""
708
739
        self.build_tree(['tree/hello.txt'])
709
740
        tree.add('hello.txt')
710
741
        out, err = self.run_bzr("commit -m hello "
711
 
            "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
 
742
                                "--commit-time='2009-10-10 08:00:00 +0100' tree/hello.txt")
712
743
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
713
744
        self.assertEqual(
714
745
            'Sat 2009-10-10 08:00:00 +0100',
715
746
            osutils.format_date(last_rev.timestamp, last_rev.timezone))
716
 
        
 
747
 
717
748
    def test_commit_time_bad_time(self):
718
749
        tree = self.make_branch_and_tree('tree')
719
750
        self.build_tree(['tree/hello.txt'])
720
751
        tree.add('hello.txt')
721
752
        out, err = self.run_bzr("commit -m hello "
722
 
            "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
 
753
                                "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
723
754
        self.assertStartsWith(
724
 
            err, "bzr: ERROR: Could not parse --commit-time:")
 
755
            err, "brz: ERROR: Could not parse --commit-time:")
725
756
 
726
757
    def test_commit_time_missing_tz(self):
727
758
        tree = self.make_branch_and_tree('tree')
728
759
        self.build_tree(['tree/hello.txt'])
729
760
        tree.add('hello.txt')
730
761
        out, err = self.run_bzr("commit -m hello "
731
 
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
 
762
                                "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
732
763
        self.assertStartsWith(
733
 
            err, "bzr: ERROR: Could not parse --commit-time:")
 
764
            err, "brz: ERROR: Could not parse --commit-time:")
734
765
        # Test that it is actually checking and does not simply crash with
735
766
        # some other exception
736
767
        self.assertContainsString(err, "missing a timezone offset")
746
777
        # then during partial commit we have error
747
778
        # parent_id {dir-XXX} not in inventory
748
779
        t.rename_one('dir/a', 'a')
749
 
        self.build_tree_contents([('test', 'changes in test')])
 
780
        self.build_tree_contents([('test', b'changes in test')])
750
781
        # partial commit
751
782
        out, err = self.run_bzr('commit test -m "partial commit"')
752
 
        self.assertEquals('', out)
 
783
        self.assertEqual('', out)
753
784
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
754
785
 
755
786
    def test_commit_readonly_checkout(self):
761
792
            self.get_readonly_transport('master')).open_branch()
762
793
        master.create_checkout('checkout')
763
794
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
764
 
            retcode=3)
 
795
                                retcode=3)
765
796
        self.assertContainsRe(err,
766
 
            r'^bzr: ERROR: Cannot lock.*readonly transport')
 
797
                              r'^brz: ERROR: Cannot lock.*readonly transport')
767
798
 
768
799
    def setup_editor(self):
769
800
        # Test that commit template hooks work
770
801
        if sys.platform == "win32":
771
 
            f = file('fed.bat', 'w')
772
 
            f.write('@rem dummy fed')
773
 
            f.close()
774
 
            self.overrideEnv('BZR_EDITOR', "fed.bat")
 
802
            with open('fed.bat', 'w') as f:
 
803
                f.write('@rem dummy fed')
 
804
            self.overrideEnv('BRZ_EDITOR', "fed.bat")
775
805
        else:
776
 
            f = file('fed.sh', 'wb')
777
 
            f.write('#!/bin/sh\n')
778
 
            f.close()
779
 
            os.chmod('fed.sh', 0755)
780
 
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
 
806
            with open('fed.sh', 'wb') as f:
 
807
                f.write(b'#!/bin/sh\n')
 
808
            os.chmod('fed.sh', 0o755)
 
809
            self.overrideEnv('BRZ_EDITOR', "./fed.sh")
781
810
 
782
811
    def setup_commit_with_template(self):
783
812
        self.setup_editor()
784
813
        msgeditor.hooks.install_named_hook("commit_message_template",
785
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
814
                                           lambda commit_obj, msg: "save me some typing\n", None)
786
815
        tree = self.make_branch_and_tree('tree')
787
816
        self.build_tree(['tree/hello.txt'])
788
817
        tree.add('hello.txt')
794
823
        self.build_tree(['tree/hello.txt'])
795
824
        tree.add('hello.txt')
796
825
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
797
 
            stdin="y\n")
 
826
                                stdin="y\n")
798
827
        self.assertContainsRe(err,
799
 
            "bzr: ERROR: Empty commit message specified")
 
828
                              "brz: ERROR: Empty commit message specified")
800
829
 
801
830
    def test_commit_hook_template_accepted(self):
802
831
        tree = self.setup_commit_with_template()
808
837
        tree = self.setup_commit_with_template()
809
838
        expected = tree.last_revision()
810
839
        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")
 
840
                                       " Please specify a commit message with either"
 
841
                                       " --message or --file or leave a blank message"
 
842
                                       " with --message \"\"."],
 
843
                                      "commit tree/hello.txt", stdin="n\n")
815
844
        self.assertEqual(expected, tree.last_revision())
816
845
 
817
846
    def test_set_commit_message(self):
818
847
        msgeditor.hooks.install_named_hook("set_commit_message",
819
 
                lambda commit_obj, msg: "save me some typing\n", None)
 
848
                                           lambda commit_obj, msg: "save me some typing\n", None)
820
849
        tree = self.make_branch_and_tree('tree')
821
850
        self.build_tree(['tree/hello.txt'])
822
851
        tree.add('hello.txt')
831
860
        with open('foo/foo.txt', 'w') as f:
832
861
            f.write('hello')
833
862
        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))
 
863
        override_whoami(self)
839
864
        self.run_bzr_error(
840
865
            ['Unable to determine your name'],
841
866
            ['commit', '-m', 'initial'], working_dir='foo')
845
870
        """
846
871
        self.run_bzr(['init', 'test_branch'])
847
872
        self.run_bzr(['checkout', 'test_branch', 'test_checkout'])
848
 
        self.run_bzr(['bind', '.'], working_dir='test_checkout') # bind to self
 
873
        # bind to self
 
874
        self.run_bzr(['bind', '.'], working_dir='test_checkout')
849
875
        with open('test_checkout/foo.txt', 'w') as f:
850
876
            f.write('hello')
851
877
        self.run_bzr(['add'], working_dir='test_checkout')
864
890
        tree.add([u'abc\xa7/', u'abc\xa7/foo'])
865
891
        tree.commit('checkin')
866
892
 
867
 
        tree.rename_one(u'abc\xa7','abc')
 
893
        tree.rename_one(u'abc\xa7', 'abc')
868
894
 
869
895
        self.run_bzr('ci -m "non-ascii mv"')
870
896
 
871
 
 
872
 
class TestSmartServerCommit(TestCaseWithTransport):
873
 
 
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'),
880
 
            'target'])
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)