/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: Martin Pool
  • Date: 2007-09-14 06:31:28 UTC
  • mfrom: (2822 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2823.
  • Revision ID: mbp@sourcefrog.net-20070914063128-0p7mh6zfb4pzdg9p
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
20
import os
21
 
import re
22
 
import sys
23
21
 
24
22
from bzrlib import (
25
23
    ignores,
26
24
    )
27
 
from bzrlib.branch import Branch
28
25
from bzrlib.bzrdir import BzrDir
29
 
from bzrlib.errors import BzrCommandError
30
26
from bzrlib.tests.blackbox import ExternalBase
31
 
from bzrlib.workingtree import WorkingTree
32
27
 
33
28
 
34
29
class TestCommit(ExternalBase):
36
31
    def test_05_empty_commit(self):
37
32
        """Commit of tree with no versioned files should fail"""
38
33
        # If forced, it should succeed, but this is not tested here.
39
 
        self.run_bzr("init")
 
34
        self.make_branch_and_tree('.')
40
35
        self.build_tree(['hello.txt'])
41
36
        out,err = self.run_bzr('commit -m empty', retcode=3)
42
37
        self.assertEqual('', out)
43
 
        self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
 
38
        self.assertContainsRe(err, 'bzr: ERROR: no changes to commit\.'
44
39
                                  ' use --unchanged to commit anyhow\n')
45
40
 
46
41
    def test_commit_success(self):
47
42
        """Successful commit should not leave behind a bzr-commit-* file"""
48
 
        self.run_bzr("init")
 
43
        self.make_branch_and_tree('.')
49
44
        self.run_bzr('commit --unchanged -m message')
50
45
        self.assertEqual('', self.run_bzr('unknowns')[0])
51
46
 
55
50
 
56
51
    def test_commit_with_path(self):
57
52
        """Commit tree with path of root specified"""
58
 
        self.run_bzr('init a')
 
53
        a_tree = self.make_branch_and_tree('a')
59
54
        self.build_tree(['a/a_file'])
60
 
        self.run_bzr('add a/a_file')
 
55
        a_tree.add('a_file')
61
56
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
62
57
 
63
 
        self.run_bzr('branch a b')
 
58
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
64
59
        self.build_tree_contents([('b/a_file', 'changes in b')])
65
60
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
66
61
 
67
62
        self.build_tree_contents([('a/a_file', 'new contents')])
68
63
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
69
64
 
70
 
        os.chdir('b')
71
 
        self.run_bzr('merge ../a', retcode=1) # will conflict
72
 
        os.chdir('..')
 
65
        b_tree.merge_from_branch(a_tree.branch)
 
66
        self.assertEqual(len(b_tree.conflicts()), 1)
73
67
        self.run_bzr('resolved b/a_file')
74
68
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
75
69
 
76
70
 
77
71
    def test_10_verbose_commit(self):
78
72
        """Add one file and examine verbose commit output"""
79
 
        self.run_bzr("init")
 
73
        tree = self.make_branch_and_tree('.')
80
74
        self.build_tree(['hello.txt'])
81
 
        self.run_bzr("add hello.txt")
 
75
        tree.add("hello.txt")
82
76
        out,err = self.run_bzr('commit -m added')
83
77
        self.assertEqual('', out)
84
 
        self.assertEqual('added hello.txt\n'
85
 
                         'Committed revision 1.\n',
86
 
                         err)
 
78
        self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
 
79
                              'added hello.txt\n'
 
80
                              'Committed revision 1.\n$',)
87
81
 
88
82
    def prepare_simple_history(self):
89
83
        """Prepare and return a working tree with one commit of one file"""
100
94
        self.build_tree_contents([('hello.txt', 'new contents')])
101
95
        out, err = self.run_bzr('commit -m modified')
102
96
        self.assertEqual('', out)
103
 
        self.assertEqual('modified hello.txt\n'
104
 
                         'Committed revision 2.\n',
105
 
                         err)
 
97
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
98
                              'modified hello\.txt\n'
 
99
                              'Committed revision 2\.\n$')
106
100
 
107
101
    def test_verbose_commit_renamed(self):
108
102
        # Verbose commit of renamed file should say so
110
104
        wt.rename_one('hello.txt', 'gutentag.txt')
111
105
        out, err = self.run_bzr('commit -m renamed')
112
106
        self.assertEqual('', out)
113
 
        self.assertEqual('renamed hello.txt => gutentag.txt\n'
114
 
                         'Committed revision 2.\n',
115
 
                         err)
 
107
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
108
                              'renamed hello\.txt => gutentag\.txt\n'
 
109
                              'Committed revision 2\.$\n')
116
110
 
117
111
    def test_verbose_commit_moved(self):
118
112
        # Verbose commit of file moved to new directory should say so
122
116
        wt.rename_one('hello.txt', 'subdir/hello.txt')
123
117
        out, err = self.run_bzr('commit -m renamed')
124
118
        self.assertEqual('', out)
125
 
        self.assertEqualDiff('added subdir\n'
126
 
                             'renamed hello.txt => subdir/hello.txt\n'
127
 
                             'Committed revision 2.\n',
128
 
                             err)
 
