/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/workingtree_implementations/test_commit.py

  • Committer: Robert Collins
  • Date: 2007-11-05 19:40:28 UTC
  • mfrom: (2963 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2967.
  • Revision ID: robertc@robertcollins.net-20071105194028-5gc6rdajk96maaq1
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib import (
22
22
    branch,
23
23
    bzrdir,
 
24
    conflicts,
24
25
    errors,
 
26
    osutils,
25
27
    revision as _mod_revision,
26
28
    ui,
27
29
    uncommit,
29
31
    )
30
32
from bzrlib.errors import (NotBranchError, NotVersionedError, 
31
33
                           UnsupportedOperation)
32
 
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
33
 
from bzrlib.tests import TestSkipped, TestCase
 
34
from bzrlib.osutils import pathjoin, getcwd
 
35
from bzrlib.tests import TestCase
34
36
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
35
37
from bzrlib.trace import mutter
36
38
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
88
90
 
89
91
class TestCommit(TestCaseWithWorkingTree):
90
92
 
 
93
    def test_autodelete_renamed(self):
 
94
        tree_a = self.make_branch_and_tree('a')
 
95
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2'])
 
96
        tree_a.add(['dir', 'dir/f1', 'dir/f2'], ['dir-id', 'f1-id', 'f2-id'])
 
97
        rev_id1 = tree_a.commit('init')
 
98
        # Start off by renaming entries,
 
99
        # but then actually auto delete the whole tree
 
100
        # https://bugs.launchpad.net/bzr/+bug/114615
 
101
        tree_a.rename_one('dir/f1', 'dir/a')
 
102
        tree_a.rename_one('dir/f2', 'dir/z')
 
103
        osutils.rmtree('a/dir')
 
104
        tree_a.commit('autoremoved')
 
105
 
 
106
        tree_a.lock_read()
 
107
        try:
 
108
            root_id = tree_a.inventory.root.file_id
 
109
            paths = [(path, ie.file_id)
 
110
                     for path, ie in tree_a.iter_entries_by_dir()]
 
111
        finally:
 
112
            tree_a.unlock()
 
113
        # The only paths left should be the root
 
114
        self.assertEqual([('', root_id)], paths)
 
115
 
 
116
    def test_no_autodelete_renamed_away(self):
 
117
        tree_a = self.make_branch_and_tree('a')
 
118
        self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
 
119
        tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'],
 
120
                   ['dir-id', 'f1-id', 'f2-id', 'dir2-id'])
 
121
        rev_id1 = tree_a.commit('init')
 
122
        # Rename one entry out of this directory
 
123
        tree_a.rename_one('dir/f1', 'dir2/a')
 
124
        osutils.rmtree('a/dir')
 
125
        tree_a.commit('autoremoved')
 
126
 
 
127
        tree_a.lock_read()
 
128
        try:
 
129
            root_id = tree_a.inventory.root.file_id
 
130
            paths = [(path, ie.file_id)
 
131
                     for path, ie in tree_a.iter_entries_by_dir()]
 
132
        finally:
 
133
            tree_a.unlock()
 
134
        # The only paths left should be the root
 
135
        self.assertEqual([('', root_id), ('dir2', 'dir2-id'),
 
136
                          ('dir2/a', 'f1-id'),
 
137
                         ], paths)
 
138
 
 
139
    def test_no_autodelete_alternate_renamed(self):
 
140
        # Test for bug #114615
 
141
        tree_a = self.make_branch_and_tree('A')
 
142
        self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
 
143
        tree_a.add(['a', 'a/m', 'a/n'], ['a-id', 'm-id', 'n-id'])
 
144
        tree_a.commit('init')
 
145
 
 
146
        tree_a.lock_read()
 
147
        try:
 
148
            root_id = tree_a.inventory.root.file_id
 
149
        finally:
 
150
            tree_a.unlock()
 
151
 
 
152
        tree_b = tree_a.bzrdir.sprout('B').open_workingtree()
 
153
        self.build_tree(['B/xyz/'])
 
154
        tree_b.add(['xyz'], ['xyz-id'])
 
155
        tree_b.rename_one('a/m', 'xyz/m')
 
156
        osutils.rmtree('B/a')
 
157
        tree_b.commit('delete in B')
 
158
 
 
159
        paths = [(path, ie.file_id)
 
160
                 for path, ie in tree_b.iter_entries_by_dir()]
 
161
        self.assertEqual([('', root_id),
 
162
                          ('xyz', 'xyz-id'),
 
163
                          ('xyz/m', 'm-id'),
 
164
                         ], paths)
 
165
 
 
166
        self.build_tree_contents([('A/a/n', 'new contents for n\n')])
 
167
        tree_a.commit('change n in A')
 
168
 
 
169
        # Merging from A should introduce conflicts because 'n' was modified
 
170
        # and removed, so 'a' needs to be restored.
 
171
        num_conflicts = tree_b.merge_from_branch(tree_a.branch)
 
172
        self.assertEqual(3, num_conflicts)
 
173
        paths = [(path, ie.file_id)
 
174
                 for path, ie in tree_b.iter_entries_by_dir()]
 
175
        self.assertEqual([('', root_id),
 
176
                          ('a', 'a-id'),
 
177
                          ('xyz', 'xyz-id'),
 
178
                          ('a/n.OTHER', 'n-id'),
 
179
                          ('xyz/m', 'm-id'),
 
180
                         ], paths)
 
181
        osutils.rmtree('B/a')
 
182
        try:
 
183
            # bzr resolve --all
 
184
            tree_b.set_conflicts(conflicts.ConflictList())
 
185
        except errors.UnsupportedOperation:
 
186
            # On WT2, set_conflicts is unsupported, but the rmtree has the same
 
187
            # effect.
 
188
            pass
 
189
        tree_b.commit('autoremove a, without touching xyz/m')
 
190
        paths = [(path, ie.file_id)
 
191
                 for path, ie in tree_b.iter_entries_by_dir()]
 
192
        self.assertEqual([('', root_id),
 
193
                          ('xyz', 'xyz-id'),
 
194
                          ('xyz/m', 'm-id'),
 
195
                         ], paths)
 
196
 
91
197
    def test_commit_sets_last_revision(self):
92
198
        tree = self.make_branch_and_tree('tree')
93
199
        committed_id = tree.commit('foo', rev_id='foo')