~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_commit.py

[patch] 'bzr init DIR' (John)

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