~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commit.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-28 12:47:17 UTC
  • mfrom: (6437.3.28 2.5)
  • mto: This revision was merged to the branch mainline in revision 6451.
  • Revision ID: jelmer@canonical.com-20120128124717-80ggi7q1y7m2wjf0
MergeĀ 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        """Commit and check two versions of a single file."""
83
83
        wt = self.make_branch_and_tree('.')
84
84
        b = wt.branch
85
 
        file('hello', 'w').write('hello world')
 
85
        with file('hello', 'w') as f: f.write('hello world')
86
86
        wt.add('hello')
87
87
        rev1 = wt.commit(message='add hello')
88
88
        file_id = wt.path2id('hello')
89
89
 
90
 
        file('hello', 'w').write('version 2')
 
90
        with file('hello', 'w') as f: f.write('version 2')
91
91
        rev2 = wt.commit(message='commit 2')
92
92
 
93
93
        eq = self.assertEquals
111
111
        """Attempt a lossy commit to a native branch."""
112
112
        wt = self.make_branch_and_tree('.')
113
113
        b = wt.branch
114
 
        file('hello', 'w').write('hello world')
 
114
        with file('hello', 'w') as f: f.write('hello world')
115
115
        wt.add('hello')
116
116
        revid = wt.commit(message='add hello', rev_id='revid', lossy=True)
117
117
        self.assertEquals('revid', revid)
122
122
        wt = self.make_branch_and_tree('.',
123
123
            format=test_foreign.DummyForeignVcsDirFormat())
124
124
        b = wt.branch
125
 
        file('hello', 'w').write('hello world')
 
125
        with file('hello', 'w') as f: f.write('hello world')
126
126
        wt.add('hello')
127
127
        revid = wt.commit(message='add hello', lossy=True,
128
128
            timestamp=1302659388, timezone=0)
135
135
            format=test_foreign.DummyForeignVcsDirFormat())
136
136
        wt = foreign_branch.create_checkout("local")
137
137
        b = wt.branch
138
 
        file('local/hello', 'w').write('hello world')
 
138
        with file('local/hello', 'w') as f: f.write('hello world')
139
139
        wt.add('hello')
140
140
        revid = wt.commit(message='add hello', lossy=True,
141
141
            timestamp=1302659388, timezone=0)
149
149
        """Test a commit with a missing file"""
150
150
        wt = self.make_branch_and_tree('.')
151
151
        b = wt.branch
152
 
        file('hello', 'w').write('hello world')
 
152
        with file('hello', 'w') as f: f.write('hello world')
153
153
        wt.add(['hello'], ['hello-id'])
154
154
        wt.commit(message='add hello')
155
155
 
187
187
        """Commit refuses unless there are changes or it's forced."""
188
188
        wt = self.make_branch_and_tree('.')
189
189
        b = wt.branch
190
 
        file('hello', 'w').write('hello')
 
190
        with file('hello', 'w') as f: f.write('hello')
191
191
        wt.add(['hello'])
192
192
        wt.commit(message='add hello')
193
193
        self.assertEquals(b.revno(), 1)
213
213
        """Selective commit in tree with deletions"""
214
214
        wt = self.make_branch_and_tree('.')
215
215
        b = wt.branch
216
 
        file('hello', 'w').write('hello')
217
 
        file('buongia', 'w').write('buongia')
 
216
        with file('hello', 'w') as f: f.write('hello')
 
217
        with file('buongia', 'w') as f: f.write('buongia')
218
218
        wt.add(['hello', 'buongia'],
219
219
              ['hello-id', 'buongia-id'])
220
220
        wt.commit(message='add files',
221
221
                 rev_id='test@rev-1')
222
222
 
223
223
        os.remove('hello')
224
 
        file('buongia', 'w').write('new text')
 
224
        with file('buongia', 'w') as f: f.write('new text')
225
225
        wt.commit(message='update text',
226
226
                 specific_files=['buongia'],
227
227
                 allow_pointless=False,
336
336
        """Commit with a removed file"""
337
337
        wt = self.make_branch_and_tree('.')
338
338
        b = wt.branch
339
 
        file('hello', 'w').write('hello world')
 
339
        with file('hello', 'w') as f: f.write('hello world')
340
340
        wt.add(['hello'], ['hello-id'])
341
341
        wt.commit(message='add hello')
342
342
        wt.remove('hello')
351
351
        b = wt.branch
352
352
        rev_ids = []
353
353
        for i in range(4):
354
 
            file('hello', 'w').write((str(i) * 4) + '\n')
 
354
            with file('hello', 'w') as f: f.write((str(i) * 4) + '\n')
355
355
            if i == 0:
356
356
                wt.add(['hello'], ['hello-id'])
357
357
            rev_id = 'test@rev-%d' % (i+1)
380
380
        from bzrlib.errors import StrictCommitFailed
381
381
        wt = self.make_branch_and_tree('.')
382
382
        b = wt.branch
383
 
        file('hello', 'w').write('hello world')
 
383
        with file('hello', 'w') as f: f.write('hello world')
384
384
        wt.add('hello')
385
 
        file('goodbye', 'w').write('goodbye cruel world!')
 
385
        with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
386
386
        self.assertRaises(StrictCommitFailed, wt.commit,
387
387
            message='add hello but not goodbye', strict=True)
388
388
 
391
391
        should work."""
392
392
        wt = self.make_branch_and_tree('.')
393
393
        b = wt.branch
394
 
        file('hello', 'w').write('hello world')
 
394
        with file('hello', 'w') as f: f.write('hello world')
395
395
        wt.add('hello')
396
396
        wt.commit(message='add hello', strict=True)
397
397
 
399
399
        """Try and commit with unknown files and strict = False, should work."""
400
400
        wt = self.make_branch_and_tree('.')
401
401
        b = wt.branch
402
 
        file('hello', 'w').write('hello world')
 
402
        with file('hello', 'w') as f: f.write('hello world')
403
403
        wt.add('hello')
404
 
        file('goodbye', 'w').write('goodbye cruel world!')
 
404
        with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
405
405
        wt.commit(message='add hello but not goodbye', strict=False)
406
406
 
407
407
    def test_nonstrict_commit_without_unknowns(self):
409
409
        should work."""
410
410
        wt = self.make_branch_and_tree('.')
411
411
        b = wt.branch
412
 
        file('hello', 'w').write('hello world')
 
412
        with file('hello', 'w') as f: f.write('hello world')
413
413
        wt.add('hello')
414
414
        wt.commit(message='add hello', strict=False)
415
415