~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

  • Committer: Robert Collins
  • Date: 2005-11-07 20:29:51 UTC
  • mfrom: (1457.1.17)
  • Revision ID: robertc@robertcollins.net-20051107202951-6ae936c7a3e57f6f
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        b = Branch.initialize('.')
51
51
        file('hello', 'w').write('hello world')
52
52
        b.add('hello')
53
 
        b.commit(message='add hello')
 
53
        b.working_tree().commit(message='add hello')
54
54
        file_id = b.working_tree().path2id('hello')
55
55
 
56
56
        file('hello', 'w').write('version 2')
57
 
        b.commit(message='commit 2')
 
57
        b.working_tree().commit(message='commit 2')
58
58
 
59
59
        eq = self.assertEquals
60
60
        eq(b.revno(), 2)
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')
78
78
 
79
79
        os.remove('hello')
80
 
        b.commit('removed hello', rev_id='rev2')
 
80
        b.working_tree().commit('removed hello', rev_id='rev2')
81
81
 
82
82
        tree = b.revision_tree('rev2')
83
83
        self.assertFalse(tree.has_id('hello-id'))
84
84
 
85
 
 
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')
90
89
        b.add(['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,
94
 
                          b.commit,
 
93
                          b.working_tree().commit,
95
94
                          message='fails',
96
95
                          allow_pointless=False)
97
96
        self.assertEquals(b.revno(), 1)
98
97
        
99
 
 
100
 
 
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,
106
 
                          b.commit,
 
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)
111
108
 
112
109
 
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')
122
119
        
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')
129
126
 
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)
154
151
 
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)
157
154
 
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,
180
 
                          b.commit,
 
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)
195
192
 
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'])
201
198
 
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'])
216
213
 
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')
230
227
 
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')
234
231
 
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),
250
247
                     rev_id=rev_id)
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')
274
271
        b.add('hello')
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)
278
275
 
279
276
    def test_strict_commit_without_unknowns(self):
283
280
        b = Branch.initialize('.')
284
281
        file('hello', 'w').write('hello world')
285
282
        b.add('hello')
286
 
        b.commit(message='add hello', strict=True)
 
283
        b.working_tree().commit(message='add hello', strict=True)
287
284
 
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')
292
289
        b.add('hello')
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)
295
292
 
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')
301
298
        b.add('hello')
302
 
        b.commit(message='add hello', strict=False)
 
299
        b.working_tree().commit(message='add hello', strict=False)
303
300
 
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'))
311
308
        try:
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'))
330
327
        try:
331
328
            from bzrlib.testament import Testament