/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

  • Committer: Jelmer Vernooij
  • Date: 2020-06-19 21:26:53 UTC
  • mfrom: (7490.40.19 work)
  • mto: This revision was merged to the branch mainline in revision 7516.
  • Revision ID: jelmer@jelmer.uk-20200619212653-7j6rgywzczhc8cmj
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

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