/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

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
18
18
"""Tests for the commit CLI of bzr."""
19
19
 
20
20
import os
21
 
import re
22
21
import sys
23
22
 
 
23
import bzrlib
24
24
from bzrlib import (
 
25
    osutils,
25
26
    ignores,
 
27
    osutils,
26
28
    )
27
 
from bzrlib.branch import Branch
28
29
from bzrlib.bzrdir import BzrDir
29
 
from bzrlib.errors import BzrCommandError
 
30
from bzrlib.tests import (
 
31
    probe_bad_non_ascii,
 
32
    TestSkipped,
 
33
    )
30
34
from bzrlib.tests.blackbox import ExternalBase
31
 
from bzrlib.workingtree import WorkingTree
32
35
 
33
36
 
34
37
class TestCommit(ExternalBase):
36
39
    def test_05_empty_commit(self):
37
40
        """Commit of tree with no versioned files should fail"""
38
41
        # If forced, it should succeed, but this is not tested here.
39
 
        self.run_bzr("init")
 
42
        self.make_branch_and_tree('.')
40
43
        self.build_tree(['hello.txt'])
41
44
        out,err = self.run_bzr('commit -m empty', retcode=3)
42
45
        self.assertEqual('', out)
43
 
        self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
 
46
        self.assertContainsRe(err, 'bzr: ERROR: no changes to commit\.'
44
47
                                  ' use --unchanged to commit anyhow\n')
45
48
 
46
49
    def test_commit_success(self):
47
50
        """Successful commit should not leave behind a bzr-commit-* file"""
48
 
        self.run_bzr("init")
 
51
        self.make_branch_and_tree('.')
49
52
        self.run_bzr('commit --unchanged -m message')
50
53
        self.assertEqual('', self.run_bzr('unknowns')[0])
51
54
 
55
58
 
56
59
    def test_commit_with_path(self):
57
60
        """Commit tree with path of root specified"""
58
 
        self.run_bzr('init a')
 
61
        a_tree = self.make_branch_and_tree('a')
59
62
        self.build_tree(['a/a_file'])
60
 
        self.run_bzr('add a/a_file')
 
63
        a_tree.add('a_file')
61
64
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
62
65
 
63
 
        self.run_bzr('branch a b')
 
66
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
64
67
        self.build_tree_contents([('b/a_file', 'changes in b')])
65
68
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
66
69
 
67
70
        self.build_tree_contents([('a/a_file', 'new contents')])
68
71
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
69
72
 
70
 
        os.chdir('b')
71
 
        self.run_bzr('merge ../a', retcode=1) # will conflict
72
 
        os.chdir('..')
 
73
        b_tree.merge_from_branch(a_tree.branch)
 
74
        self.assertEqual(len(b_tree.conflicts()), 1)
73
75
        self.run_bzr('resolved b/a_file')
74
76
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
75
77
 
76
78
 
77
79
    def test_10_verbose_commit(self):
78
80
        """Add one file and examine verbose commit output"""
79
 
        self.run_bzr("init")
 
81
        tree = self.make_branch_and_tree('.')
80
82
        self.build_tree(['hello.txt'])
81
 
        self.run_bzr("add hello.txt")
 
83
        tree.add("hello.txt")
82
84
        out,err = self.run_bzr('commit -m added')
83
85
        self.assertEqual('', out)
84
 
        self.assertEqual('added hello.txt\n'
85
 
                         'Committed revision 1.\n',
86
 
                         err)
 
86
        self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
 
87
                              'added hello.txt\n'
 
88
                              'Committed revision 1.\n$',)
87
89
 
88
90
    def prepare_simple_history(self):
89
91
        """Prepare and return a working tree with one commit of one file"""
100
102
        self.build_tree_contents([('hello.txt', 'new contents')])
101
103
        out, err = self.run_bzr('commit -m modified')
102
104
        self.assertEqual('', out)
103
 
        self.assertEqual('modified hello.txt\n'
104
 
                         'Committed revision 2.\n',
105
 
                         err)
 
105
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
106
                              'modified hello\.txt\n'
 
