/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 breezy/git/tests/test_workingtree.py

Support Git rename tracking.

Merged from https://code.launchpad.net/~jelmer/brz/renames/+merge/381006

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import stat
24
24
 
 
25
from dulwich import __version__ as dulwich_version
 
26
from dulwich.diff_tree import RenameDetector
25
27
from dulwich.index import IndexEntry
26
28
from dulwich.objects import (
27
29
    S_IFGITLINK,
141
143
 
142
144
    def test_missing(self):
143
145
        delta = TreeDelta()
144
 
        delta.removed.append(TreeChange(b'git:a', ('a', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', None), (True, False)))
145
 
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
146
 
                    (b'a' * 40, b'a' * 40))]
 
146
        delta.removed.append(
 
147
            TreeChange(
 
148
                b'git:a', ('a', 'a'), False, (True, True),
 
149
                (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', None),
 
150
                (True, False)))
 
151
        changes = [
 
152
            ('remove',
 
153
                (b'a', stat.S_IFREG | 0o755, b'a' * 40),
 
154
                (b'a', 0, b'a' * 40))]
147
155
        self.assertEqual(
148
156
            delta,
149
157
            tree_delta_from_git_changes(changes, (default_mapping, default_mapping)))
158
166
 
159
167
    def expectDelta(self, expected_changes,
160
168
                    expected_extras=None, want_unversioned=False,
161
 
                    tree_id=None):
 
169
                    tree_id=None, rename_detector=None):
162
170
        if tree_id is None:
163
171
            try:
164
172
                tree_id = self.store[self.wt.branch.repository._git.head()].tree
166
174
                tree_id = None
167
175
        with self.wt.lock_read():
168
176
            changes, extras = changes_between_git_tree_and_working_copy(
169
 
                self.store, tree_id, self.wt, want_unversioned=want_unversioned)
 
177
                self.store, tree_id, self.wt, want_unversioned=want_unversioned,
 
178
                rename_detector=rename_detector)
170
179
            self.assertEqual(expected_changes, list(changes))
171
180
        if expected_extras is None:
172
181
            expected_extras = set()
174
183
 
175
184
    def test_empty(self):
176
185
        self.expectDelta(
177
 
            [((None, b''), (None, stat.S_IFDIR), (None, Tree().id))])
 
186
            [('add', (None, None, None), (b'', stat.S_IFDIR, Tree().id))])
178
187
 
179
188
    def test_added_file(self):
180
189
        self.build_tree(['a'])
183
192
        t = Tree()
184
193
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
185
194
        self.expectDelta(
186
 
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
187
 
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))])
 
195
            [('add', (None, None, None), (b'', stat.S_IFDIR, t.id)),
 
196
             ('add', (None, None, None), (b'a', stat.S_IFREG | 0o644, a.id))])
 
197
 
 
198
    def test_renamed_file(self):
 
199
        self.build_tree(['a'])
 
200
        self.wt.add(['a'])
 
201
        self.wt.rename_one('a', 'b')
 
202
        a = Blob.from_string(b'contents of a\n')
 
203
        self.store.add_object(a)
 
204
        oldt = Tree()
 
205
        oldt.add(b"a", stat.S_IFREG | 0o644, a.id)
 
206
        self.store.add_object(oldt)
 
207
        newt = Tree()
 
208
        newt.add(b"b", stat.S_IFREG | 0o644, a.id)
 
209
        self.store.add_object(newt)
 
210
        self.expectDelta(
 
211
            [('modify', (b'', stat.S_IFDIR, oldt.id), (b'', stat.S_IFDIR, newt.id)),
 
212
             ('delete', (b'a', stat.S_IFREG | 0o644, a.id), (None, None, None)),
 
213
             ('add', (None, None, None), (b'b', stat.S_IFREG | 0o644, a.id)),
 
214
             ],
 
215
            tree_id=oldt.id)
 
216
        if dulwich_version >= (0, 19, 15):
 
217
            self.expectDelta(
 
218
                [('modify', (b'', stat.S_IFDIR, oldt.id), (b'', stat.S_IFDIR, newt.id)),
 
219
                 ('rename', (b'a', stat.S_IFREG | 0o644, a.id), (b'b', stat.S_IFREG | 0o644, a.id))],
 
220
                tree_id=oldt.id, rename_detector=RenameDetector(self.store))
 
221
 
 
222
    def test_copied_file(self):
 
223
        self.build_tree(['a'])
 
224
        self.wt.add(['a'])
 
225
        self.wt.copy_one('a', 'b')
 
226
        a = Blob.from_string(b'contents of a\n')
 
227
        self.store.add_object(a)
 
228
        oldt = Tree()
 
229
        oldt.add(b"a", stat.S_IFREG | 0o644, a.id)
 
230
        self.store.add_object(oldt)
 
231
        newt = Tree()
 
232
        newt.add(b"a", stat.S_IFREG | 0o644, a.id)
 
233
        newt.add(b"b", stat.S_IFREG | 0o644, a.id)
 
234
        self.store.add_object(newt)
 
