/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

Merge from 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
52
        b.working_tree().add('hello')
53
53
        b.working_tree().commit(message='add hello')
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
76
        b.working_tree().add(['hello'], ['hello-id'])
77
77
        b.working_tree().commit(message='add 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
89
        b.working_tree().add(['hello'])
90
90
        b.working_tree().commit(message='add hello')
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
115
        b.working_tree().add(['hello', 'buongia'],
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('.')
148
 
        tree = WorkingTree('.', b)
 
147
        b = Branch.initialize(u'.')
 
148
        tree = WorkingTree(u'.', b)
149
149
        self.build_tree(['hello'], line_endings='binary')
150
150
        tree.add(['hello'], ['hello-id'])
151
151
        tree.commit(message='one', rev_id='test@rev-1', allow_pointless=False)
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,
182
182
    def test_commit_move(self):
183
183
        """Test commit of revisions with moved files and directories"""
184
184
        eq = self.assertEquals
185
 
        b = Branch.initialize('.')
 
185
        b = Branch.initialize(u'.')
186
186
        r1 = 'test@rev-1'
187
187
        self.build_tree(['hello', 'a/', 'b/'])
188
188
        b.working_tree().add(['hello', 'a', 'b'], ['hello-id', 'a-id', 'b-id'])
201
201
        self.check_inventory_shape(b.get_revision_inventory(r3),
202
202
                                   ['a', 'a/hello', 'a/b'])
203
203
 
204
 
        b.working_tree().move([os.sep.join(['a', 'hello'])],
205
 
               os.sep.join(['a', 'b']))
 
204
        b.working_tree().move(['a/hello'], 'a/b')
206
205
        r4 = 'test@rev-4'
207
206
        b.working_tree().commit('four', rev_id=r4, allow_pointless=False)
208
207
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
215
214
        
216
215
    def test_removed_commit(self):
217
216
        """Commit with a removed file"""
218
 
        b = Branch.initialize('.')
 
217
        b = Branch.initialize(u'.')
219
218
        wt = b.working_tree()
220
219
        file('hello', 'w').write('hello world')
221
220
        b.working_tree().add(['hello'], ['hello-id'])
231
230
 
232
231
    def test_committed_ancestry(self):
233
232
        """Test commit appends revisions to ancestry."""
234
 
        b = Branch.initialize('.')
 
233
        b = Branch.initialize(u'.')
235
234
        rev_ids = []
236
235
        for i in range(4):
237
236
            file('hello', 'w').write((str(i) * 4) + '\n')
248
247
            eq(anc, [None] + rev_ids[:i+1])
249
248
 
250
249
    def test_commit_new_subdir_child_selective(self):
251
 
        b = Branch.initialize('.')
 
250
        b = Branch.initialize(u'.')
252
251
        self.build_tree(['dir/', 'dir/file1', 'dir/file2'])
253
252
        b.working_tree().add(['dir', 'dir/file1', 'dir/file2'],
254
253
              ['dirid', 'file1id', 'file2id'])
262
261
    def test_strict_commit(self):
263
262
        """Try and commit with unknown files and strict = True, should fail."""
264
263
        from bzrlib.errors import StrictCommitFailed
265
 
        b = Branch.initialize('.')
 
264
        b = Branch.initialize(u'.')
266
265
        file('hello', 'w').write('hello world')
267
266
        b.working_tree().add('hello')
268
267
        file('goodbye', 'w').write('goodbye cruel world!')
273
272
        """Try and commit with no unknown files and strict = True,
274
273
        should work."""
275
274
        from bzrlib.errors import StrictCommitFailed
276
 
        b = Branch.initialize('.')
 
275
        b = Branch.initialize(u'.')
277
276
        file('hello', 'w').write('hello world')
278
277
        b.working_tree().add('hello')
279
278
        b.working_tree().commit(message='add hello', strict=True)
280
279
 
281
280
    def test_nonstrict_commit(self):
282
281
        """Try and commit with unknown files and strict = False, should work."""
283
 
        b = Branch.initialize('.')
 
282
        b = Branch.initialize(u'.')
284
283
        file('hello', 'w').write('hello world')
285
284
        b.working_tree().add('hello')
286
285
        file('goodbye', 'w').write('goodbye cruel world!')
289
288
    def test_nonstrict_commit_without_unknowns(self):
290
289
        """Try and commit with no unknown files and strict = False,
291
290
        should work."""
292
 
        b = Branch.initialize('.')
 
291
        b = Branch.initialize(u'.')
293
292
        file('hello', 'w').write('hello world')
294
293
        b.working_tree().add('hello')
295
294
        b.working_tree().commit(message='add hello', strict=False)
298
297
        import bzrlib.gpg
299
298
        import bzrlib.commit as commit
300
299
        oldstrategy = bzrlib.gpg.GPGStrategy
301
 
        branch = Branch.initialize('.')
 
300
        branch = Branch.initialize(u'.')
302
301
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
303
302
        self.failIf(branch.revision_store.has_id('A', 'sig'))
304
303
        try:
317
316
        import bzrlib.gpg
318
317
        import bzrlib.commit as commit
319
318
        oldstrategy = bzrlib.gpg.GPGStrategy
320
 
        branch = Branch.initialize('.')
 
319
        branch = Branch.initialize(u'.')
321
320
        branch.working_tree().commit("base", allow_pointless=True, rev_id='A')
322
321
        self.failIf(branch.revision_store.has_id('A', 'sig'))
323
322
        try:
330
329
                              branch, "base",
331
330
                              allow_pointless=True,
332
331
                              rev_id='B')
333
 
            branch = Branch.open('.')
 
332
            branch = Branch.open(u'.')
334
333
            self.assertEqual(branch.revision_history(), ['A'])
335
334
            self.failIf(branch.revision_store.has_id('B'))
336
335
        finally:
338
337
 
339
338
    def test_commit_invokes_hooks(self):
340
339
        import bzrlib.commit as commit
341
 
        branch = Branch.initialize('.')
 
340
        branch = Branch.initialize(u'.')
342
341
        calls = []
343
342
        def called(branch, rev_id):
344
343
            calls.append('called')