43
43
return "bzrlib.ahook bzrlib.ahook"
46
class TestCommit(TestCaseInTempDir):
46
class TestCommit(TestCaseWithTransport):
48
48
def test_simple_commit(self):
49
49
"""Commit and check two versions of a single file."""
50
b = Branch.initialize(u'.')
50
wt = self.make_branch_and_tree('.')
51
52
file('hello', 'w').write('hello world')
52
b.working_tree().add('hello')
53
b.working_tree().commit(message='add hello')
54
file_id = b.working_tree().path2id('hello')
54
wt.commit(message='add hello')
55
file_id = wt.path2id('hello')
56
57
file('hello', 'w').write('version 2')
57
b.working_tree().commit(message='commit 2')
58
wt.commit(message='commit 2')
59
60
eq = self.assertEquals
72
73
def test_delete_commit(self):
73
74
"""Test a commit with a deleted file"""
74
b = Branch.initialize(u'.')
75
wt = self.make_branch_and_tree('.')
75
77
file('hello', 'w').write('hello world')
76
b.working_tree().add(['hello'], ['hello-id'])
77
b.working_tree().commit(message='add hello')
78
wt.add(['hello'], ['hello-id'])
79
wt.commit(message='add hello')
80
b.working_tree().commit('removed hello', rev_id='rev2')
82
wt.commit('removed hello', rev_id='rev2')
82
84
tree = b.repository.revision_tree('rev2')
83
85
self.assertFalse(tree.has_id('hello-id'))
85
87
def test_pointless_commit(self):
86
88
"""Commit refuses unless there are changes or it's forced."""
87
b = Branch.initialize(u'.')
89
wt = self.make_branch_and_tree('.')
88
91
file('hello', 'w').write('hello')
89
b.working_tree().add(['hello'])
90
b.working_tree().commit(message='add hello')
93
wt.commit(message='add hello')
91
94
self.assertEquals(b.revno(), 1)
92
95
self.assertRaises(PointlessCommit,
93
b.working_tree().commit,
95
98
allow_pointless=False)
96
99
self.assertEquals(b.revno(), 1)
98
101
def test_commit_empty(self):
99
102
"""Commiting an empty tree works."""
100
b = Branch.initialize(u'.')
101
b.working_tree().commit(message='empty tree', allow_pointless=True)
103
wt = self.make_branch_and_tree('.')
105
wt.commit(message='empty tree', allow_pointless=True)
102
106
self.assertRaises(PointlessCommit,
103
b.working_tree().commit,
104
108
message='empty tree',
105
109
allow_pointless=False)
106
b.working_tree().commit(message='empty tree', allow_pointless=True)
110
wt.commit(message='empty tree', allow_pointless=True)
107
111
self.assertEquals(b.revno(), 2)
110
113
def test_selective_delete(self):
111
114
"""Selective commit in tree with deletions"""
112
b = Branch.initialize(u'.')
115
wt = self.make_branch_and_tree('.')
113
117
file('hello', 'w').write('hello')
114
118
file('buongia', 'w').write('buongia')
115
b.working_tree().add(['hello', 'buongia'],
119
wt.add(['hello', 'buongia'],
116
120
['hello-id', 'buongia-id'])
117
b.working_tree().commit(message='add files',
121
wt.commit(message='add files',
118
122
rev_id='test@rev-1')
120
124
os.remove('hello')
121
125
file('buongia', 'w').write('new text')
122
b.working_tree().commit(message='update text',
126
wt.commit(message='update text',
123
127
specific_files=['buongia'],
124
128
allow_pointless=False,
125
129
rev_id='test@rev-2')
127
b.working_tree().commit(message='remove hello',
131
wt.commit(message='remove hello',
128
132
specific_files=['hello'],
129
133
allow_pointless=False,
130
134
rev_id='test@rev-3')
141
145
self.assertFalse(tree3.has_filename('hello'))
142
146
self.assertEquals(tree3.get_file_text('buongia-id'), 'new text')
145
148
def test_commit_rename(self):
146
149
"""Test commit of a revision where a file is renamed."""
147
b = Branch.initialize(u'.')
148
tree = WorkingTree(u'.', b)
150
tree = self.make_branch_and_tree('.')
149
152
self.build_tree(['hello'], line_endings='binary')
150
153
tree.add(['hello'], ['hello-id'])
151
154
tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
182
186
def test_commit_move(self):
183
187
"""Test commit of revisions with moved files and directories"""
184
188
eq = self.assertEquals
185
b = Branch.initialize(u'.')
189
wt = self.make_branch_and_tree('.')
186
191
r1 = 'test@rev-1'
187
192
self.build_tree(['hello', 'a/', 'b/'])
188
b.working_tree().add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
189
b.working_tree().commit('initial', rev_id=r1, allow_pointless=False)
190
b.working_tree().move(['hello'], 'a')
193
wt.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
194
wt.commit('initial', rev_id=r1, allow_pointless=False)
195
wt.move(['hello'], 'a')
191
196
r2 = 'test@rev-2'
192
b.working_tree().commit('two', rev_id=r2, allow_pointless=False)
197
wt.commit('two', rev_id=r2, allow_pointless=False)
193
198
self.check_inventory_shape(b.working_tree().read_working_inventory(),
194
199
['a', 'a/hello', 'b'])
196
b.working_tree().move(['b'], 'a')
197
202
r3 = 'test@rev-3'
198
b.working_tree().commit('three', rev_id=r3, allow_pointless=False)
199
self.check_inventory_shape(b.working_tree().read_working_inventory(),
203
wt.commit('three', rev_id=r3, allow_pointless=False)
204
self.check_inventory_shape(wt.read_working_inventory(),
200
205
['a', 'a/hello', 'a/b'])
201
206
self.check_inventory_shape(b.repository.get_revision_inventory(r3),
202
207
['a', 'a/hello', 'a/b'])
204
b.working_tree().move(['a/hello'], 'a/b')
209
wt.move(['a/hello'], 'a/b')
205
210
r4 = 'test@rev-4'
206
b.working_tree().commit('four', rev_id=r4, allow_pointless=False)
207
self.check_inventory_shape(b.working_tree().read_working_inventory(),
211
wt.commit('four', rev_id=r4, allow_pointless=False)
212
self.check_inventory_shape(wt.read_working_inventory(),
208
213
['a', 'a/b/hello', 'a/b'])
210
215
inv = b.repository.get_revision_inventory(r4)
215
220
def test_removed_commit(self):
216
221
"""Commit with a removed file"""
217
b = Branch.initialize(u'.')
218
wt = b.working_tree()
222
wt = self.make_branch_and_tree('.')
219
224
file('hello', 'w').write('hello world')
220
b.working_tree().add(['hello'], ['hello-id'])
221
b.working_tree().commit(message='add hello')
223
wt = b.working_tree() # FIXME: kludge for aliasing of working inventory
225
wt.add(['hello'], ['hello-id'])
226
wt.commit(message='add hello')
224
227
wt.remove('hello')
225
b.working_tree().commit('removed hello', rev_id='rev2')
228
wt.commit('removed hello', rev_id='rev2')
227
230
tree = b.repository.revision_tree('rev2')
228
231
self.assertFalse(tree.has_id('hello-id'))
231
233
def test_committed_ancestry(self):
232
234
"""Test commit appends revisions to ancestry."""
233
b = Branch.initialize(u'.')
235
wt = self.make_branch_and_tree('.')
235
238
for i in range(4):
236
239
file('hello', 'w').write((str(i) * 4) + '\n')
238
b.working_tree().add(['hello'], ['hello-id'])
241
wt.add(['hello'], ['hello-id'])
239
242
rev_id = 'test@rev-%d' % (i+1)
240
243
rev_ids.append(rev_id)
241
b.working_tree().commit(message='rev %d' % (i+1),
244
wt.commit(message='rev %d' % (i+1),
243
246
eq = self.assertEquals
244
247
eq(b.revision_history(), rev_ids)
247
250
eq(anc, [None] + rev_ids[:i+1])
249
252
def test_commit_new_subdir_child_selective(self):
250
b = Branch.initialize(u'.')
253
wt = self.make_branch_and_tree('.')
251
255
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
252
b.working_tree().add(['dir', 'dir/file1', 'dir/file2'],
256
wt.add(['dir', 'dir/file1', 'dir/file2'],
253
257
['dirid', 'file1id', 'file2id'])
254
b.working_tree().commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
258
wt.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
255
259
inv = b.repository.get_inventory('1')
256
260
self.assertEqual('1', inv['dirid'].revision)
257
261
self.assertEqual('1', inv['file1id'].revision)
261
265
def test_strict_commit(self):
262
266
"""Try and commit with unknown files and strict = True, should fail."""
263
267
from bzrlib.errors import StrictCommitFailed
264
b = Branch.initialize(u'.')
268
wt = self.make_branch_and_tree('.')
265
270
file('hello', 'w').write('hello world')
266
b.working_tree().add('hello')
267
272
file('goodbye', 'w').write('goodbye cruel world!')
268
273
self.assertRaises(StrictCommitFailed, b.working_tree().commit,
269
274
message='add hello but not goodbye', strict=True)
272
277
"""Try and commit with no unknown files and strict = True,
274
279
from bzrlib.errors import StrictCommitFailed
275
b = Branch.initialize(u'.')
280
wt = self.make_branch_and_tree('.')
276
282
file('hello', 'w').write('hello world')
277
b.working_tree().add('hello')
278
b.working_tree().commit(message='add hello', strict=True)
284
wt.commit(message='add hello', strict=True)
280
286
def test_nonstrict_commit(self):
281
287
"""Try and commit with unknown files and strict = False, should work."""
282
b = Branch.initialize(u'.')
288
wt = self.make_branch_and_tree('.')
283
290
file('hello', 'w').write('hello world')
284
b.working_tree().add('hello')
285
292
file('goodbye', 'w').write('goodbye cruel world!')
286
b.working_tree().commit(message='add hello but not goodbye', strict=False)
293
wt.commit(message='add hello but not goodbye', strict=False)
288
295
def test_nonstrict_commit_without_unknowns(self):
289
296
"""Try and commit with no unknown files and strict = False,
291
b = Branch.initialize(u'.')
298
wt = self.make_branch_and_tree('.')
292
300
file('hello', 'w').write('hello world')
293
b.working_tree().add('hello')
294
b.working_tree().commit(message='add hello', strict=False)
302
wt.commit(message='add hello', strict=False)
296
304
def test_signed_commit(self):
297
305
import bzrlib.gpg
298
306
import bzrlib.commit as commit
299
307
oldstrategy = bzrlib.gpg.GPGStrategy
300
branch = Branch.initialize(u'.')
301
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
308
wt = self.make_branch_and_tree('.')
310
wt.commit("base", allow_pointless=True, rev_id='A')
302
311
self.failIf(branch.repository.revision_store.has_id('A', 'sig'))
304
313
from bzrlib.testament import Testament
305
314
# monkey patch gpg signing mechanism
306
315
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
307
commit.Commit(config=MustSignConfig(branch)).commit(branch, "base",
316
commit.Commit(config=MustSignConfig(branch)).commit(message="base",
308
317
allow_pointless=True,
310
320
self.assertEqual(Testament.from_revision(branch.repository,
311
321
'B').as_short_text(),
312
322
branch.repository.revision_store.get('B',
318
328
import bzrlib.gpg
319
329
import bzrlib.commit as commit
320
330
oldstrategy = bzrlib.gpg.GPGStrategy
321
branch = Branch.initialize(u'.')
322
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
331
wt = self.make_branch_and_tree('.')
333
wt.commit("base", allow_pointless=True, rev_id='A')
323
334
self.failIf(branch.repository.revision_store.has_id('A', 'sig'))
325
336
from bzrlib.testament import Testament