~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2008-09-09 15:09:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3699.
  • Revision ID: john@arbash-meinel.com-20080909150912-wyttm8he1zsls2ck
Use the right timing function on win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
23
24
from bzrlib import (
24
25
    osutils,
25
26
    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.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')))
 
127
        self.assertContainsRe(err, '^Committing to: .*\n'
 
128
                              'added subdir\n'
 
129
                              'renamed hello\.txt => subdir/hello\.txt\n'
 
130
                              'Committed revision 2\.\n$')
134
131
 
135
132
    def test_verbose_commit_with_unknown(self):
136
133
        """Unknown files should not be listed by default in verbose output"""
223
220
        os.chdir('this')
224
221
        out,err = self.run_bzr('commit -m added')
225
222
        self.assertEqual('', out)
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')))
 
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)
240
237
 
241
238
    def test_empty_commit_message(self):
242
239
        tree = self.make_branch_and_tree('.')
251
248
        # LANG env variable has no effect on Windows
252
249
        # but some characters anyway cannot be represented
253
250
        # in default user encoding
254
 
        char = probe_bad_non_ascii(osutils.get_user_encoding())
 
251
        char = probe_bad_non_ascii(bzrlib.user_encoding)
255
252
        if char is None:
256
253
            raise TestSkipped('Cannot find suitable non-ascii character'
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.
 
254
                'for user_encoding (%s)' % bzrlib.user_encoding)
262
255
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
263
256
                                          retcode=1,
264
257
                                          env_changes={'LANG': 'C'})
309
302
    def test_commit_a_text_merge_in_a_checkout(self):
310
303
        # checkouts perform multiple actions in a transaction across bond
311
304
        # branches and their master, and have been observed to fail in the
312
 
        # past. This is a user story reported to fail in bug #43959 where
 
305
        # past. This is a user story reported to fail in bug #43959 where 
313
306
        # a merge done in a checkout (using the update command) failed to
314
307
        # commit correctly.
315
308
        trunk = self.make_branch_and_tree('trunk')
399
392
 
400
393
        # With no changes, it should just be 'no changes'
401
394
        # Make sure that commit is failing because there is nothing to do
402
 
        self.run_bzr_error(['No changes to commit'],
 
395
        self.run_bzr_error(['no changes to commit'],
403
396
                           'commit --strict -m no-changes',
404
397
                           working_dir='tree')
405
398
 
524
517
        self.build_tree(['tree/hello.txt'])
525
518
        tree.add('hello.txt')
526
519
        self.run_bzr_error(
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."],
 
520
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
530
521
            'commit -m add-b --fixes=lp:orange',
531
522
            working_dir='tree')
532
523
 
536
527
        self.build_tree(['tree/hello.txt'])
537
528
        tree.add('hello.txt')
538
529
        self.run_bzr_error(
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"
 
530
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
541
531
             r"Commit refused\."],
542
532
            'commit -m add-b --fixes=orange',
543
533
            working_dir='tree')
564
554
                     "tree/hello.txt"])
565
555
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
566
556
        properties = last_rev.properties
567
 
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['authors'])
 
557
        self.assertEqual(u'John D\xf6 <jdoe@example.com>', properties['author'])
568
558
 
569
559
    def test_author_no_email(self):
570
560
        """Author's name without an email address is allowed, too."""
575
565
                                "tree/hello.txt")
576
566
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
577
567
        properties = last_rev.properties
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'])
 
568
        self.assertEqual('John Doe', properties['author'])
590
569
 
591
570
    def test_partial_commit_with_renames_in_tree(self):
592
571
        # this test illustrates bug #140419
617
596
            retcode=3)
618
597
        self.assertContainsRe(err,
619
598
            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)