~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2009-08-25 21:09:17 UTC
  • mto: This revision was merged to the branch mainline in revision 4650.
  • Revision ID: robertc@robertcollins.net-20090825210917-dq2i8k6n4z63pneh
Support shelve and unshelve on windows - bug 305006.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tests for the commit CLI of bzr."""
20
20
import os
21
21
import sys
22
22
 
23
 
import bzrlib
24
23
from bzrlib import (
25
24
    osutils,
26
25
    ignores,
 
26
    msgeditor,
27
27
    osutils,
28
28
    )
29
29
from bzrlib.bzrdir import BzrDir
43
43
        self.build_tree(['hello.txt'])
44
44
        out,err = self.run_bzr('commit -m empty', retcode=3)
45
45
        self.assertEqual('', out)
46
 
        self.assertContainsRe(err, 'bzr: ERROR: no changes to commit\.'
47
 
                                  ' use --unchanged to commit anyhow\n')
 
46
        self.assertContainsRe(err, 'bzr: ERROR: No changes to commit\.'
 
47
                                  ' Use --unchanged to commit anyhow.\n')
48
48
 
49
49
    def test_commit_success(self):
50
50
        """Successful commit should not leave behind a bzr-commit-* file"""
124
124
        wt.rename_one('hello.txt', 'subdir/hello.txt')
125
125
        out, err = self.run_bzr('commit -m renamed')
126
126
        self.assertEqual('', out)
127
 
        self.assertContainsRe(err, '^Committing to: .*\n'
128
 
                              'added subdir\n'
129
 
                              'renamed hello\.txt => subdir/hello\.txt\n'
130
 
                              'Committed revision 2\.\n$')
 
127
        self.assertEqual(set([
 
128
            'Committing to: %s/' % osutils.getcwd(),
 
129
            'added subdir',
 
130
            'renamed hello.txt => subdir/hello.txt',
 
131
            'Committed revision 2.',
 
132
            '',
 
133
            ]), set(err.split('\n')))
131
134
 
132
135
    def test_verbose_commit_with_unknown(self):
133
136
        """Unknown files should not be listed by default in verbose output"""
220
223
        os.chdir('this')
221
224
        out,err = self.run_bzr('commit -m added')
222
225
        self.assertEqual('', out)
223
 
        expected = '%s/' % (osutils.getcwd(), )
224
 
        self.assertEqualDiff(
225
 
            'Committing to: %s\n'
226
 
            'modified filetomodify\n'
227
 
            'added newdir\n'
228
 
            'added newfile\n'
229
 
            'renamed dirtorename => renameddir\n'
230
 
            'renamed filetorename => renamedfile\n'
231
 
            'renamed dirtoreparent => renameddir/reparenteddir\n'
232
 
            'renamed filetoreparent => renameddir/reparentedfile\n'
233
 
            'deleted dirtoremove\n'
234
 
            'deleted filetoremove\n'
235
 
            'Committed revision 2.\n' % (expected, ),
236
 
            err)
 
226
        self.assertEqual(set([
 
227
            'Committing to: %s/' % osutils.getcwd(),
 
228
            'modified filetomodify',
 
229
            'added newdir',
 
230
            'added newfile',
 
231
            'renamed dirtorename => renameddir',
 
232
            'renamed filetorename => renamedfile',
 
233
            'renamed dirtoreparent => renameddir/reparenteddir',
 
234
            'renamed filetoreparent => renameddir/reparentedfile',
 
235
            'deleted dirtoremove',
 
236
            'deleted filetoremove',
 
237
            'Committed revision 2.',
 
238
            ''
 
239
            ]), set(err.split('\n')))
237
240
 
238
241
    def test_empty_commit_message(self):
239
242
        tree = self.make_branch_and_tree('.')
248
251
        # LANG env variable has no effect on Windows
249
252
        # but some characters anyway cannot be represented
250
253
        # in default user encoding
251
 
        char = probe_bad_non_ascii(bzrlib.user_encoding)
 
254
        char = probe_bad_non_ascii(osutils.get_user_encoding())
252
255
        if char is None:
253
256
            raise TestSkipped('Cannot find suitable non-ascii character'
254
 
                'for user_encoding (%s)' % bzrlib.user_encoding)
 
257
                'for user_encoding (%s)' % osutils.get_user_encoding())
 
258
        # TODO: jam 2009-07-23 This test seems to fail on Windows now. My best
 
259
        #       guess is that the change to use Unicode command lines means
 
260
        #       that we no longer pay any attention to LANG=C when decoding the
 
261
        #       commandline arguments.
255
262
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
256
263
                                          retcode=1,
257
264
                                          env_changes={'LANG': 'C'})
302
309
    def test_commit_a_text_merge_in_a_checkout(self):
303
310
        # checkouts perform multiple actions in a transaction across bond
304
311
        # branches and their master, and have been observed to fail in the
305
 
        # past. This is a user story reported to fail in bug #43959 where 
 
312
        # past. This is a user story reported to fail in bug #43959 where
306
313
        # a merge done in a checkout (using the update command) failed to
307
314
        # commit correctly.
308
315
        trunk = self.make_branch_and_tree('trunk')
392
399
 
393
400
        # With no changes, it should just be 'no changes'
394
401
        # Make sure that commit is failing because there is nothing to do
395
 
        self.run_bzr_error(['no changes to commit'],
 
402
        self.run_bzr_error(['No changes to commit'],
396
403
                           'commit --strict -m no-changes',
397
404
                           working_dir='tree')
398
405
 
517
524
        self.build_tree(['tree/hello.txt'])
518
525
        tree.add('hello.txt')
519
526
        self.run_bzr_error(
520
 
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
 
527
            ["Did not understand bug identifier orange: Must be an integer. "
 
528
             "See \"bzr help bugs\" for more information on this feature.\n"
 
529
             "Commit refused."],
521
530
            'commit -m add-b --fixes=lp:orange',
522
531
            working_dir='tree')
523
532
 
527
536
        self.build_tree(['tree/hello.txt'])
528
537
        tree.add('hello.txt')
529
538
        self.run_bzr_error(
530
 
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
 
539
            [r"Invalid bug orange. Must be in the form of 'tracker:id'\. "
 
540
             r"See \"bzr help bugs\" for more information on this feature.\n"
531
541
             r"Commit refused\."],
532
542
            'commit -m add-b --fixes=orange',
533
543
            working_dir='tree')
554
564
                     "tree/hello.txt"])
555
565
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
556
566
        properties = last_rev.properties
557
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['author'])
 
567
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
558
568
 
559
569
    def test_author_no_email(self):
560
570
        """Author's name without an email address is allowed, too."""
