~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Martin Pool
  • Date: 2006-01-23 02:09:39 UTC
  • mfrom: (1534.1.11 integration)
  • Revision ID: mbp@sourcefrog.net-20060123020939-567fb193328ed7a6
[merge] robert's integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
 
20
20
import bzrlib
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
47
47
 
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.add('hello')
 
52
        b.working_tree().add('hello')
53
53
        b.working_tree().commit(message='add hello')
54
54
        file_id = b.working_tree().path2id('hello')
55
55
 
71
71
 
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')
78
78
 
79
79
        os.remove('hello')
84
84
 
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.add(['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,
97
97
        
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,
109
109
 
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')
144
144
 
145
145
    def test_commit_rename(self):
146
146
        """Test commit of a revision where a file is renamed."""
147
 
        b = Branch.initialize('.')
 
147
        b = Branch.initialize(u'.')
 
148
        tree = WorkingTree(u'.', b)
148
149
        self.build_tree(['hello'], line_endings='binary')
149
 
        b.add(['hello'], ['hello-id'])
150
 
        b.working_tree().commit(message='one', rev_id='test@rev-1', allow_pointless=False)
 
150
        tree.add(['hello'], ['hello-id'])
 
151
        tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
151
152
 
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)
154
155
 
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')
170
171
 
171
 
 
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)
181
 
                          
182
 
 
183
181
 
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)
192
 
 
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'])
198
195
 
199
 
        b.move(['b'], 'a')
 
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'])
206
203
 
207
 
        b.move([os.sep.join(['a', 'hello'])],
208
 
               os.sep.join(['a', 'b']))
 
204
        b.working_tree().move(['a/hello'], 'a/b')
209
205
        r4 = 'test@rev-4'
210
206
        b.working_tree().commit('four', rev_id=r4, allow_pointless=False)
211
207
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
215
211
        eq(inv['hello-id'].revision, r4)
216
212
        eq(inv['a-id'].revision, r1)
217
213
        eq(inv['b-id'].revision, r3)
218
 
 
219
214
        
220
215
    def test_removed_commit(self):
221
216
        """Commit with a removed file"""
222
 
        b = Branch.initialize('.')
 
217
        b = Branch.initialize(u'.')
223
218
        wt = b.working_tree()
224
219
        file('hello', 'w').write('hello world')
225
 
        b.add(['hello'], ['hello-id'])
 
220
        b.working_tree().add(['hello'], ['hello-id'])
226
221
        b.working_tree().commit(message='add hello')
227
222
 
228
223
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
235
230
 
236
231
    def test_committed_ancestry(self):
237
232
        """Test commit appends revisions to ancestry."""
238
 
        b = Branch.initialize('.')
 
233
        b = Branch.initialize(u'.')
239
234
        rev_ids = []
240
235
        for i in range(4):
241
236
            file('hello', 'w').write((str(i) * 4) + '\n')
242
237
            if i == 0:
243
 
                b.add(['hello'], ['hello-id'])
 
238
                b.working_tree().add(['hello'], ['hello-id'])
244
239
            rev_id = 'test@rev-%d' % (i+1)
245
240
            rev_ids.append(rev_id)
246
241
            b.working_tree().commit(message='rev %d' % (i+1),
252
247
            eq(anc, [None] + rev_ids[:i+1])
253
248
 
254
249
    def test_commit_new_subdir_child_selective(self):
255
 
        b = Branch.initialize('.')
 
250
        b = Branch.initialize(u'.')
256
251
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
257
 
        b.add(['dir', 'dir/file1', 'dir/file2'],
 
252
        b.working_tree().add(['dir', 'dir/file1', 'dir/file2'],
258
253
              ['dirid', 'file1id', 'file2id'])
259
254
        b.working_tree().commit('dir/file1', specific_files=['dir/file1'], rev_id='1')
260
255
        inv = b.get_inventory('1')
266
261
    def test_strict_commit(self):
267
262
        """Try and commit with unknown files and strict = True, should fail."""
268
263
        from bzrlib.errors import StrictCommitFailed
269
 
        b = Branch.initialize('.')
 
264
        b = Branch.initialize(u'.')
270
265
        file('hello', 'w').write('hello world')
271
 
        b.add('hello')
 
266
        b.working_tree().add('hello')
272
267
        file('goodbye', 'w').write('goodbye cruel world!')
273
268
        self.assertRaises(StrictCommitFailed, b.working_tree().commit,
274
269
            message='add hello but not goodbye', strict=True)
277
272
        """Try and commit with no unknown files and strict = True,
278
273
        should work."""
279
274
        from bzrlib.errors import StrictCommitFailed
280
 
        b = Branch.initialize('.')
 
275
        b = Branch.initialize(u'.')
281
276
        file('hello', 'w').write('hello world')
282
 
        b.add('hello')
 
277
        b.working_tree().add('hello')
283
278
        b.working_tree().commit(message='add hello', strict=True)
284
279
 
285
280
    def test_nonstrict_commit(self):
286
281
        """Try and commit with unknown files and strict = False, should work."""
287
 
        b = Branch.initialize('.')
 
282
        b = Branch.initialize(u'.')
288
283
        file('hello', 'w').write('hello world')
289
 
        b.add('hello')
 
284
        b.working_tree().add('hello')
290
285
        file('goodbye', 'w').write('goodbye cruel world!')
291
286
        b.working_tree().commit(message='add hello but not goodbye', strict=False)
292
287
 
293
288
    def test_nonstrict_commit_without_unknowns(self):
294
289
        """Try and commit with no unknown files and strict = False,
295
290
        should work."""
296
 
        b = Branch.initialize('.')
 
291
        b = Branch.initialize(u'.')
297
292
        file('hello', 'w').write('hello world')
298
 
        b.add('hello')
 
293
        b.working_tree().add('hello')
299
294
        b.working_tree().commit(message='add hello', strict=False)
300
295
 
301
296
    def test_signed_commit(self):
302
297
        import bzrlib.gpg
303
298
        import bzrlib.commit as commit
304
299
        oldstrategy = bzrlib.gpg.GPGStrategy
305
 
        branch = Branch.initialize('.')
 
300
        branch = Branch.initialize(u'.')
306
301
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
307
302
        self.failIf(branch.revision_store.has_id('A', 'sig'))
308
303
        try:
321
316
        import bzrlib.gpg
322
317
        import bzrlib.commit as commit
323
318
        oldstrategy = bzrlib.gpg.GPGStrategy
324
 
        branch = Branch.initialize('.')
 
319
        branch = Branch.initialize(u'.')
325
320
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
326
321
        self.failIf(branch.revision_store.has_id('A', 'sig'))
327
322
        try:
334
329
                              branch, "base",
335
330
                              allow_pointless=True,
336
331
                              rev_id='B')
337
 
            branch = Branch.open('.')
 
332
            branch = Branch.open(u'.')
338
333
            self.assertEqual(branch.revision_history(), ['A'])
339
334
            self.failIf(branch.revision_store.has_id('B'))
340
335
        finally:
342
337
 
343
338
    def test_commit_invokes_hooks(self):
344
339
        import bzrlib.commit as commit
345
 
        branch = Branch.initialize('.')
 
340
        branch = Branch.initialize(u'.')
346
341
        calls = []
347
342
        def called(branch, rev_id):
348
343
            calls.append('called')