21
from bzrlib.selftest import TestCaseInTempDir
21
from bzrlib.tests import TestCaseInTempDir
22
22
from bzrlib.branch import Branch
23
23
from bzrlib.workingtree import WorkingTree
24
24
from bzrlib.commit import Commit
48
48
def test_simple_commit(self):
49
49
"""Commit and check two versions of a single file."""
50
b = Branch.initialize('.')
50
b = Branch.initialize(u'.')
51
51
file('hello', 'w').write('hello world')
52
b.working_tree().add('hello')
53
53
b.working_tree().commit(message='add hello')
54
54
file_id = b.working_tree().path2id('hello')
72
72
def test_delete_commit(self):
73
73
"""Test a commit with a deleted file"""
74
b = Branch.initialize('.')
74
b = Branch.initialize(u'.')
75
75
file('hello', 'w').write('hello world')
76
b.add(['hello'], ['hello-id'])
76
b.working_tree().add(['hello'], ['hello-id'])
77
77
b.working_tree().commit(message='add hello')
85
85
def test_pointless_commit(self):
86
86
"""Commit refuses unless there are changes or it's forced."""
87
b = Branch.initialize('.')
87
b = Branch.initialize(u'.')
88
88
file('hello', 'w').write('hello')
89
b.working_tree().add(['hello'])
90
90
b.working_tree().commit(message='add hello')
91
91
self.assertEquals(b.revno(), 1)
92
92
self.assertRaises(PointlessCommit,
98
98
def test_commit_empty(self):
99
99
"""Commiting an empty tree works."""
100
b = Branch.initialize('.')
100
b = Branch.initialize(u'.')
101
101
b.working_tree().commit(message='empty tree', allow_pointless=True)
102
102
self.assertRaises(PointlessCommit,
103
103
b.working_tree().commit,
110
110
def test_selective_delete(self):
111
111
"""Selective commit in tree with deletions"""
112
b = Branch.initialize('.')
112
b = Branch.initialize(u'.')
113
113
file('hello', 'w').write('hello')
114
114
file('buongia', 'w').write('buongia')
115
b.add(['hello', 'buongia'],
115
b.working_tree().add(['hello', 'buongia'],
116
116
['hello-id', 'buongia-id'])
117
117
b.working_tree().commit(message='add files',
118
118
rev_id='test@rev-1')
145
145
def test_commit_rename(self):
146
146
"""Test commit of a revision where a file is renamed."""
147
b = Branch.initialize('.')
148
self.build_tree(['hello'])
149
b.add(['hello'], ['hello-id'])
150
b.working_tree().commit(message='one', rev_id='test@rev-1', allow_pointless=False)
147
b = Branch.initialize(u'.')
148
tree = WorkingTree(u'.', b)
149
self.build_tree(['hello'], line_endings='binary')
150
tree.add(['hello'], ['hello-id'])
151
tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
152
b.rename_one('hello', 'fruity')
153
b.working_tree().commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
153
tree.rename_one('hello', 'fruity')
154
tree.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
155
156
eq = self.assertEquals
156
157
tree1 = b.revision_tree('test@rev-1')
168
169
ie = tree2.inventory['hello-id']
169
170
eq(ie.revision, 'test@rev-2')
172
172
def test_reused_rev_id(self):
173
173
"""Test that a revision id cannot be reused in a branch"""
174
b = Branch.initialize('.')
174
b = Branch.initialize(u'.')
175
175
b.working_tree().commit('initial', rev_id='test@rev-1', allow_pointless=True)
176
176
self.assertRaises(Exception,
177
177
b.working_tree().commit,
178
178
message='reused id',
179
179
rev_id='test@rev-1',
180
180
allow_pointless=True)
184
182
def test_commit_move(self):
185
183
"""Test commit of revisions with moved files and directories"""
186
184
eq = self.assertEquals
187
b = Branch.initialize('.')
185
b = Branch.initialize(u'.')
188
186
r1 = 'test@rev-1'
189
187
self.build_tree(['hello', 'a/', 'b/'])
190
b.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
188
b.working_tree().add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
191
189
b.working_tree().commit('initial', rev_id=r1, allow_pointless=False)
193
b.move(['hello'], 'a')
190
b.working_tree().move(['hello'], 'a')
194
191
r2 = 'test@rev-2'
195
192
b.working_tree().commit('two', rev_id=r2, allow_pointless=False)
196
193
self.check_inventory_shape(b.working_tree().read_working_inventory(),
197
194
['a', 'a/hello', 'b'])
196
b.working_tree().move(['b'], 'a')
200
197
r3 = 'test@rev-3'
201
198
b.working_tree().commit('three', rev_id=r3, allow_pointless=False)
202
199
self.check_inventory_shape(b.working_tree().read_working_inventory(),
204
201
self.check_inventory_shape(b.get_revision_inventory(r3),
205
202
['a', 'a/hello', 'a/b'])
207
b.move([os.sep.join(['a', 'hello'])],
204
b.working_tree().move([os.sep.join(['a', 'hello'])],
208
205
os.sep.join(['a', 'b']))
209
206
r4 = 'test@rev-4'
210
207
b.working_tree().commit('four', rev_id=r4, allow_pointless=False)
215
212
eq(inv['hello-id'].revision, r4)
216
213
eq(inv['a-id'].revision, r1)
217
214
eq(inv['b-id'].revision, r3)
220
216
def test_removed_commit(self):
221
217
"""Commit with a removed file"""
222
b = Branch.initialize('.')
218
b = Branch.initialize(u'.')
223
219
wt = b.working_tree()
224
220
file('hello', 'w').write('hello world')
225
b.add(['hello'], ['hello-id'])
221
b.working_tree().add(['hello'], ['hello-id'])
226
222
b.working_tree().commit(message='add hello')
228
224
wt = b.working_tree() # FIXME: kludge for aliasing of working inventory
236
232
def test_committed_ancestry(self):
237
233
"""Test commit appends revisions to ancestry."""
238
b = Branch.initialize('.')
234
b = Branch.initialize(u'.')
240
236
for i in range(4):
241
237
file('hello', 'w').write((str(i) * 4) + '\n')
243
b.add(['hello'], ['hello-id'])
239
b.working_tree().add(['hello'], ['hello-id'])
244
240
rev_id = 'test@rev-%d' % (i+1)
245
241
rev_ids.append(rev_id)
246
242
b.working_tree().commit(message='rev %d' % (i+1),
252
248
eq(anc, [None] + rev_ids[:i+1])
254
250
def test_commit_new_subdir_child_selective(self):
255
b = Branch.initialize('.')
251
b = Branch.initialize(u'.')
256
252
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
257
b.add(['dir', 'dir/file1', 'dir/file2'],
253
b.working_tree().add(['dir', 'dir/file1', 'dir/file2'],
258
254
['dirid', 'file1id', 'file2id'])
259
255
b.working_tree().commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
260
256
inv = b.get_inventory('1')
266
262
def test_strict_commit(self):
267
263
"""Try and commit with unknown files and strict = True, should fail."""
268
264
from bzrlib.errors import StrictCommitFailed
269
b = Branch.initialize('.')
265
b = Branch.initialize(u'.')
270
266
file('hello', 'w').write('hello world')
267
b.working_tree().add('hello')
272
268
file('goodbye', 'w').write('goodbye cruel world!')
273
269
self.assertRaises(StrictCommitFailed, b.working_tree().commit,
274
270
message='add hello but not goodbye', strict=True)
277
273
"""Try and commit with no unknown files and strict = True,
279
275
from bzrlib.errors import StrictCommitFailed
280
b = Branch.initialize('.')
276
b = Branch.initialize(u'.')
281
277
file('hello', 'w').write('hello world')
278
b.working_tree().add('hello')
283
279
b.working_tree().commit(message='add hello', strict=True)
285
281
def test_nonstrict_commit(self):
286
282
"""Try and commit with unknown files and strict = False, should work."""
287
b = Branch.initialize('.')
283
b = Branch.initialize(u'.')
288
284
file('hello', 'w').write('hello world')
285
b.working_tree().add('hello')
290
286
file('goodbye', 'w').write('goodbye cruel world!')
291
287
b.working_tree().commit(message='add hello but not goodbye', strict=False)
293
289
def test_nonstrict_commit_without_unknowns(self):
294
290
"""Try and commit with no unknown files and strict = False,
296
b = Branch.initialize('.')
292
b = Branch.initialize(u'.')
297
293
file('hello', 'w').write('hello world')
294
b.working_tree().add('hello')
299
295
b.working_tree().commit(message='add hello', strict=False)
301
297
def test_signed_commit(self):
302
298
import bzrlib.gpg
303
299
import bzrlib.commit as commit
304
300
oldstrategy = bzrlib.gpg.GPGStrategy
305
branch = Branch.initialize('.')
301
branch = Branch.initialize(u'.')
306
302
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
307
303
self.failIf(branch.revision_store.has_id('A', 'sig'))
321
317
import bzrlib.gpg
322
318
import bzrlib.commit as commit
323
319
oldstrategy = bzrlib.gpg.GPGStrategy
324
branch = Branch.initialize('.')
320
branch = Branch.initialize(u'.')
325
321
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
326
322
self.failIf(branch.revision_store.has_id('A', 'sig'))
335
331
allow_pointless=True,
337
branch = Branch.open('.')
333
branch = Branch.open(u'.')
338
334
self.assertEqual(branch.revision_history(), ['A'])
339
335
self.failIf(branch.revision_store.has_id('B'))
343
339
def test_commit_invokes_hooks(self):
344
340
import bzrlib.commit as commit
345
branch = Branch.initialize('.')
341
branch = Branch.initialize(u'.')
347
343
def called(branch, rev_id):
348
344
calls.append('called')