107
                              'Committed revision 2\.\n$')
106
108
 
107
109
    def test_verbose_commit_renamed(self):
108
110
        # Verbose commit of renamed file should say so
110
112
        wt.rename_one('hello.txt', 'gutentag.txt')
111
113
        out, err = self.run_bzr('commit -m renamed')
112
114
        self.assertEqual('', out)
113
 
        self.assertEqual('renamed hello.txt => gutentag.txt\n'
114
 
                         'Committed revision 2.\n',
115
 
                         err)
 
115
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
116
                              'renamed hello\.txt => gutentag\.txt\n'
 
117
                              'Committed revision 2\.$\n')
116
118
 
117
119
    def test_verbose_commit_moved(self):
118
120
        # Verbose commit of file moved to new directory should say so
122
124
        wt.rename_one('hello.txt', 'subdir/hello.txt')
123
125
        out, err = self.run_bzr('commit -m renamed')
124
126
        self.assertEqual('', out)
125
 
        self.assertEqualDiff('added subdir\n'
126
 
                             'renamed hello.txt => subdir/hello.txt\n'
127
 
                             'Committed revision 2.\n',
128
 
                             err)
 
127
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
128
                              'added subdir\n'
 
129
                              'renamed hello\.txt => subdir/hello\.txt\n'
 
130
                              'Committed revision 2\.\n$')
129
131
 
130
132
    def test_verbose_commit_with_unknown(self):
131
133
        """Unknown files should not be listed by default in verbose output"""
135
137
        wt.add(['hello.txt'])
136
138
        out,err = self.run_bzr('commit -m added')
137
139
        self.assertEqual('', out)
138
 
        self.assertEqual('added hello.txt\n'
139
 
                         'Committed revision 1.\n',
140
 
                         err)
 
140
        self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
 
141
                              'added hello\.txt\n'
 
142
                              'Committed revision 1\.\n$')
141
143
 
142
144
    def test_verbose_commit_with_unchanged(self):
143
145
        """Unchanged files should not be listed by default in verbose output"""
144
 
        self.run_bzr("init")
 
146
        tree = self.make_branch_and_tree('.')
145
147
        self.build_tree(['hello.txt', 'unchanged.txt'])
146
 
        self.run_bzr('add unchanged.txt')
 
148
        tree.add('unchanged.txt')
147
149
        self.run_bzr('commit -m unchanged unchanged.txt')
148
 
        self.run_bzr("add hello.txt")
 
150
        tree.add("hello.txt")
149
151
        out,err = self.run_bzr('commit -m added')
150
152
        self.assertEqual('', out)
151
 
        self.assertEqual('added hello.txt\n'
152
 
                         'Committed revision 2.\n',
153
 
                         err)
 
153
        self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
 
154
                              'added hello\.txt\n'
 
155
                              'Committed revision 2\.$\n')
 
156
 
 
157
    def test_verbose_commit_includes_master_location(self):
 
158
        """Location of master is displayed when committing to bound branch"""
 
159
        a_tree = self.make_branch_and_tree('a')
 
160
        self.build_tree(['a/b'])
 
161
        a_tree.add('b')
 
162
        a_tree.commit(message='Initial message')
 
163
 
 
164
        b_tree = a_tree.branch.create_checkout('b')
 
165
        expected = "%s/" % (osutils.abspath('a'), )
 
166
        out, err = self.run_bzr('commit -m blah --unchanged', working_dir='b')
 
167
        self.assertEqual(err, 'Committing revision 2 to "%s".\n'
 
168
                         'Committed revision 2.\n' % expected)
154
169
 
155
170
    def test_commit_merge_reports_all_modified_files(self):
156
171
        # the commit command should show all the files that are shown by
189
204
            other_tree.rename_one('dirtorename', 'renameddir')
190
205
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
191
206
            other_tree.rename_one('filetorename', 'renamedfile')
192
 
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
 
207
            other_tree.rename_one('filetoreparent',
 
208
                                  'renameddir/reparentedfile')
193
209
            other_tree.remove(['dirtoremove', 'filetoremove'])
