/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005, 2006 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
13
# You should have received a copy of the GNU General Public License
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
16
17
18
"""Tests for the commit CLI of bzr."""
19
20
import os
21
import re
22
import sys
23
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
24
from bzrlib import (
25
    ignores,
26
    )
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
27
from bzrlib.branch import Branch
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
28
from bzrlib.bzrdir import BzrDir
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
29
from bzrlib.errors import BzrCommandError
30
from bzrlib.tests.blackbox import ExternalBase
31
from bzrlib.workingtree import WorkingTree
32
33
34
class TestCommit(ExternalBase):
35
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
36
    def test_05_empty_commit(self):
37
        """Commit of tree with no versioned files should fail"""
38
        # If forced, it should succeed, but this is not tested here.
1711.2.60 by John Arbash Meinel
Fix an empty commit to raise the right exception.
39
        self.run_bzr("init")
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
40
        self.build_tree(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
41
        out,err = self.run_bzr('commit -m empty', retcode=3)
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
42
        self.assertEqual('', out)
43
        self.assertStartsWith(err, 'bzr: ERROR: no changes to commit.'
44
                                  ' use --unchanged to commit anyhow\n')
45
46
    def test_commit_success(self):
47
        """Successful commit should not leave behind a bzr-commit-* file"""
48
        self.run_bzr("init")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
49
        self.run_bzr('commit --unchanged -m message')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
50
        self.assertEqual('', self.run_bzr('unknowns')[0])
2089.1.1 by wang
If a commit fails, the commit message is stored in a file at the root of
51
52
        # same for unicode messages
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
53
        self.run_bzr(["commit", "--unchanged", "-m", u'foo\xb5'])
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
54
        self.assertEqual('', self.run_bzr('unknowns')[0])
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
55
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
56
    def test_commit_with_path(self):
57
        """Commit tree with path of root specified"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
58
        self.run_bzr('init a')
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
59
        self.build_tree(['a/a_file'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
60
        self.run_bzr('add a/a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
61
        self.run_bzr(['commit', '-m', 'first commit', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
62
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
63
        self.run_bzr('branch a b')
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
64
        self.build_tree_contents([('b/a_file', 'changes in b')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
65
        self.run_bzr(['commit', '-m', 'first commit in b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
66
67
        self.build_tree_contents([('a/a_file', 'new contents')])
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
68
        self.run_bzr(['commit', '-m', 'change in a', 'a'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
69
70
        os.chdir('b')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
71
        self.run_bzr('merge ../a', retcode=1) # will conflict
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
72
        os.chdir('..')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
73
        self.run_bzr('resolved b/a_file')
2552.2.5 by Vincent Ladeuil
Revert the intrusive run_bzr('commit') rewritings.
74
        self.run_bzr(['commit', '-m', 'merge into b', 'b'])
1704.2.11 by Martin Pool
Handle 'bzr commit DIR' when dir contains pending merges.
75
76
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
77
    def test_10_verbose_commit(self):
78
        """Add one file and examine verbose commit output"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
79
        self.run_bzr("init")
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
80
        self.build_tree(['hello.txt'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
81
        self.run_bzr("add hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
82
        out,err = self.run_bzr('commit -m added')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
83
        self.assertEqual('', out)
84
        self.assertEqual('added hello.txt\n'
85
                         'Committed revision 1.\n',
86
                         err)
87
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
88
    def prepare_simple_history(self):
89
        """Prepare and return a working tree with one commit of one file"""
90
        # Commit with modified file should say so
91
        wt = BzrDir.create_standalone_workingtree('.')
92
        self.build_tree(['hello.txt', 'extra.txt'])
93
        wt.add(['hello.txt'])
94
        wt.commit(message='added')
95
        return wt
96
97
    def test_verbose_commit_modified(self):
98
        # Verbose commit of modified file should say so
99
        wt = self.prepare_simple_history()
100
        self.build_tree_contents([('hello.txt', 'new contents')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
101
        out, err = self.run_bzr('commit -m modified')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
102
        self.assertEqual('', out)
103
        self.assertEqual('modified hello.txt\n'
104
                         'Committed revision 2.\n',
105
                         err)
106
107
    def test_verbose_commit_renamed(self):
108
        # Verbose commit of renamed file should say so
109
        wt = self.prepare_simple_history()
110
        wt.rename_one('hello.txt', 'gutentag.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
111
        out, err = self.run_bzr('commit -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
112
        self.assertEqual('', out)
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
113
        self.assertEqual('renamed hello.txt => gutentag.txt\n'
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
114
                         'Committed revision 2.\n',
115
                         err)
116
117
    def test_verbose_commit_moved(self):
118
        # Verbose commit of file moved to new directory should say so
119
        wt = self.prepare_simple_history()
120
        os.mkdir('subdir')
121
        wt.add(['subdir'])
122
        wt.rename_one('hello.txt', 'subdir/hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
123
        out, err = self.run_bzr('commit -m renamed')
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
124
        self.assertEqual('', out)
125
        self.assertEqualDiff('added subdir\n'
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
126
                             'renamed hello.txt => subdir/hello.txt\n'
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
127
                             'Committed revision 2.\n',
128
                             err)
129
130
    def test_verbose_commit_with_unknown(self):
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
131
        """Unknown files should not be listed by default in verbose output"""
132
        # Is that really the best policy?
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
133
        wt = BzrDir.create_standalone_workingtree('.')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
134
        self.build_tree(['hello.txt', 'extra.txt'])
1669.2.1 by Martin Pool
verbose commit now specifically identifies modified/renamed/reparented files
135
        wt.add(['hello.txt'])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
136
        out,err = self.run_bzr('commit -m added')
1616.1.3 by Martin Pool
Clean up cut&pasted test for verbose commit
137
        self.assertEqual('', out)
138
        self.assertEqual('added hello.txt\n'
139
                         'Committed revision 1.\n',
140
                         err)
141
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
142
    def test_verbose_commit_with_unchanged(self):
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
143
        """Unchanged files should not be listed by default in verbose output"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
144
        self.run_bzr("init")
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
145
        self.build_tree(['hello.txt', 'unchanged.txt'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
146
        self.run_bzr('add unchanged.txt')
147
        self.run_bzr('commit -m unchanged unchanged.txt')
148
        self.run_bzr("add hello.txt")
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
149
        out,err = self.run_bzr('commit -m added')
1616.1.4 by Martin Pool
Verbose commit shouldn't talk about every unchanged file.
150
        self.assertEqual('', out)
151
        self.assertEqual('added hello.txt\n'
152
                         'Committed revision 2.\n',
153
                         err)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
154
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
155
    def test_commit_merge_reports_all_modified_files(self):
156
        # the commit command should show all the files that are shown by
157
        # bzr diff or bzr status when committing, even when they were not
158
        # changed by the user but rather through doing a merge.
159
        this_tree = self.make_branch_and_tree('this')
160
        # we need a bunch of files and dirs, to perform one action on each.
161
        self.build_tree([
162
            'this/dirtorename/',
163
            'this/dirtoreparent/',
164
            'this/dirtoleave/',
165
            'this/dirtoremove/',
166
            'this/filetoreparent',
167
            'this/filetorename',
168
            'this/filetomodify',
169
            'this/filetoremove',
170
            'this/filetoleave']
171
            )
172
        this_tree.add([
173
            'dirtorename',
174
            'dirtoreparent',
175
            'dirtoleave',
176
            'dirtoremove',
177
            'filetoreparent',
178
            'filetorename',
179
            'filetomodify',
180
            'filetoremove',
181
            'filetoleave']
182
            )
183
        this_tree.commit('create_files')
184
        other_dir = this_tree.bzrdir.sprout('other')
185
        other_tree = other_dir.open_workingtree()
186
        other_tree.lock_write()
187
        # perform the needed actions on the files and dirs.
188
        try:
189
            other_tree.rename_one('dirtorename', 'renameddir')
190
            other_tree.rename_one('dirtoreparent', 'renameddir/reparenteddir')
191
            other_tree.rename_one('filetorename', 'renamedfile')
192
            other_tree.rename_one('filetoreparent', 'renameddir/reparentedfile')
193
            other_tree.remove(['dirtoremove', 'filetoremove'])
194
            self.build_tree_contents([
195
                ('other/newdir/', ),
196
                ('other/filetomodify', 'new content'),
197
                ('other/newfile', 'new file content')])
198
            other_tree.add('newfile')
199
            other_tree.add('newdir/')
200
            other_tree.commit('modify all sample files and dirs.')
201
        finally:
202
            other_tree.unlock()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
203
        this_tree.merge_from_branch(other_tree.branch)
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
204
        os.chdir('this')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
205
        out,err = self.run_bzr('commit -m added')
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
206
        os.chdir('..')
207
        self.assertEqual('', out)
208
        self.assertEqualDiff(
209
            'modified filetomodify\n'
210
            'added newdir\n'
211
            'added newfile\n'
212
            'renamed dirtorename => renameddir\n'
213
            'renamed dirtoreparent => renameddir/reparenteddir\n'
214
            'renamed filetoreparent => renameddir/reparentedfile\n'
2484.1.25 by John Arbash Meinel
[merge] bzr.dev 2612
215
            'renamed filetorename => renamedfile\n'
1668.1.5 by Martin Pool
[broken] fix up display of files changed by a commit
216
            'deleted dirtoremove\n'
217
            'deleted filetoremove\n'
218
            'Committed revision 2.\n',
219
            err)
220
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
221
    def test_empty_commit_message(self):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
222
        self.run_bzr("init")
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
223
        file('foo.c', 'wt').write('int main() {}')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
224
        self.run_bzr('add foo.c')
225
        self.run_bzr('commit -m ""', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
226
2625.9.2 by Daniel Watkins
Added test to ensure correct error message is given if an unencodable commit message is given at the command line.
227
    def test_unsupported_encoding_commit_message(self):
228
        tree = self.make_branch_and_tree('.')
229
        self.build_tree_contents([('foo.c', 'int main() {}')])
230
        tree.add('foo.c')
231
        out,err = self.run_bzr_subprocess('commit -m "\xff"', retcode=1,
232
                                                    env_changes={'LANG': 'C'})
233
        self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
234
                                    'unsupported by the current encoding.')
235
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
236
    def test_other_branch_commit(self):
237
        # this branch is to ensure consistent behaviour, whether we're run
238
        # inside a branch, or not.
239
        os.mkdir('empty_branch')
240
        os.chdir('empty_branch')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
241
        self.run_bzr('init')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
242
        os.mkdir('branch')
243
        os.chdir('branch')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
244
        self.run_bzr('init')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
245
        file('foo.c', 'wt').write('int main() {}')
246
        file('bar.c', 'wt').write('int main() {}')
247
        os.chdir('..')
2552.2.2 by Vincent Ladeuil
Enforce run_bzr(string) where possible.
248
        self.run_bzr('add branch/foo.c')
249
        self.run_bzr('add branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
250
        # can't commit files in different trees; sane error
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
251
        self.run_bzr('commit -m newstuff branch/foo.c .', retcode=3)
252
        self.run_bzr('commit -m newstuff branch/foo.c')
253
        self.run_bzr('commit -m newstuff branch')
254
        self.run_bzr('commit -m newstuff branch', retcode=3)
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
255
256
    def test_out_of_date_tree_commit(self):
257
        # check we get an error code and a clear message committing with an out
258
        # of date checkout
259
        self.make_branch_and_tree('branch')
260
        # make a checkout
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
261
        self.run_bzr('checkout --lightweight branch checkout')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
262
        # commit to the original branch to make the checkout out of date
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
263
        self.run_bzr('commit --unchanged -m message branch')
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
264
        # now commit to the checkout should emit
265
        # ERROR: Out of date with the branch, 'bzr update' is suggested
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
266
        output = self.run_bzr('commit --unchanged -m checkout_message '
1508.1.22 by Robert Collins
implement out of date working tree checks in commit.
267
                             'checkout', retcode=3)
268
        self.assertEqual(output,
269
                         ('',
270
                          "bzr: ERROR: Working tree is out of date, please run "
271
                          "'bzr update'.\n"))
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
272
273
    def test_local_commit_unbound(self):
274
        # a --local commit on an unbound branch is an error
275
        self.make_branch_and_tree('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
276
        out, err = self.run_bzr('commit --local', retcode=3)
1587.1.8 by Robert Collins
Local commits on unbound branches fail.
277
        self.assertEqualDiff('', out)
278
        self.assertEqualDiff('bzr: ERROR: Cannot perform local-only commits '
279
                             'on unbound branches.\n', err)
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
280
281
    def test_commit_a_text_merge_in_a_checkout(self):
282
        # checkouts perform multiple actions in a transaction across bond
283
        # branches and their master, and have been observed to fail in the
284
        # past. This is a user story reported to fail in bug #43959 where 
285
        # a merge done in a checkout (using the update command) failed to
286
        # commit correctly.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
287
        self.run_bzr('init trunk')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
288
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
289
        self.run_bzr('checkout trunk u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
290
        self.build_tree_contents([('u1/hosts', 'initial contents')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
291
        self.run_bzr('add u1/hosts')
292
        self.run_bzr('commit -m add-hosts u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
293
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
294
        self.run_bzr('checkout trunk u2')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
295
        self.build_tree_contents([('u2/hosts', 'altered in u2')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
296
        self.run_bzr('commit -m checkin-from-u2 u2')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
297
298
        # make an offline commits
299
        self.build_tree_contents([('u1/hosts', 'first offline change in u1')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
300
        self.run_bzr('commit -m checkin-offline --local u1')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
301
302
        # now try to pull in online work from u2, and then commit our offline
303
        # work as a merge
304
        # retcode 1 as we expect a text conflict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
305
        self.run_bzr('update u1', retcode=1)
306
        self.run_bzr('resolved u1/hosts')
1668.1.3 by Martin Pool
[patch] use the correct transaction when committing snapshot (Malone: #43959)
307
        # add a text change here to represent resolving the merge conflicts in
308
        # favour of a new version of the file not identical to either the u1
309
        # version or the u2 version.
310
        self.build_tree_contents([('u1/hosts', 'merge resolution\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
311
        self.run_bzr('commit -m checkin-merge-of-the-offline-work-from-u1 u1')
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
312
313
    def test_commit_respects_spec_for_removals(self):
314
        """Commit with a file spec should only commit removals that match"""
315
        t = self.make_branch_and_tree('.')
316
        self.build_tree(['file-a', 'dir-a/', 'dir-a/file-b'])
317
        t.add(['file-a', 'dir-a', 'dir-a/file-b'])
318
        t.commit('Create')
319
        t.remove(['file-a', 'dir-a/file-b'])
320
        os.chdir('dir-a')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
321
        result = self.run_bzr('commit . -m removed-file-b')[1]
1551.7.24 by Aaron Bentley
Ensure commit respects file spec when committing removals
322
        self.assertNotContainsRe(result, 'file-a')
323
        result = self.run_bzr('status')[0]
324
        self.assertContainsRe(result, 'removed:\n  file-a')
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
325
326
    def test_strict_commit(self):
327
        """Commit with --strict works if everything is known"""
1551.9.5 by Aaron Bentley
Revert broken save-commit-message code
328
        ignores._set_user_ignores([])
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
329
        tree = self.make_branch_and_tree('tree')
330
        self.build_tree(['tree/a'])
331
        tree.add('a')
332
        # A simple change should just work
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
333
        self.run_bzr('commit --strict -m adding-a',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
334
                     working_dir='tree')
335
336
    def test_strict_commit_no_changes(self):
337
        """commit --strict gives "no changes" if there is nothing to commit"""
338
        tree = self.make_branch_and_tree('tree')
339
        self.build_tree(['tree/a'])
340
        tree.add('a')
341
        tree.commit('adding a')
342
343
        # With no changes, it should just be 'no changes'
344
        # Make sure that commit is failing because there is nothing to do
345
        self.run_bzr_error(['no changes to commit'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
346
                           'commit --strict -m no-changes',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
347
                           working_dir='tree')
348
349
        # But --strict doesn't care if you supply --unchanged
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
350
        self.run_bzr('commit --strict --unchanged -m no-changes',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
351
                     working_dir='tree')
352
353
    def test_strict_commit_unknown(self):
354
        """commit --strict fails if a file is unknown"""
355
        tree = self.make_branch_and_tree('tree')
356
        self.build_tree(['tree/a'])
357
        tree.add('a')
358
        tree.commit('adding a')
359
360
        # Add one file so there is a change, but forget the other
361
        self.build_tree(['tree/b', 'tree/c'])
362
        tree.add('b')
363
        self.run_bzr_error(['Commit refused because there are unknown files'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
364
                           'commit --strict -m add-b',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
365
                           working_dir='tree')
366
367
        # --no-strict overrides --strict
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
368
        self.run_bzr('commit --strict -m add-b --no-strict',
2116.2.1 by John Arbash Meinel
Add commit --strict tests, and add a default ignore so that commit --strict works again
369
                     working_dir='tree')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
370
371
    def test_fixes_bug_output(self):
372
        """commit --fixes=lp:23452 succeeds without output."""
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
373
        tree = self.make_branch_and_tree('tree')
374
        self.build_tree(['tree/hello.txt'])
375
        tree.add('hello.txt')
2376.4.12 by Jonathan Lange
Update NEWS file.
376
        output, err = self.run_bzr(
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
377
            'commit -m hello --fixes=lp:23452 tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
378
        self.assertEqual('', output)
2376.4.12 by Jonathan Lange
Update NEWS file.
379
        self.assertEqual('added hello.txt\nCommitted revision 1.\n', err)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
380
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
381
    def test_no_bugs_no_properties(self):
382
        """If no bugs are fixed, the bugs property is not set.
383
384
        see https://beta.launchpad.net/bzr/+bug/109613
385
        """
386
        tree = self.make_branch_and_tree('tree')
387
        self.build_tree(['tree/hello.txt'])
388
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
389
        self.run_bzr( 'commit -m hello tree/hello.txt')
2453.2.1 by Martin Pool
Don't set the bugs property unless bugs are actually set
390
        # Get the revision properties, ignoring the branch-nick property, which
391
        # we don't care about for this test.
392
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
393
        properties = dict(last_rev.properties)
394
        del properties['branch-nick']
395
        self.assertFalse('bugs' in properties)
396
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
397
    def test_fixes_bug_sets_property(self):
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
398
        """commit --fixes=lp:234 sets the lp:234 revprop to 'fixed'."""
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
399
        tree = self.make_branch_and_tree('tree')
400
        self.build_tree(['tree/hello.txt'])
401
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
402
        self.run_bzr('commit -m hello --fixes=lp:234 tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
403
404
        # Get the revision properties, ignoring the branch-nick property, which
405
        # we don't care about for this test.
406
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
407
        properties = dict(last_rev.properties)
408
        del properties['branch-nick']
409
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
410
        self.assertEqual({'bugs': 'https://launchpad.net/bugs/234 fixed'},
2376.4.7 by jml at canonical
- Add docstrings to tests.
411
                         properties)
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
412
413
    def test_fixes_multiple_bugs_sets_properties(self):
414
        """--fixes can be used more than once to show that bugs are fixed."""
415
        tree = self.make_branch_and_tree('tree')
416
        self.build_tree(['tree/hello.txt'])
417
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
418
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=lp:235'
419
                     ' tree/hello.txt')
2376.4.1 by jml at canonical
Blackbox-driven --fixes option to commit.
420
421
        # Get the revision properties, ignoring the branch-nick property, which
422
        # we don't care about for this test.
423
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
424
        properties = dict(last_rev.properties)
425
        del properties['branch-nick']
426
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
427
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
428
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
429
                     'https://launchpad.net/bugs/235 fixed'},
430
            properties)
2376.4.7 by jml at canonical
- Add docstrings to tests.
431
432
    def test_fixes_bug_with_alternate_trackers(self):
433
        """--fixes can be used on a properly configured branch to mark bug
434
        fixes on multiple trackers.
435
        """
436
        tree = self.make_branch_and_tree('tree')
437
        tree.branch.get_config().set_user_option(
438
            'trac_twisted_url', 'http://twistedmatrix.com/trac')
439
        self.build_tree(['tree/hello.txt'])
440
        tree.add('hello.txt')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
441
        self.run_bzr('commit -m hello --fixes=lp:123 --fixes=twisted:235 tree/')
2376.4.7 by jml at canonical
- Add docstrings to tests.
442
443
        # Get the revision properties, ignoring the branch-nick property, which
444
        # we don't care about for this test.
445
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
446
        properties = dict(last_rev.properties)
447
        del properties['branch-nick']
448
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
449
        self.assertEqual(
2376.4.21 by Jonathan Lange
Change the bugs separator to \n from ,
450
            {'bugs': 'https://launchpad.net/bugs/123 fixed\n'
2376.4.18 by Jonathan Lange
Store all bug fix URLs in a single property.
451
                     'http://twistedmatrix.com/trac/ticket/235 fixed'},
452
            properties)
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
453
454
    def test_fixes_unknown_bug_prefix(self):
455
        tree = self.make_branch_and_tree('tree')
456
        self.build_tree(['tree/hello.txt'])
457
        tree.add('hello.txt')
458
        self.run_bzr_error(
459
            ["Unrecognized bug %s. Commit refused." % 'xxx:123'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
460
            'commit -m add-b --fixes=xxx:123',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
461
            working_dir='tree')
462
463
    def test_fixes_invalid_bug_number(self):
464
        tree = self.make_branch_and_tree('tree')
465
        self.build_tree(['tree/hello.txt'])
466
        tree.add('hello.txt')
467
        self.run_bzr_error(
2376.4.7 by jml at canonical
- Add docstrings to tests.
468
            ["Invalid bug identifier for %s. Commit refused." % 'lp:orange'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
469
            'commit -m add-b --fixes=lp:orange',
2376.4.2 by jml at canonical
More sophisticated error handling for --fixes option
470
            working_dir='tree')
2376.4.7 by jml at canonical
- Add docstrings to tests.
471
472
    def test_fixes_invalid_argument(self):
473
        """Raise an appropriate error when the fixes argument isn't tag:id."""
474
        tree = self.make_branch_and_tree('tree')
475
        self.build_tree(['tree/hello.txt'])
476
        tree.add('hello.txt')
477
        self.run_bzr_error(
2376.4.13 by Jonathan Lange
Some stylistic cleanups
478
            [r"Invalid bug orange. Must be in the form of 'tag:id'\. "
479
             r"Commit refused\."],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
480
            'commit -m add-b --fixes=orange',
2376.4.7 by jml at canonical
- Add docstrings to tests.
481
            working_dir='tree')
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
482
483
    def test_no_author(self):
484
        """If the author is not specified, the author property is not set."""
485
        tree = self.make_branch_and_tree('tree')
486
        self.build_tree(['tree/hello.txt'])
487
        tree.add('hello.txt')
488
        self.run_bzr( 'commit -m hello tree/hello.txt')
489
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
490
        properties = last_rev.properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
491
        self.assertFalse('author' in properties)
492
493
    def test_author_sets_property(self):
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
494
        """commit --author='John Doe <jdoe@example.com>' sets the author
495
           revprop.
496
        """
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
497
        tree = self.make_branch_and_tree('tree')
498
        self.build_tree(['tree/hello.txt'])
499
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
500
        self.run_bzr("commit -m hello --author='John Doe <jdoe@example.com>' "
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
501
                     "tree/hello.txt")
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
502
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
503
        properties = last_rev.properties
504
        self.assertEqual('John Doe <jdoe@example.com>', properties['author'])
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
505
506
    def test_author_no_email(self):
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
507
        """Author's name without an email address is allowed, too."""
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
508
        tree = self.make_branch_and_tree('tree')
509
        self.build_tree(['tree/hello.txt'])
510
        tree.add('hello.txt')
2671.2.4 by Lukáš Lalinský
Fixed broken test_author_* blackbox tests.
511
        out, err = self.run_bzr("commit -m hello --author='John Doe' "
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
512
                                "tree/hello.txt")
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
513
        last_rev = tree.branch.repository.get_revision(tree.last_revision())
2671.2.2 by Lukáš Lalinský
Move setting of the author revision property to MutableTree.commit. Don't use try/except KeyError in LongLogFormatter to display authors and branch-nicks. Removed warning about missing e-mail in the authors name.
514
        properties = last_rev.properties
2671.2.1 by Lukáš Lalinský
Add --author option to 'bzr commit' to record the author's name, if it's different from the committer.
515
        self.assertEqual('John Doe', properties['author'])