235
        self.expectDelta(
 
236
            [('modify', (b'', stat.S_IFDIR, oldt.id), (b'', stat.S_IFDIR, newt.id)),
 
237
             ('add', (None, None, None), (b'b', stat.S_IFREG | 0o644, a.id)),
 
238
             ],
 
239
            tree_id=oldt.id)
 
240
 
 
241
        if dulwich_version >= (0, 19, 15):
 
242
            self.expectDelta(
 
243
                [('modify', (b'', stat.S_IFDIR, oldt.id), (b'', stat.S_IFDIR, newt.id)),
 
244
                 ('copy', (b'a', stat.S_IFREG | 0o644, a.id), (b'b', stat.S_IFREG | 0o644, a.id))],
 
245
                tree_id=oldt.id, rename_detector=RenameDetector(self.store, find_copies_harder=True))
 
246
            self.expectDelta(
 
247
                [('modify', (b'', stat.S_IFDIR, oldt.id), (b'', stat.S_IFDIR, newt.id)),
 
248
                 ('add', (None, None, None), (b'b', stat.S_IFREG | 0o644, a.id)),
 
249
                 ],
 
250
                tree_id=oldt.id, rename_detector=RenameDetector(self.store, find_copies_harder=False))
188
251
 
189
252
    def test_added_unknown_file(self):
190
253
        self.build_tree(['a'])
191
254
        t = Tree()
192
255
        self.expectDelta(
193
 
            [((None, b''), (None, stat.S_IFDIR), (None, t.id))])
 
256
            [('add', (None, None, None), (b'', stat.S_IFDIR, t.id))])
194
257
        a = Blob.from_string(b'contents of a\n')
195
258
        t = Tree()
196
259
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
197
260
        self.expectDelta(
198
 
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
199
 
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
 
261
            [('add', (None, None, None), (b'', stat.S_IFDIR, t.id)),
 
262
             ('add', (None, None, None), (b'a', stat.S_IFREG | 0o644, a.id))],
200
263
            [b'a'],
201
264
            want_unversioned=True)
202
265
 
208
271
        t = Tree()
209
272
        t.add(b"a", 0, ZERO_SHA)
210
273
        self.expectDelta(
211
 
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
212
 
             ((None, b'a'), (None, 0), (None, ZERO_SHA))],
 
274
            [('add', (None, None, None), (b'', stat.S_IFDIR, t.id)),
 
275
             ('add', (None, None, None), (b'a', 0, ZERO_SHA))],
213
276
            [])
214
277
 
215
278
    def test_missing_versioned_file(self):
223
286
        newt = Tree()
224
287
        newt.add(b"a", 0, ZERO_SHA)
225
288
        self.expectDelta(
226
 
            [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
227
 
             ((b'a', b'a'), (stat.S_IFREG | 0o644, 0), (a.id, ZERO_SHA))])
 
289
            [('modify',
 
290
                (b'', stat.S_IFDIR, oldt.id),
 
291
                (b'', stat.S_IFDIR, newt.id)),
 
292
             ('modify',
 
293
                 (b'a', stat.S_IFREG | 0o644, a.id),
 
294
                 (b'a', 0, ZERO_SHA))])
228
295
 
229
296
    def test_versioned_replace_by_dir(self):
230
297
        self.build_tree(['a'])
239
306
        newa = Tree()
240
307
        newt.add(b"a", stat.S_IFDIR, newa.id)
241
308
        self.expectDelta([
242
 
            ((b'', b''),
243
 
             (stat.S_IFDIR, stat.S_IFDIR),
244
 
             (oldt.id, newt.id)),
245
 
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
 
309
            ('modify',
 
310
                (b'', stat.S_IFDIR, oldt.id),
 
311
                (b'', stat.S_IFDIR, newt.id)),
 
312
            ('modify',
 
313
                (b'a', stat.S_IFREG | 0o644, olda.id),
 
314
                (b'a', stat.S_IFDIR, newa.id))
246
315
            ], want_unversioned=False)
247
316
        self.expectDelta([
248
 
            ((b'', b''),
249
 
             (stat.S_IFDIR, stat.S_IFDIR),
250
 
             (oldt.id, newt.id)),
251
 
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
 
317
            ('modify',
 
318
                (b'', stat.S_IFDIR, oldt.id),
 
319
                (b'', stat.S_IFDIR, newt.id)),
 
320
            ('modify',
 
321
                (b'a', stat.S_IFREG | 0o644, olda.id),
 
322
                (b'a', stat.S_IFDIR, newa.id)),
252
323
            ], want_unversioned=True)
253
324
 
254
325
    def test_extra(self):
257
328
        newt = Tree()
258
329
        newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
259
330
        self.expectDelta([
260
 
            ((None, b''),
261
 
             (None, stat.S_IFDIR),
262
 
             (None, newt.id)),
263
 
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
 
331
            ('add',
 
332
                (None, None, None),
 
333
                (b'', stat.S_IFDIR, newt.id)),
 
334
            ('add',
 
335
                (None, None, None),
 
336
                (b'a', stat.S_IFREG | 0o644, newa.id)),
264
337
            ], [b'a'], want_unversioned=True)
265
338
 
266
339
    def test_submodule(self):