194
210
            self.build_tree_contents([
195
 
                ('other/newdir/', ),
 
211
                ('other/newdir/',),
196
212
                ('other/filetomodify', 'new content'),
197
213
                ('other/newfile', 'new file content')])
198
214
            other_tree.add('newfile')
203
219
        this_tree.merge_from_branch(other_tree.branch)
204
220
        os.chdir('this')
205
221
        out,err = self.run_bzr('commit -m added')
206
 
        os.chdir('..')
207
222
        self.assertEqual('', out)
 
223
        expected = '%s/' % (osutils.getcwd(), )
208
224
        self.assertEqualDiff(
 
225
            'Committing revision 2 to "%s".\n'
209
226
            'modified filetomodify\n'
210
227
            'added newdir\n'
211
228
            'added newfile\n'
212
229
            'renamed dirtorename => renameddir\n'
 
230
            'renamed filetorename => renamedfile\n'
213
231
            'renamed dirtoreparent => renameddir/reparenteddir\n'
214
232
            'renamed filetoreparent => renameddir/reparentedfile\n'
215
 
            'renamed filetorename => renamedfile\n'
216
233
            'deleted dirtoremove\n'
217
234
            'deleted filetoremove\n'
218
 
            'Committed revision 2.\n',
 
235
            'Committed revision 2.\n' % (expected, ),
219
236
            err)
220
237
 
221
238
    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')
 
239
        tree = self.make_branch_and_tree('.')
 
240
        self.build_tree_contents([('foo.c', 'int main() {}')])
 
241
        tree.add('foo.c')
225
242
        self.run_bzr('commit -m ""', retcode=3)
226
243
 
227
244
    def test_unsupported_encoding_commit_message(self):
228
245
        tree = self.make_branch_and_tree('.')
229
246
        self.build_tree_contents([('foo.c', 'int main() {}')])
230
247
        tree.add('foo.c')
231
 
        out,err = self.run_bzr_subprocess('commit -m "\xff"', retcode=1,
232
 
                                                    env_changes={'LANG': 'C'})
 
248
        # LANG env variable has no effect on Windows
 
249
        # but some characters anyway cannot be represented
 
250
        # in default user encoding
 
251
        char = probe_bad_non_ascii(bzrlib.user_encoding)
 
252
        if char is None:
 
253
            raise TestSkipped('Cannot find suitable non-ascii character'
 
254
                'for user_encoding (%s)' % bzrlib.user_encoding)
 
255
        out,err = self.run_bzr_subprocess('commit -m "%s"' % char,
 
256
                                          retcode=1,
 
257
                                          env_changes={'LANG': 'C'})
233
258
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
234
259
                                    'unsupported by the current encoding.')
235
260
 
236
261
    def test_other_branch_commit(self):
237
262
        # this branch is to ensure consistent behaviour, whether we're run
238
263
        # inside a branch, or not.
239
 
        os.mkdir('empty_branch')
240
 
        os.chdir('empty_branch')
241
 
        self.run_bzr('init')
242
 
        os.mkdir('branch')
243
 
        os.chdir('branch')
244
 
        self.run_bzr('init')
245
 
        file('foo.c', 'wt').write('int main() {}')
246
 
        file('bar.c', 'wt').write('int main() {}')
247
 
        os.chdir('..')
248
 
        self.run_bzr('add branch/foo.c')
249
 
        self.run_bzr('add branch')
 
264
        outer_tree = self.make_branch_and_tree('.')
 
265
        inner_tree = self.make_branch_and_tree('branch')
 
266
        self.build_tree_contents([
 
267
            ('branch/foo.c', 'int main() {}'),
 
268
            ('branch/bar.c', 'int main() {}')])
 
269
        inner_tree.add('foo.c')
 
270
        inner_tree.add('bar.c')
250
271
        # can't commit files in different trees; sane error
251
272
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
252
273
        self.run_bzr('commit -m newstuff branch/foo.c')
256
277
    def test_out_of_date_tree_commit(self):
257
278
        # check we get an error code and a clear message committing with an out
258
279
        # of date checkout
