~lifeless/bzr/5158

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2008-08-05 09:43:41 UTC
  • Revision ID: robertc@robertcollins.net-20080805094341-uelcr4qz98trh2yj
Implement the oft-discussed automatic-add-and-delete at commit time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
 
92
92
class TestCommit(TestCaseWithWorkingTree):
93
93
 
 
94
    def test_commit_auto_add_delete(self):
 
95
        tree = self.make_branch_and_tree('.')
 
96
        self.build_tree(['foo', 'bar'])
 
97
        tree.add('foo')
 
98
        self.get_transport('.').delete('foo')
 
99
        tree.commit('do a commit', auto_add_delete=True)
 
100
        self.assertEqual(None, tree.path2id('foo'))
 
101
        self.assertNotEqual(None, tree.path2id('bar'))
 
102
 
 
103
    def test_commit_auto_add_directory(self):
 
104
        # ensure that the children of an auto added directory are added.
 
105
        tree = self.make_branch_and_tree('.')
 
106
        self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
 
107
        tree.commit('do a commit', auto_add_delete=True)
 
108
        self.assertNotEqual(None, tree.path2id('foo'))
 
109
        self.assertNotEqual(None, tree.path2id('foo/bar'))
 
110
        self.assertNotEqual(None, tree.path2id('foo/bar/baz'))
 
111
 
 
112
    def test_commit_auto_add_and_delete_strict_wins(self):
 
113
        tree = self.make_branch_and_tree('.')
 
114
        self.build_tree(['foo', 'bar'])
 
115
        tree.add('foo')
 
116
        # First with the unadded 'bar'
 
117
        self.assertRaises(errors.StrictCommitFailed, tree.commit, 'first post',
 
118
            auto_add_delete=True, strict=True)
 
119
        # Now with a deleted 'foo'
 
120
        tree.add('bar')
 
121
        self.get_transport('.').delete('foo')
 
122
        self.assertRaises(errors.StrictCommitFailed, tree.commit, 'first post',
 
123
            auto_add_delete=True, strict=True)
 
124
 
94
125
    def test_autodelete_renamed(self):
95
126
        tree_a = self.make_branch_and_tree('a')
96
127
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
102
133
        tree_a.rename_one('dir/f1', 'dir/a')
103
134
        tree_a.rename_one('dir/f2', 'dir/z')
104
135
        osutils.rmtree('a/dir')
105
 
        tree_a.commit('autoremoved')
 
136
        tree_a.commit('autoremoved', auto_add_delete=True)
106
137
 
107
138
        tree_a.lock_read()
108
139
        try:
123
154
        # Rename one entry out of this directory
124
155
        tree_a.rename_one('dir/f1', 'dir2/a')
125
156
        osutils.rmtree('a/dir')
126
 
        tree_a.commit('autoremoved')
 
157
        tree_a.commit('autoremoved', auto_add_delete=True)
127
158
 
128
159
        tree_a.lock_read()
129
160
        try:
155
186
        tree_b.add(['xyz'], ['xyz-id'])
156
187
        tree_b.rename_one('a/m', 'xyz/m')
157
188
        osutils.rmtree('B/a')
158
 
        tree_b.commit('delete in B')
 
189
        tree_b.commit('delete in B', auto_add_delete=True)
159
190
 
160
191
        paths = [(path, ie.file_id)
161
192
                 for path, ie in tree_b.iter_entries_by_dir()]
187
218
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
188
219
            # effect.
189
220
            pass
190
 
        tree_b.commit('autoremove a, without touching xyz/m')
 
221
        tree_b.commit('autoremove a, without touching xyz/m', auto_add_delete=True)
191
222
        paths = [(path, ie.file_id)
192
223
                 for path, ie in tree_b.iter_entries_by_dir()]
193
224
        self.assertEqual([('', root_id),
241
272
        self.assertEqual(1, len(changes))
242
273
        self.assertEqual((None, 'a/b'), changes[0][1])
243
274
 
 
275
    def test_commit_missing_error(self):
 
276
        tree = self.make_branch_and_tree('.')
 
277
        self.build_tree(['foo'])
 
278
        tree.add('foo')
 
279
        self.get_transport('.').delete('foo')
 
280
        self.assertRaises(errors.MissingFilesCommitFailed,
 
281
            tree.commit, 'do a commit')
 
282
 
244
283
    def test_commit_sets_last_revision(self):
245
284
        tree = self.make_branch_and_tree('tree')
246
285
        committed_id = tree.commit('foo', rev_id='foo')
354
393
        # now we have a tree with a through d in the inventory, but only
355
394
        # a present on disk. After commit b-id, c-id and d-id should be
356
395
        # missing from the inventory, within the same tree transaction.
357
 
        wt.commit('commit stuff')
 
396
        wt.commit('commit stuff', auto_add_delete=True)
358
397
        self.assertTrue(wt.has_id('a-id'))
359
398
        self.assertFalse(wt.has_or_had_id('b-id'))
360
399
        self.assertFalse(wt.has_or_had_id('c-id'))
387
426
        this_dir = self.get_transport()
388
427
        this_dir.delete_tree('b')
389
428
        wt.lock_write()
390
 
        wt.commit('commit deleted rename')
 
429
        wt.commit('commit deleted rename', auto_add_delete=True)
391
430
        self.assertTrue(wt.has_id('a-id'))
392
431
        self.assertFalse(wt.has_or_had_id('b-id'))
393
432
        self.assertFalse(wt.has_or_had_id('c-id'))