565
575
                                "tree/hello.txt")
566
576
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
567
577
        properties = last_rev.properties
568
 
        self.assertEqual('John Doe', properties['author'])
 
578
        self.assertEqual('John Doe', properties['authors'])
 
579
 
 
580
    def test_multiple_authors(self):
 
581
        """Multiple authors can be specyfied, and all are stored."""
 
582
        tree = self.make_branch_and_tree('tree')
 
583
        self.build_tree(['tree/hello.txt'])
 
584
        tree.add('hello.txt')
 
585
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
 
586
                                "--author='Jane Rey' tree/hello.txt")
 
587
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
588
        properties = last_rev.properties
 
589
        self.assertEqual('John Doe\nJane Rey', properties['authors'])
569
590
 
570
591
    def test_partial_commit_with_renames_in_tree(self):
571
592
        # this test illustrates bug #140419
596
617
            retcode=3)
597
618
        self.assertContainsRe(err,
598
619
            r'^bzr: ERROR: Cannot lock.*readonly transport')
 
620
 
 
621
    def test_commit_hook_template(self):
 
622
        # Test that commit template hooks work
 
623
        def restoreDefaults():
 
624
            msgeditor.hooks['commit_message_template'] = []
 
625
            osutils.set_or_unset_env('BZR_EDITOR', default_editor)
 
626
        if sys.platform == "win32":
 
627
            f = file('fed.bat', 'w')
 
628
            f.write('@rem dummy fed')
 
629
            f.close()
 
630
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "fed.bat")
 
631
        else:
 
632
            f = file('fed.sh', 'wb')
 
633
            f.write('#!/bin/sh\n')
 
634
            f.close()
 
635
            os.chmod('fed.sh', 0755)
 
636
            default_editor = osutils.set_or_unset_env('BZR_EDITOR', "./fed.sh")
 
637
        self.addCleanup(restoreDefaults)
 
638
        msgeditor.hooks.install_named_hook("commit_message_template",
 
639
                lambda commit_obj, msg: "save me some typing\n", None)
 
640
        tree = self.make_branch_and_tree('tree')
 
641
        self.build_tree(['tree/hello.txt'])
 
642
        tree.add('hello.txt')
 
643
        out, err = self.run_bzr("commit tree/hello.txt")
 
644
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
645
        self.assertEqual('save me some typing\n', last_rev.message)