259
 
        self.make_branch_and_tree('branch')
 
280
        tree = self.make_branch_and_tree('branch')
260
281
        # make a checkout
261
 
        self.run_bzr('checkout --lightweight branch checkout')
 
282
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
262
283
        # commit to the original branch to make the checkout out of date
263
 
        self.run_bzr('commit --unchanged -m message branch')
 
284
        tree.commit('message branch', allow_pointless=True)
264
285
        # now commit to the checkout should emit
265
286
        # ERROR: Out of date with the branch, 'bzr update' is suggested
266
287
        output = self.run_bzr('commit --unchanged -m checkout_message '
267
288
                             'checkout', retcode=3)
268
289
        self.assertEqual(output,
269
290
                         ('',
270
 
                          "bzr: ERROR: Working tree is out of date, please run "
271
 
                          "'bzr update'.\n"))
 
291
                          "bzr: ERROR: Working tree is out of date, please "
 
292
                          "run 'bzr update'.\n"))
272
293
 
273
294
    def test_local_commit_unbound(self):
274
295
        # a --local commit on an unbound branch is an error
284
305
        # past. This is a user story reported to fail in bug #43959 where 
285
306
        # a merge done in a checkout (using the update command) failed to
286
307
        # commit correctly.
287
 
        self.run_bzr('init trunk')
 
308
        trunk = self.make_branch_and_tree('trunk')
288
309
 
289
 
        self.run_bzr('checkout trunk u1')
 
310
        u1 = trunk.branch.create_checkout('u1')
290
311
        self.build_tree_contents([('u1/hosts', 'initial contents')])
291
 
        self.run_bzr('add u1/hosts')
 
312
        u1.add('hosts')
292
313
        self.run_bzr('commit -m add-hosts u1')
293
314
 
294
 
        self.run_bzr('checkout trunk u2')
 
315
        u2 = trunk.branch.create_checkout('u2')
295
316
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
296
317
        self.run_bzr('commit -m checkin-from-u2 u2')
297
318
 
376
397
        output, err = self.run_bzr(
377
398
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
378
399
        self.assertEqual('', output)
379
 
        self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
 
400
        self.assertContainsRe(err, 'Committing revision 1 to ".*"\.\n'
 
401
                              'added hello\.txt\n'
 
402
                              'Committed revision 1\.\n')
380
403
 
381
404
    def test_no_bugs_no_properties(self):
382
405
        """If no bugs are fixed, the bugs property is not set.
513
536
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
514
537
        properties = last_rev.properties
515
538
        self.assertEqual('John Doe', properties['author'])
 
539
 
 
540
    def test_partial_commit_with_renames_in_tree(self):
 
541
        # this test illustrates bug #140419
 
542
        t = self.make_branch_and_tree('.')
 
543
        self.build_tree(['dir/', 'dir/a', 'test'])
 
544
        t.add(['dir/', 'dir/a', 'test'])
 
545
        t.commit('initial commit')
 
546
        # important part: file dir/a should change parent
 
547
        # and should appear before old parent
 
548
        # then during partial commit we have error
 
549
        # parent_id {dir-XXX} not in inventory
 
550
        t.rename_one('dir/a', 'a')
 
551
        self.build_tree_contents([('test', 'changes in test')])
 
552
        # partial commit
 
553
        out, err = self.run_bzr('commit test -m "partial commit"')
 
554
        self.assertEquals('', out)
 
555
        self.assertContainsRe(err, r'modified test\nCommitted revision 2.')
 
556
 
 
557
    def test_commit_readonly_checkout(self):
 
558
        # https://bugs.edge.launchpad.net/bzr/+bug/129701
 
559
        # "UnlockableTransport error trying to commit in checkout of readonly
 
560
        # branch"
 
561
        self.make_branch('master')
 
562
        master = BzrDir.open_from_transport(
 
563
            self.get_readonly_transport('master')).open_branch()
 
564
        master.create_checkout('checkout')
 
565
        out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
 
566
            retcode=3)
 
567
        self.assertContainsRe(err,
 
568
            r'^bzr: ERROR: Cannot lock.*readonly transport')