50
50
b = Branch.initialize('.')
51
51
file('hello', 'w').write('hello world')
53
b.commit(message='add hello')
53
b.working_tree().commit(message='add hello')
54
54
file_id = b.working_tree().path2id('hello')
56
56
file('hello', 'w').write('version 2')
57
b.commit(message='commit 2')
57
b.working_tree().commit(message='commit 2')
59
59
eq = self.assertEquals
74
74
b = Branch.initialize('.')
75
75
file('hello', 'w').write('hello world')
76
76
b.add(['hello'], ['hello-id'])
77
b.commit(message='add hello')
77
b.working_tree().commit(message='add hello')
80
b.commit('removed hello', rev_id='rev2')
80
b.working_tree().commit('removed hello', rev_id='rev2')
82
82
tree = b.revision_tree('rev2')
83
83
self.assertFalse(tree.has_id('hello-id'))
86
85
def test_pointless_commit(self):
87
86
"""Commit refuses unless there are changes or it's forced."""
88
87
b = Branch.initialize('.')
89
88
file('hello', 'w').write('hello')
91
b.commit(message='add hello')
90
b.working_tree().commit(message='add hello')
92
91
self.assertEquals(b.revno(), 1)
93
92
self.assertRaises(PointlessCommit,
93
b.working_tree().commit,
96
95
allow_pointless=False)
97
96
self.assertEquals(b.revno(), 1)
101
98
def test_commit_empty(self):
102
99
"""Commiting an empty tree works."""
103
100
b = Branch.initialize('.')
104
b.commit(message='empty tree', allow_pointless=True)
101
b.working_tree().commit(message='empty tree', allow_pointless=True)
105
102
self.assertRaises(PointlessCommit,
103
b.working_tree().commit,
107
104
message='empty tree',
108
105
allow_pointless=False)
109
b.commit(message='empty tree', allow_pointless=True)
106
b.working_tree().commit(message='empty tree', allow_pointless=True)
110
107
self.assertEquals(b.revno(), 2)
117
114
file('buongia', 'w').write('buongia')
118
115
b.add(['hello', 'buongia'],
119
116
['hello-id', 'buongia-id'])
120
b.commit(message='add files',
117
b.working_tree().commit(message='add files',
121
118
rev_id='test@rev-1')
123
120
os.remove('hello')
124
121
file('buongia', 'w').write('new text')
125
b.commit(message='update text',
122
b.working_tree().commit(message='update text',
126
123
specific_files=['buongia'],
127
124
allow_pointless=False,
128
125
rev_id='test@rev-2')
130
b.commit(message='remove hello',
127
b.working_tree().commit(message='remove hello',
131
128
specific_files=['hello'],
132
129
allow_pointless=False,
133
130
rev_id='test@rev-3')
150
147
b = Branch.initialize('.')
151
148
self.build_tree(['hello'])
152
149
b.add(['hello'], ['hello-id'])
153
b.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
150
b.working_tree().commit(message='one', rev_id='test@rev-1', allow_pointless=False)
155
152
b.rename_one('hello', 'fruity')
156
b.commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
153
b.working_tree().commit(message='renamed', rev_id='test@rev-2', allow_pointless=False)
158
155
eq = self.assertEquals
159
156
tree1 = b.revision_tree('test@rev-1')
175
172
def test_reused_rev_id(self):
176
173
"""Test that a revision id cannot be reused in a branch"""
177
174
b = Branch.initialize('.')
178
b.commit('initial', rev_id='test@rev-1', allow_pointless=True)
175
b.working_tree().commit('initial', rev_id='test@rev-1', allow_pointless=True)
179
176
self.assertRaises(Exception,
177
b.working_tree().commit,
181
178
message='reused id',
182
179
rev_id='test@rev-1',
183
180
allow_pointless=True)
191
188
r1 = 'test@rev-1'
192
189
self.build_tree(['hello', 'a/', 'b/'])
193
190
b.add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
194
b.commit('initial', rev_id=r1, allow_pointless=False)
191
b.working_tree().commit('initial', rev_id=r1, allow_pointless=False)
196
193
b.move(['hello'], 'a')
197
194
r2 = 'test@rev-2'
198
b.commit('two', rev_id=r2, allow_pointless=False)
195
b.working_tree().commit('two', rev_id=r2, allow_pointless=False)
199
196
self.check_inventory_shape(b.working_tree().read_working_inventory(),
200
197
['a', 'a/hello', 'b'])
202
199
b.move(['b'], 'a')
203
200
r3 = 'test@rev-3'
204
b.commit('three', rev_id=r3, allow_pointless=False)
201
b.working_tree().commit('three', rev_id=r3, allow_pointless=False)
205
202
self.check_inventory_shape(b.working_tree().read_working_inventory(),
206
203
['a', 'a/hello', 'a/b'])
207
204
self.check_inventory_shape(b.get_revision_inventory(r3),
210
207
b.move([os.sep.join(['a', 'hello'])],
211
208
os.sep.join(['a', 'b']))
212
209
r4 = 'test@rev-4'
213
b.commit('four', rev_id=r4, allow_pointless=False)
210
b.working_tree().commit('four', rev_id=r4, allow_pointless=False)
214
211
self.check_inventory_shape(b.working_tree().read_working_inventory(),
215
212
['a', 'a/b/hello', 'a/b'])
226
223
wt = b.working_tree()
227
224
file('hello', 'w').write('hello world')
228
225
b.add(['hello'], ['hello-id'])
229
b.commit(message='add hello')
226
b.working_tree().commit(message='add hello')
231
228
wt = b.working_tree() # FIXME: kludge for aliasing of working inventory
232
229
wt.remove('hello')
233
b.commit('removed hello', rev_id='rev2')
230
b.working_tree().commit('removed hello', rev_id='rev2')
235
232
tree = b.revision_tree('rev2')
236
233
self.assertFalse(tree.has_id('hello-id'))
246
243
b.add(['hello'], ['hello-id'])
247
244
rev_id = 'test@rev-%d' % (i+1)
248
245
rev_ids.append(rev_id)
249
b.commit(message='rev %d' % (i+1),
246
b.working_tree().commit(message='rev %d' % (i+1),
251
248
eq = self.assertEquals
252
249
eq(b.revision_history(), rev_ids)
259
256
self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
260
257
b.add(['dir', 'dir/file1', 'dir/file2'],
261
258
['dirid', 'file1id', 'file2id'])
262
b.commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
259
b.working_tree().commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
263
260
inv = b.get_inventory('1')
264
261
self.assertEqual('1', inv['dirid'].revision)
265
262
self.assertEqual('1', inv['file1id'].revision)
273
270
file('hello', 'w').write('hello world')
275
272
file('goodbye', 'w').write('goodbye cruel world!')
276
self.assertRaises(StrictCommitFailed, b.commit,
273
self.assertRaises(StrictCommitFailed, b.working_tree().commit,
277
274
message='add hello but not goodbye', strict=True)
279
276
def test_strict_commit_without_unknowns(self):
283
280
b = Branch.initialize('.')
284
281
file('hello', 'w').write('hello world')
286
b.commit(message='add hello', strict=True)
283
b.working_tree().commit(message='add hello', strict=True)
288
285
def test_nonstrict_commit(self):
289
286
"""Try and commit with unknown files and strict = False, should work."""
291
288
file('hello', 'w').write('hello world')
293
290
file('goodbye', 'w').write('goodbye cruel world!')
294
b.commit(message='add hello but not goodbye', strict=False)
291
b.working_tree().commit(message='add hello but not goodbye', strict=False)
296
293
def test_nonstrict_commit_without_unknowns(self):
297
294
"""Try and commit with no unknown files and strict = False,
299
296
b = Branch.initialize('.')
300
297
file('hello', 'w').write('hello world')
302
b.commit(message='add hello', strict=False)
299
b.working_tree().commit(message='add hello', strict=False)
304
301
def test_signed_commit(self):
305
302
import bzrlib.gpg
306
303
import bzrlib.commit as commit
307
304
oldstrategy = bzrlib.gpg.GPGStrategy
308
305
branch = Branch.initialize('.')
309
branch.commit("base", allow_pointless=True, rev_id='A')
306
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
310
307
self.failIf(branch.revision_store.has_id('A', 'sig'))
312
309
from bzrlib.testament import Testament
325
322
import bzrlib.commit as commit
326
323
oldstrategy = bzrlib.gpg.GPGStrategy
327
324
branch = Branch.initialize('.')
328
branch.commit("base", allow_pointless=True, rev_id='A')
325
branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
329
326
self.failIf(branch.revision_store.has_id('A', 'sig'))
331
328
from bzrlib.testament import Testament