/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 brzlib/tests/blackbox/test_commit.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

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