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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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 ... import (
 
27
from bzrlib 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 bzrlib.controldir import ControlDir
 
34
from bzrlib.tests import (
35
35
    test_foreign,
36
36
    features,
37
37
    )
38
 
from .. import TestCaseWithTransport
39
 
from ..matchers import ContainsNoVfsCalls
 
38
from bzrlib.tests import TestCaseWithTransport
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
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) 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 '\'
54
54
        self.assertThat(
55
55
            err,
56
56
            DocTestMatches("""\
57
57
Committing to: ...
58
 
brz: ERROR: No changes to commit.\
59
 
 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,\
60
60
 or use --unchanged to force an empty commit.
61
61
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))
62
62
 
91
91
        a_tree.add('a_file')
92
92
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
93
93
 
94
 
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
95
 
        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')])
96
96
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
97
97
 
98
 
        self.build_tree_contents([('a/a_file', b'new contents')])
 
98
        self.build_tree_contents([('a/a_file', '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', b'new contents')])
 
129
        self.build_tree_contents([('hello.txt', '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).
203
203
        out, err = self.run_bzr('commit -m renamed')
204
204
        self.assertEqual('', out)
205
205
        self.assertContainsRe(err, '^Committing to: .*\n'
206
 
                              'renamed hello\\.txt => gutentag\\.txt\n'
207
 
                              'Committed revision 2\\.$\n')
 
206
                              'renamed hello\.txt => gutentag\.txt\n'
 
207
                              'Committed revision 2\.$\n')
208
208
 
209
209
    def test_verbose_commit_moved(self):
210
210
        # Verbose commit of file moved to new directory should say so
214
214
        wt.rename_one('hello.txt', 'subdir/hello.txt')
215
215
        out, err = self.run_bzr('commit -m renamed')
216
216
        self.assertEqual('', out)
217
 
        self.assertEqual({
 
217
        self.assertEqual(set([
218
218
            'Committing to: %s/' % osutils.getcwd(),
219
219
            'added subdir',
220
220
            'renamed hello.txt => subdir/hello.txt',
221
221
            'Committed revision 2.',
222
222
            '',
223
 
            }, set(err.split('\n')))
 
223
            ]), set(err.split('\n')))
224
224
 
225
225
    def test_verbose_commit_with_unknown(self):
226
226
        """Unknown files should not be listed by default in verbose output"""
228
228
        wt = ControlDir.create_standalone_workingtree('.')
229
229
        self.build_tree(['hello.txt', 'extra.txt'])
230
230
        wt.add(['hello.txt'])
231
 
        out, err = self.run_bzr('commit -m added')
 
231
        out,err = self.run_bzr('commit -m added')
232
232
        self.assertEqual('', out)
233
233
        self.assertContainsRe(err, '^Committing to: .*\n'
234
 
                              'added hello\\.txt\n'
235
 
                              'Committed revision 1\\.\n$')
 
234
                              'added hello\.txt\n'
 
235
                              'Committed revision 1\.\n$')
236
236
 
237
237
    def test_verbose_commit_with_unchanged(self):
238
238
        """Unchanged files should not be listed by default in verbose output"""
241
241
        tree.add('unchanged.txt')
242
242
        self.run_bzr('commit -m unchanged unchanged.txt')
243
243
        tree.add("hello.txt")
244
 
        out, err = self.run_bzr('commit -m added')
 
244
        out,err = self.run_bzr('commit -m added')
245
245
        self.assertEqual('', out)
246
246
        self.assertContainsRe(err, '^Committing to: .*\n'
247
 
                              'added hello\\.txt\n'
248
 
                              'Committed revision 2\\.$\n')
 
247
                              'added hello\.txt\n'
 
248
                              'Committed revision 2\.$\n')
249
249
 
250
250
    def test_verbose_commit_includes_master_location(self):
251
251
        """Location of master is displayed when committing to bound branch"""
262
262
 
263
263
    def test_commit_sanitizes_CR_in_message(self):
264
264
        # See bug #433779, basically Emacs likes to pass '\r\n' style line
265
 
        # 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
266
266
        # '\r' in commit messages. (Mostly because of issues where XML style
267
267
        # formats arbitrarily strip it out of the data while parsing.)
268
268
        # To make life easier for users, we just always translate '\r\n' =>
280
280
 
281
281
    def test_commit_merge_reports_all_modified_files(self):
282
282
        # the commit command should show all the files that are shown by
283
 
        # 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
284
284
        # changed by the user but rather through doing a merge.
285
285
        this_tree = self.make_branch_and_tree('this')
286
286
        # we need a bunch of files and dirs, to perform one action on each.
307
307
            'filetoleave']
308
308
            )
309
309
        this_tree.commit('create_files')
310
 
        other_dir = this_tree.controldir.sprout('other')
 
310
        other_dir = this_tree.bzrdir.sprout('other')
311
311
        other_tree = other_dir.open_workingtree()
312
312
        other_tree.lock_write()
313
313
        # perform the needed actions on the files and dirs.
320
320
            other_tree.remove(['dirtoremove', 'filetoremove'])
321
321
            self.build_tree_contents([
322
322
                ('other/newdir/',),
323
 
                ('other/filetomodify', b'new content'),
324
 
                ('other/newfile', b'new file content')])
 
323
                ('other/filetomodify', 'new content'),
 
324
                ('other/newfile', '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.')
330
330
        this_tree.merge_from_branch(other_tree.branch)
331
331
        out, err = self.run_bzr('commit -m added', working_dir='this')
332
332
        self.assertEqual('', out)
333
 
        self.assertEqual({
 
333
        self.assertEqual(set([
334
334
            'Committing to: %s/' % osutils.pathjoin(osutils.getcwd(), 'this'),
335
335
            'modified filetomodify',
336
336
            'added newdir',
343
343
            'deleted filetoremove',
344
344
            'Committed revision 2.',
345
345
            ''
346
 
            }, set(err.split('\n')))
 
346
            ]), set(err.split('\n')))
347
347
 
348
348
    def test_empty_commit_message(self):
349
349
        tree = self.make_branch_and_tree('.')
350
 
        self.build_tree_contents([('foo.c', b'int main() {}')])
 
350
        self.build_tree_contents([('foo.c', 'int main() {}')])
351
351
        tree.add('foo.c')
352
352
        self.run_bzr('commit -m ""')
353
353
 
357
357
        outer_tree = self.make_branch_and_tree('.')
358
358
        inner_tree = self.make_branch_and_tree('branch')
359
359
        self.build_tree_contents([
360
 
            ('branch/foo.c', b'int main() {}'),
361
 
            ('branch/bar.c', b'int main() {}')])
 
360
            ('branch/foo.c', 'int main() {}'),
 
361
            ('branch/bar.c', 'int main() {}')])
362
362
        inner_tree.add(['foo.c', 'bar.c'])
363
363
        # can't commit files in different trees; sane error
364
364
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
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
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([('u1/hosts', b'first offline change in u1\n')])
 
415
        self.build_tree_contents([('u1/hosts', '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
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', b'merge resolution\n')])
 
435
        self.build_tree_contents([('u1/hosts', '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')
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(
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')
 
533
                              'added hello\.txt\n'
 
534
                              'Committed revision 1\.\n')
548
535
 
549
536
    def test_no_bugs_no_properties(self):
550
537
        """If no bugs are fixed, the bugs property is not set.
554
541
        tree = self.make_branch_and_tree('tree')
555
542
        self.build_tree(['tree/hello.txt'])
556
543
        tree.add('hello.txt')
557
 
        self.run_bzr('commit -m hello tree/hello.txt')
 
544
        self.run_bzr( 'commit -m hello tree/hello.txt')
558
545
        # Get the revision properties, ignoring the branch-nick property, which
559
546
        # we don't care about for this test.
560
547
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
634
621
        self.build_tree(['tree/hello.txt'])
635
622
        tree.add('hello.txt')
636
623
        self.run_bzr_error(
637
 
            ["brz: ERROR: No tracker specified for bug 123. Use the form "
 
624
            ["bzr: ERROR: No tracker specified for bug 123. Use the form "
638
625
            "'tracker:id' or specify a default bug tracker using the "
639
626
            "`bugtracker` option.\n"
640
 
            "See \"brz help bugs\" for more information on this feature. "
 
627
            "See \"bzr help bugs\" for more information on this feature. "
641
628
            "Commit refused."],
642
629
            'commit -m add-b --fixes=123',
643
630
            working_dir='tree')
653
640
        tree.add('hello.txt')
654
641
        self.run_bzr_error(
655
642
            ["Did not understand bug identifier orange: Must be an integer. "
656
 
             "See \"brz help bugs\" for more information on this feature.\n"
 
643
             "See \"bzr help bugs\" for more information on this feature.\n"
657
644
             "Commit refused."],
658
645
            'commit -m add-b --fixes=lp:orange',
659
646
            working_dir='tree')
665
652
        tree.add('hello.txt')
666
653
        self.run_bzr_error(
667
654
            [r"Invalid bug orange:apples:bananas. Must be in the form of "
668
 
             r"'tracker:id'\. See \"brz help bugs\" for more information on "
 
655
             r"'tracker:id'\. See \"bzr help bugs\" for more information on "
669
656
             r"this feature.\nCommit refused\."],
670
657
            'commit -m add-b --fixes=orange:apples:bananas',
671
658
            working_dir='tree')
734
721
        out, err = self.run_bzr("commit -m hello "
735
722
            "--commit-time='NOT A TIME' tree/hello.txt", retcode=3)
736
723
        self.assertStartsWith(
737
 
            err, "brz: ERROR: Could not parse --commit-time:")
 
724
            err, "bzr: ERROR: Could not parse --commit-time:")
738
725
 
739
726
    def test_commit_time_missing_tz(self):
740
727
        tree = self.make_branch_and_tree('tree')
743
730
        out, err = self.run_bzr("commit -m hello "
744
731
            "--commit-time='2009-10-10 08:00:00' tree/hello.txt", retcode=3)
745
732
        self.assertStartsWith(
746
 
            err, "brz: ERROR: Could not parse --commit-time:")
 
733
            err, "bzr: ERROR: Could not parse --commit-time:")
747
734
        # Test that it is actually checking and does not simply crash with
748
735
        # some other exception
749
736
        self.assertContainsString(err, "missing a timezone offset")
759
746
        # then during partial commit we have error
760
747
        # parent_id {dir-XXX} not in inventory
761
748
        t.rename_one('dir/a', 'a')
762
 
        self.build_tree_contents([('test', b'changes in test')])
 
749
        self.build_tree_contents([('test', 'changes in test')])
763
750
        # partial commit
764
751
        out, err = self.run_bzr('commit test -m "partial commit"')
765
 
        self.assertEqual('', out)
 
752
        self.assertEquals('', out)
766
753
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
767
754
 
768
755
    def test_commit_readonly_checkout(self):
776
763
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
777
764
            retcode=3)
