/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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
 
22
    bzrdir,
22
23
    config,
23
 
    controldir,
24
24
    errors,
25
25
    )
26
26
from bzrlib.branch import Branch
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
 
        with file('hello', 'w') as f: f.write('hello world')
 
85
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('version 2')
 
90
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
114
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
125
        file('hello', 'w').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
 
        with file('local/hello', 'w') as f: f.write('hello world')
 
138
        file('local/hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
152
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello')
 
190
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello')
217
 
        with file('buongia', 'w') as f: f.write('buongia')
 
216
        file('hello', 'w').write('hello')
 
217
        file('buongia', 'w').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
 
        with file('buongia', 'w') as f: f.write('new text')
 
224
        file('buongia', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
339
        file('hello', 'w').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
 
            with file('hello', 'w') as f: f.write((str(i) * 4) + '\n')
 
354
            file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
383
        file('hello', 'w').write('hello world')
384
384
        wt.add('hello')
385
 
        with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
385
        file('goodbye', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
394
        file('hello', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
402
        file('hello', 'w').write('hello world')
403
403
        wt.add('hello')
404
 
        with file('goodbye', 'w') as f: f.write('goodbye cruel world!')
 
404
        file('goodbye', 'w').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
 
        with file('hello', 'w') as f: f.write('hello world')
 
412
        file('hello', 'w').write('hello world')
413
413
        wt.add('hello')
414
414
        wt.commit(message='add hello', strict=False)
415
415
 
835
835
    def test_commit_with_checkout_and_branch_sharing_repo(self):
836
836
        repo = self.make_repository('repo', shared=True)
837
837
        # make_branch_and_tree ignores shared repos
838
 
        branch = controldir.ControlDir.create_branch_convenience('repo/branch')
 
838
        branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
839
839
        tree2 = branch.create_checkout('repo/tree2')
840
840
        tree2.commit('message', rev_id='rev1')
841
841
        self.assertTrue(tree2.branch.repository.has_revision('rev1'))