119
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
120
                              'added subdir\n'
 
121
                              'renamed hello\.txt => subdir/hello\.txt\n'
 
122
                              'Committed revision 2\.\n$')
129
123
 
130
124
    def test_verbose_commit_with_unknown(self):
131
125
        """Unknown files should not be listed by default in verbose output"""
135
129
        wt.add(['hello.txt'])
136
130
        out,err = self.run_bzr('commit -m added')
137
131
        self.assertEqual('', out)
138
 
        self.assertEqual('added hello.txt\n'
139
 
                         'Committed revision 1.\n',
140
 
                         err)
 
132
        self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
 
133
                              'added hello\.txt\n'
 
134
                              'Committed revision 1\.\n$')
141
135
 
142
136
    def test_verbose_commit_with_unchanged(self):
143
137
        """Unchanged files should not be listed by default in verbose output"""
144
 
        self.run_bzr("init")
 
138
        tree = self.make_branch_and_tree('.')
145
139
        self.build_tree(['hello.txt', 'unchanged.txt'])
146
 
        self.run_bzr('add unchanged.txt')
 
140
        tree.add('unchanged.txt')
147
141
        self.run_bzr('commit -m unchanged unchanged.txt')
148
 
        self.run_bzr("add hello.txt")
 
142
        tree.add("hello.txt")
149
143
        out,err = self.run_bzr('commit -m added')
150
144
        self.assertEqual('', out)
151
 
        self.assertEqual('added hello.txt\n'
152
 
                         'Committed revision 2.\n',
153
 
                         err)
 
145
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
146
                              'added hello\.txt\n'
 
147
                              'Committed revision 2\.$\n')
 
148
 
 
149
    def test_verbose_commit_includes_master_location(self):
 
150
        """Location of master is displayed when committing to bound branch"""
 
151
        a_tree = self.make_branch_and_tree('a')
 
152
        self.build_tree(['a/b'])
 
153
        a_tree.add('b')
 
154
        a_tree.commit(message='Initial message')
 
155
 
 
156
        b_tree = a_tree.branch.create_checkout('b')
 
157
        expected = "%s/" % (os.path.abspath('a'), )
 
158
        out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
 
159
        self.assertEqual(err, 'Committing revision 2 to "%s".\n'
 
160
                         'Committed revision 2.\n' % expected)
154
161
 
155
162
    def test_commit_merge_reports_all_modified_files(self):
156
163
        # the commit command should show all the files that are shown by
189
196
            other_tree.rename_one('dirtorename', 'renameddir')
190
197
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
191
198
            other_tree.rename_one('filetorename', 'renamedfile')
192
 
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
199
            other_tree.rename_one('filetoreparent',
 
200
                                  'renameddir/reparentedfile')
193
201
            other_tree.remove(['dirtoremove', 'filetoremove'])
194
202
            self.build_tree_contents([
195
 
                ('other/newdir/', ),
 
203
                ('other/newdir/',),
196
204
                ('other/filetomodify', 'new content'),
197
205
                ('other/newfile', 'new file content')])
198
206
            other_tree.add('newfile')
203
211
        this_tree.merge_from_branch(other_tree.branch)
204
212
        os.chdir('this')
205
213
        out,err = self.run_bzr('commit -m added')
206
 
        os.chdir('..')
207
214
        self.assertEqual('', out)
 
215
        expected = '%s/' % (os.getcwd(), )
208
216
        self.assertEqualDiff(
 
217
            'Committing revision 2 to "%s".\n'
209
218
            'modified filetomodify\n'
210
219
            'added newdir\n'
211
220
            'added newfile\n'
215
224
            'renamed filetorename => renamedfile\n'
216
225
            'deleted dirtoremove\n'
217
226
            'deleted filetoremove\n'
218
 
            'Committed revision 2.\n',
 
227
            'Committed revision 2.\n' % (expected, ),
219
228
            err)
220
229
 
221
230
    def test_empty_commit_message(self):
222
 
        self.run_bzr("init")
223
 
        file('foo.c', 'wt').write('int main() {}')
224
 
        self.run_bzr('add foo.c')
 
231
        tree = self.make_branch_and_tree('.')
 
232
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
233
        tree.add('foo.c')
225
234
        self.run_bzr('commit -m ""', retcode=3)
226
235
 
 
236
    def test_unsupported_encoding_commit_message(self):
 
237
        tree = self.make_branch_and_tree('.')
 
238
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
239
        tree.add('foo.c')
 
240
        out,err = self.run_bzr_subprocess('commit -m "\xff"', retcode=1,
 
241
                                                    env_changes={'LANG': 'C'})
 
242
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
 
243
                                    'unsupported by the current encoding.')
 
244
 
227
245
    def test_other_branch_commit(self):
228
246
        # this branch is to ensure consistent behaviour, whether we're run
229
247
        # inside a branch, or not.
230
 
        os.mkdir('empty_branch')
231
 
        os.chdir('empty_branch')
232
 
        self.run_bzr('init')
233
 
        os.mkdir('branch')
234
 
        os.chdir('branch')
