/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: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

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.index import IndexEntry
25
26
from dulwich.objects import (
 
27
    S_IFGITLINK,
26
28
    Blob,
27
29
    Tree,
28
30
    ZERO_SHA,
30
32
 
31
33
from ... import (
32
34
    conflicts as _mod_conflicts,
 
35
    workingtree as _mod_workingtree,
33
36
    )
34
37
from ...delta import TreeDelta
35
38
from ..mapping import (
57
60
 
58
61
    def test_conflict_list(self):
59
62
        self.assertIsInstance(
60
 
                self.tree.conflicts(),
61
 
                _mod_conflicts.ConflictList)
 
63
            self.tree.conflicts(),
 
64
            _mod_conflicts.ConflictList)
62
65
 
63
66
    def test_add_conflict(self):
64
67
        self.build_tree(['conflicted'])
65
68
        self.tree.add(['conflicted'])
66
69
        with self.tree.lock_tree_write():
67
 
            self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + (FLAG_STAGEMASK, )
 
70
            self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + \
 
71
                (FLAG_STAGEMASK, )
68
72
            self.tree._index_dirty = True
69
73
        conflicts = self.tree.conflicts()
70
74
        self.assertEqual(1, len(conflicts))
88
92
        self.assertTrue(self.tree.is_ignored('a'))
89
93
 
90
94
 
 
95
class GitWorkingTreeFileTests(TestCaseWithTransport):
 
96
 
 
97
    def setUp(self):
 
98
        super(GitWorkingTreeFileTests, self).setUp()
 
99
        self.tree = self.make_branch_and_tree('actual', format="git")
 
100
        self.build_tree_contents(
 
101
            [('linked/',), ('linked/.git', 'gitdir: ../actual/.git')])
 
102
        self.wt = _mod_workingtree.WorkingTree.open('linked')
 
103
 
 
104
    def test_add(self):
 
105
        self.build_tree(['linked/somefile'])
 
106
        self.wt.add(["somefile"])
 
107
        self.wt.commit("Add somefile")
 
108
 
 
109
 
91
110
class TreeDeltaFromGitChangesTests(TestCase):
92
111
 
93
112
    def test_empty(self):
96
115
        self.assertEqual(
97
116
            delta,
98
117
            tree_delta_from_git_changes(changes, default_mapping,
99
 
                (GitFileIdMap({}, default_mapping),
100
 
                 GitFileIdMap({}, default_mapping))))
 
118
                                        (GitFileIdMap({}, default_mapping),
 
119
                                         GitFileIdMap({}, default_mapping))))
101
120
 
102
121
    def test_missing(self):
103
122
        delta = TreeDelta()
104
123
        delta.removed.append(('a', b'a-id', 'file'))
105
 
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0), (b'a' * 40, b'a' * 40))]
 
124
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
 
125
                    (b'a' * 40, b'a' * 40))]
106
126
        self.assertEqual(
107
127
            delta,
108
128
            tree_delta_from_git_changes(changes, default_mapping,
109
 
                (GitFileIdMap({u'a': b'a-id'}, default_mapping),
110
 
                 GitFileIdMap({u'a': b'a-id'}, default_mapping))))
 
129
                                        (GitFileIdMap({u'a': b'a-id'}, default_mapping),
 
130
                                         GitFileIdMap({u'a': b'a-id'}, default_mapping))))
111
131
 
112
132
 
113
133
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
115
135
    def setUp(self):
116
136
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
117
137
        self.wt = self.make_branch_and_tree('.', format='git')
 
138
        self.store = self.wt.branch.repository._git.object_store
118
139
 
119
140
    def expectDelta(self, expected_changes,
120
 
                    expected_extras=None, want_unversioned=False):
121
 
        store = self.wt.branch.repository._git.object_store
122
 
        try:
123
 
            tree_id = store[self.wt.branch.repository._git.head()].tree
124
 
        except KeyError:
125
 
            tree_id = None
 
141
                    expected_extras=None, want_unversioned=False,
 
142
                    tree_id=None):
 
143
        if tree_id is None:
 
144
            try:
 
145
                tree_id = self.store[self.wt.branch.repository._git.head()].tree
 
146
            except KeyError:
 
147
                tree_id = None
126
148
        with self.wt.lock_read():
127
149
            changes, extras = changes_between_git_tree_and_working_copy(
128
 
                store, tree_id, self.wt, want_unversioned=want_unversioned)
 
150
                self.store, tree_id, self.wt, want_unversioned=want_unversioned)
129
151
            self.assertEqual(expected_changes, list(changes))
130
152
        if expected_extras is None:
131
153
            expected_extras = set()
182
204
        newt = Tree()
183
205
        newt.add(b"a", 0, ZERO_SHA)
184
206
        self.expectDelta(
185
 
                [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
186
 
                 ((b'a', b'a'), (stat.S_IFREG|0o644, 0), (a.id, ZERO_SHA))])
 
207
            [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
 
208
             ((b'a', b'a'), (stat.S_IFREG | 0o644, 0), (a.id, ZERO_SHA))])
187
209
 
188
210
    def test_versioned_replace_by_dir(self):
189
211
        self.build_tree(['a'])
199
221
        newt.add(b"a", stat.S_IFDIR, newa.id)
200
222
        self.expectDelta([
201
223
            ((b'', b''),
202
 
            (stat.S_IFDIR, stat.S_IFDIR),
203
 
            (oldt.id, newt.id)),
 
224
             (stat.S_IFDIR, stat.S_IFDIR),
 
225
             (oldt.id, newt.id)),
204
226
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
205
227
            ], want_unversioned=False)
206
228
        self.expectDelta([
207
229
            ((b'', b''),
208
 
            (stat.S_IFDIR, stat.S_IFDIR),
209
 
            (oldt.id, newt.id)),
 
230
             (stat.S_IFDIR, stat.S_IFDIR),
 
231
             (oldt.id, newt.id)),
210
232
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
211
233
            ], want_unversioned=True)
212
234
 
217
239
        newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
218
240
        self.expectDelta([
219
241
            ((None, b''),
220
 
            (None, stat.S_IFDIR),
221
 
            (None, newt.id)),
 
242
             (None, stat.S_IFDIR),
 
243
             (None, newt.id)),
222
244
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
223
245
            ], [b'a'], want_unversioned=True)
 
246
 
 
247
    def test_submodule(self):
 
248
        self.build_tree(['a/'])
 
249
        a = Blob.from_string(b'irrelevant\n')
 
250
        with self.wt.lock_tree_write():
 
251
            (index, index_path) = self.wt._lookup_index(b'a')
 
252
            index[b'a'] = IndexEntry(
 
253
                    0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0)
 
254
            self.wt._index_dirty = True
 
255
        t = Tree()
 
256
        t.add(b"a", S_IFGITLINK , a.id)
 
257
        self.store.add_object(t)
 
258
        self.expectDelta([], tree_id=t.id)