~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_commit.py

  • Committer: NamNguyen
  • Date: 2007-08-15 09:06:32 UTC
  • mto: (2789.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2790.
  • Revision ID: namnguyen-20070815090632-w0xcl6t5if19m2oj
branch_implementations/test_commit.py:

  * renamed test_pre_commit_paths to test_pre_commit_ids
  * added cases for ``added``, ``deleted``, ``renamed``, ``modified``, and
    ``modified and renamed``

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
    def capture_pre_commit_hook(self, local, master, old_revno, old_revid,
63
63
                                new_revno, new_revid, affected, tree):
64
 
        # replacing ids with paths
65
 
        # notice that we leave deleted ids in tact
66
 
        for change, ids in affected.iteritems():
67
 
            if change == 'deleted':
68
 
                continue
69
 
            for i, id in enumerate(ids):
70
 
                ids[i] = tree.id2path(id)
71
64
        self.hook_calls.append(('pre_commit', old_revno, old_revid,
72
65
                                new_revno, new_revid, affected))
73
66
 
169
162
            self.hook_calls)
170
163
        tree.unlock()
171
164
    
172
 
    def test_pre_commit_paths(self):
173
 
        tree = self.make_branch_and_memory_tree('branch')
 
165
    def test_pre_commit_ids(self):
 
166
        self.build_tree(['rootfile', 'dir/', 'dir/subfile'])
 
167
        tree = self.make_branch_and_tree('.')
174
168
        tree.lock_write()
175
 
        tree.add('')
176
 
        tree.add('file', 'bang')
177
 
        tree.put_file_bytes_non_atomic('bang', 'die')
178
 
        tree.mkdir('dir', 'dirid')
179
 
        tree.add('dir/file', 'swoosh')
180
 
        tree.put_file_bytes_non_atomic('swoosh', 'swaash')
 
169
        tree.set_root_id('root_id')
 
170
        tree.add('rootfile', 'rootfile_id')
 
171
        tree.put_file_bytes_non_atomic('rootfile_id', 'abc')
 
172
        tree.add('dir', 'dir_id')
 
173
        tree.add('dir/subfile', 'dir_subfile_id')
 
174
        tree.put_file_bytes_non_atomic('dir_subfile_id', 'def')
181
175
        Branch.hooks.install_hook("pre_commit", self.capture_pre_commit_hook)
182
176
        rev1 = tree.commit('first revision')
183
 
        tree.unversion(['dirid'])
 
177
        tree.unversion(['dir_id'])
184
178
        rev2 = tree.commit('second revision')
 
179
        tree.put_file_bytes_non_atomic('rootfile_id', 'ghi')
 
180
        rev3 = tree.commit('third revision')
 
181
        tree.unlock()
 
182
        tree.lock_write()
 
183
        tree.rename_one('rootfile', 'renamed')
 
184
        rev4 = tree.commit('fourth revision')
 
185
        tree.unlock()
 
186
        tree.lock_write()
 
187
        tree.put_file_bytes_non_atomic('rootfile_id', 'jkl')
 
188
        tree.rename_one('renamed', 'rootfile')
 
189
        rev5 = tree.commit('fifth revision')
 
190
        tree.unlock()
185
191
        self.assertEqual([
186
192
            ('pre_commit', 0, NULL_REVISION, 1, rev1,
187
 
             {'added': ['dir', 'dir/file', 'file']} ),
 
193
             {'added': ['dir_id', 'dir_subfile_id', 'rootfile_id']} ),
188
194
            ('pre_commit', 1, rev1, 2, rev2,
189
 
             {'deleted': ['dirid', 'swoosh']} )
 
195
             {'deleted': ['dir_id', 'dir_subfile_id']} ),
 
196
            ('pre_commit', 2, rev2, 3, rev3,
 
197
             {'modified': ['rootfile_id']} ),
 
198
            ('pre_commit', 3, rev3, 4, rev4,
 
199
             {'renamed': ['rootfile_id']} ),
 
200
            ('pre_commit', 4, rev4, 5, rev5,
 
201
             {'modified and renamed': ['rootfile_id']} )
190
202
            ],
191
203
            self.hook_calls)
192
 
        tree.unlock()