235
 
        self.run_bzr('init')
236
 
        file('foo.c', 'wt').write('int main() {}')
237
 
        file('bar.c', 'wt').write('int main() {}')
238
 
        os.chdir('..')
239
 
        self.run_bzr('add branch/foo.c')
240
 
        self.run_bzr('add branch')
 
248
        outer_tree = self.make_branch_and_tree('.')
 
249
        inner_tree = self.make_branch_and_tree('branch')
 
250
        self.build_tree_contents([
 
251
            ('branch/foo.c', 'int main() {}'),
 
252
            ('branch/bar.c', 'int main() {}')])
 
253
        inner_tree.add('foo.c')
 
254
        inner_tree.add('bar.c')
241
255
        # can't commit files in different trees; sane error
242
256
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
243
257
        self.run_bzr('commit -m newstuff branch/foo.c')
247
261
    def test_out_of_date_tree_commit(self):
248
262
        # check we get an error code and a clear message committing with an out
249
263
        # of date checkout
250
 
        self.make_branch_and_tree('branch')
 
264
        tree = self.make_branch_and_tree('branch')
251
265
        # make a checkout
252
 
        self.run_bzr('checkout --lightweight branch checkout')
 
266
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
253
267
        # commit to the original branch to make the checkout out of date
254
 
        self.run_bzr('commit --unchanged -m message branch')
 
268
        tree.commit('message branch', allow_pointless=True)
255
269
        # now commit to the checkout should emit
256
270
        # ERROR: Out of date with the branch, 'bzr update' is suggested
257
271
        output = self.run_bzr('commit --unchanged -m checkout_message '
258
272
                             'checkout', retcode=3)
259
273
        self.assertEqual(output,
260
274
                         ('',
261
 
                          "bzr: ERROR: Working tree is out of date, please run "
262
 
                          "'bzr update'.\n"))
 
275
                          "bzr: ERROR: Working tree is out of date, please "
 
276
                          "run 'bzr update'.\n"))
263
277
 
264
278
    def test_local_commit_unbound(self):
265
279
        # a --local commit on an unbound branch is an error
275
289
        # past. This is a user story reported to fail in bug #43959 where 
276
290
        # a merge done in a checkout (using the update command) failed to
277
291
        # commit correctly.
278
 
        self.run_bzr('init trunk')
 
292
        trunk = self.make_branch_and_tree('trunk')
279
293
 
280
 
        self.run_bzr('checkout trunk u1')
 
294
        u1 = trunk.branch.create_checkout('u1')
281
295
        self.build_tree_contents([('u1/hosts', 'initial contents')])
282
 
        self.run_bzr('add u1/hosts')
 
296
        u1.add('hosts')
283
297
        self.run_bzr('commit -m add-hosts u1')
284
298
 
285
 
        self.run_bzr('checkout trunk u2')
 
299
        u2 = trunk.branch.create_checkout('u2')
286
300
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
287
301
        self.run_bzr('commit -m checkin-from-u2 u2')
288
302
 
367
381
        output, err = self.run_bzr(
368
382
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
369
383
        self.assertEqual('', output)
370
 
        self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
 
384
        self.assertContainsRe(err, 'Committing revision 1 to ".*"\.\n'
 
385
                              'added hello\.txt\n'
 
386
                              'Committed revision 1\.\n')
371
387
 
372
388
    def test_no_bugs_no_properties(self):
373
389
        """If no bugs are fixed, the bugs property is not set.
470
486
             r"Commit refused\."],
471
487
            'commit -m add-b --fixes=orange',
472
488
            working_dir='tree')
 
489
 
 
490
    def test_no_author(self):
 
491
        """If the author is not specified, the author property is not set."""
 
492
        tree = self.make_branch_and_tree('tree')
 
493
        self.build_tree(['tree/hello.txt'])
 
494
        tree.add('hello.txt')
 
495
        self.run_bzr( 'commit -m hello tree/hello.txt')
 
496
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
497
        properties = last_rev.properties
 
498
        self.assertFalse('author' in properties)
 
499
 
 
500
    def test_author_sets_property(self):
 
501
        """commit --author='John Doe <jdoe@example.com>' sets the author
 
502
           revprop.
 
503
        """
 
504
        tree = self.make_branch_and_tree('tree')
 
505
        self.build_tree(['tree/hello.txt'])
 
506
        tree.add('hello.txt')
 
507
        self.run_bzr("commit -m hello --author='John Doe <jdoe@example.com>' "
 
508
                     "tree/hello.txt")
 
509
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
510
        properties = last_rev.properties
 
511
        self.assertEqual('John Doe <jdoe@example.com>', properties['author'])
 
512
 
 
513
    def test_author_no_email(self):
 
514
        """Author's name without an email address is allowed, too."""
 
515
        tree = self.make_branch_and_tree('tree')
 
516
        self.build_tree(['tree/hello.txt'])
 
517
        tree.add('hello.txt')
 
518
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
 
519
                                "tree/hello.txt")
 
520
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
 
521
        properties = last_rev.properties
 
522
        self.assertEqual('John Doe', properties['author'])