~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

[merge] refactoring of branch vs working tree, etc (robertc)

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        """Commit and check two versions of a single file."""
50
50
        b = Branch.initialize('.')
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
 
73
73
        """Test a commit with a deleted file"""
74
74
        b = Branch.initialize('.')
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')
86
86
        """Commit refuses unless there are changes or it's forced."""
87
87
        b = Branch.initialize('.')
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,
112
112
        b = Branch.initialize('.')
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
147
        b = Branch.initialize('.')
 
148
        tree = WorkingTree('.', 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
174
        b = Branch.initialize('.')
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"""
187
185
        b = Branch.initialize('.')
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'])],
 
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)
218
 
 
219
215
        
220
216
    def test_removed_commit(self):
221
217
        """Commit with a removed file"""
222
218
        b = Branch.initialize('.')
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')
227
223
 
228
224
        wt = b.working_tree()  # FIXME: kludge for aliasing of working inventory
240
236
        for i in range(4):
241
237
            file('hello', 'w').write((str(i) * 4) + '\n')
242
238
            if i == 0:
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),
254
250
    def test_commit_new_subdir_child_selective(self):
255
251
        b = Branch.initialize('.')
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')
268
264
        from bzrlib.errors import StrictCommitFailed
269
265
        b = Branch.initialize('.')
270
266
        file('hello', 'w').write('hello world')
271
 
        b.add('hello')
 
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)
279
275
        from bzrlib.errors import StrictCommitFailed
280
276
        b = Branch.initialize('.')
281
277
        file('hello', 'w').write('hello world')
282
 
        b.add('hello')
 
278
        b.working_tree().add('hello')
283
279
        b.working_tree().commit(message='add hello', strict=True)
284
280
 
285
281
    def test_nonstrict_commit(self):
286
282
        """Try and commit with unknown files and strict = False, should work."""
287
283
        b = Branch.initialize('.')
288
284
        file('hello', 'w').write('hello world')
289
 
        b.add('hello')
 
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)
292
288
 
295
291
        should work."""
296
292
        b = Branch.initialize('.')
297
293
        file('hello', 'w').write('hello world')
298
 
        b.add('hello')
 
294
        b.working_tree().add('hello')
299
295
        b.working_tree().commit(message='add hello', strict=False)
300
296
 
301
297
    def test_signed_commit(self):