778
765
        self.assertContainsRe(err,
779
 
            r'^brz: ERROR: Cannot lock.*readonly transport')
 
766
            r'^bzr: ERROR: Cannot lock.*readonly transport')
780
767
 
781
768
    def setup_editor(self):
782
769
        # Test that commit template hooks work
784
771
            f = file('fed.bat', 'w')
785
772
            f.write('@rem dummy fed')
786
773
            f.close()
787
 
            self.overrideEnv('BRZ_EDITOR', "fed.bat")
 
774
            self.overrideEnv('BZR_EDITOR', "fed.bat")
788
775
        else:
789
776
            f = file('fed.sh', 'wb')
790
777
            f.write('#!/bin/sh\n')
791
778
            f.close()
792
 
            os.chmod('fed.sh', 0o755)
793
 
            self.overrideEnv('BRZ_EDITOR', "./fed.sh")
 
779
            os.chmod('fed.sh', 0755)
 
780
            self.overrideEnv('BZR_EDITOR', "./fed.sh")
794
781
 
795
782
    def setup_commit_with_template(self):
796
783
        self.setup_editor()
809
796
        out, err = self.run_bzr("commit tree/hello.txt", retcode=3,
810
797
            stdin="y\n")
811
798
        self.assertContainsRe(err,
812
 
            "brz: ERROR: Empty commit message specified")
 
799
            "bzr: ERROR: Empty commit message specified")
813
800
 
814
801
    def test_commit_hook_template_accepted(self):
815
802
        tree = self.setup_commit_with_template()
845
832
            f.write('hello')
846
833
        self.run_bzr(['add'], working_dir='foo')
847
834
        self.overrideEnv('EMAIL', None)
848
 
        self.overrideEnv('BRZ_EMAIL', None)
 
835
        self.overrideEnv('BZR_EMAIL', None)
849
836
        # Also, make sure that it's not inferred from mailname.
850
837
        self.overrideAttr(config, '_auto_user_id',
851
838
            lambda: (None, None))
877
864
        tree.add([u'abc\xa7/', u'abc\xa7/foo'])
878
865
        tree.commit('checkin')
879
866
 
880
 
        tree.rename_one(u'abc\xa7', 'abc')
 
867
        tree.rename_one(u'abc\xa7','abc')
881
868
 
882
869
        self.run_bzr('ci -m "non-ascii mv"')
883
870