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.
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')
46
49
def test_commit_success(self):
47
50
"""Successful commit should not leave behind a bzr-commit-* file"""
51
self.make_branch_and_tree('.')
49
52
self.run_bzr('commit --unchanged -m message')
50
53
self.assertEqual('', self.run_bzr('unknowns')[0])
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')
61
64
self.run_bzr(['commit', '-m', 'first commit', 'a'])
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'])
67
70
self.build_tree_contents([('a/a_file', 'new contents')])
68
71
self.run_bzr(['commit', '-m', 'change in a', 'a'])
71
self.run_bzr('merge ../a', retcode=1) # will conflict
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'])
77
79
def test_10_verbose_commit(self):
78
80
"""Add one file and examine verbose commit output"""
81
tree = self.make_branch_and_tree('.')
80
82
self.build_tree(['hello.txt'])
81
self.run_bzr("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
self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
88
'Committed revision 1.\n$',)
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
self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
106
'modified hello\.txt\n'
107
'Committed revision 2\.\n$')
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
self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
116
'renamed hello\.txt => gutentag\.txt\n'
117
'Committed revision 2\.$\n')
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',
127
self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
129
'renamed hello\.txt => subdir/hello\.txt\n'
130
'Committed revision 2\.\n$')
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
self.assertContainsRe(err, '^Committing revision 1 to ".*"\.\n'
142
'Committed revision 1\.\n$')
142
144
def test_verbose_commit_with_unchanged(self):
143
145
"""Unchanged files should not be listed by default in verbose output"""
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
self.assertContainsRe(err, '^Committing revision 2 to ".*"\.\n'
155
'Committed revision 2\.$\n')
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'])
162
a_tree.commit(message='Initial message')
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)
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([
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)
205
221
out,err = self.run_bzr('commit -m added')
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'
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, ),
221
238
def test_empty_commit_message(self):
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() {}')])
225
242
self.run_bzr('commit -m ""', retcode=3)
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)
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,
257
env_changes={'LANG': 'C'})
233
258
self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
234
259
'unsupported by the current encoding.')
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')
245
file('foo.c', 'wt').write('int main() {}')
246
file('bar.c', 'wt').write('int main() {}')
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,
270
"bzr: ERROR: Working tree is out of date, please run "
291
"bzr: ERROR: Working tree is out of date, please "
292
"run 'bzr update'.\n"))
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')
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')
292
313
self.run_bzr('commit -m add-hosts u1')
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')
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'
402
'Committed revision 1\.\n')
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'])
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')])
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.')