/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: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
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))
87
91
        self.tree._ignoremanager = None
88
92
        self.assertTrue(self.tree.is_ignored('a'))
89
93
 
 
94
    def test_add_submodule_dir(self):
 
95
        subtree = self.make_branch_and_tree('asub', format='git')
 
96
        subtree.commit('Empty commit')
 
97
        self.tree.add(['asub'])
 
98
        with self.tree.lock_read():
 
99
            entry = self.tree.index[b'asub']
 
100
            self.assertEqual(entry.mode, S_IFGITLINK)
 
101
        self.assertEqual([], list(subtree.unknowns()))
 
102
 
 
103
    def test_add_submodule_file(self):
 
104
        os.mkdir('.git/modules')
 
105
        subbranch = self.make_branch('.git/modules/asub', format='git-bare')
 
106
        os.mkdir('asub')
 
107
        with open('asub/.git', 'w') as f:
 
108
            f.write('gitdir: ../.git/modules/asub\n')
 
109
        subtree = _mod_workingtree.WorkingTree.open('asub')
 
110
        subtree.commit('Empty commit')
 
111
        self.tree.add(['asub'])
 
112
        with self.tree.lock_read():
 
113
            entry = self.tree.index[b'asub']
 
114
            self.assertEqual(entry.mode, S_IFGITLINK)
 
115
        self.assertEqual([], list(subtree.unknowns()))
 
116
 
 
117
 
 
118
class GitWorkingTreeFileTests(TestCaseWithTransport):
 
119
 
 
120
    def setUp(self):
 
121
        super(GitWorkingTreeFileTests, self).setUp()
 
122
        self.tree = self.make_branch_and_tree('actual', format="git")
 
123
        self.build_tree_contents(
 
124
            [('linked/',), ('linked/.git', 'gitdir: ../actual/.git')])
 
125
        self.wt = _mod_workingtree.WorkingTree.open('linked')
 
126
 
 
127
    def test_add(self):
 
128
        self.build_tree(['linked/somefile'])
 
129
        self.wt.add(["somefile"])
 
130
        self.wt.commit("Add somefile")
 
131
 
90
132
 
91
133
class TreeDeltaFromGitChangesTests(TestCase):
92
134
 
96
138
        self.assertEqual(
97
139
            delta,
98
140
            tree_delta_from_git_changes(changes, default_mapping,
99
 
                (GitFileIdMap({}, default_mapping),
100
 
                 GitFileIdMap({}, default_mapping))))
 
141
                                        (GitFileIdMap({}, default_mapping),
 
142
                                         GitFileIdMap({}, default_mapping))))
101
143
 
102
144
    def test_missing(self):
103
145
        delta = TreeDelta()
104
146
        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))]
 
147
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
 
148
                    (b'a' * 40, b'a' * 40))]
106
149
        self.assertEqual(
107
150
            delta,
108
151
            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))))
 
152
                                        (GitFileIdMap({u'a': b'a-id'}, default_mapping),
 
153
                                         GitFileIdMap({u'a': b'a-id'}, default_mapping))))
111
154
 
112
155
 
113
156
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
115
158
    def setUp(self):
116
159
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
117
160
        self.wt = self.make_branch_and_tree('.', format='git')
 
161
        self.store = self.wt.branch.repository._git.object_store
118
162
 
119
163
    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
 
164
                    expected_extras=None, want_unversioned=False,
 
165
                    tree_id=None):
 
166
        if tree_id is None:
 
167
            try:
 
168
                tree_id = self.store[self.wt.branch.repository._git.head()].tree
 
169
            except KeyError:
 
170
                tree_id = None
126
171
        with self.wt.lock_read():
127
172
            changes, extras = changes_between_git_tree_and_working_copy(
128
 
                store, tree_id, self.wt, want_unversioned=want_unversioned)
 
173
                self.store, tree_id, self.wt, want_unversioned=want_unversioned)
129
174
            self.assertEqual(expected_changes, list(changes))
130
175
        if expected_extras is None:
131
176
            expected_extras = set()
182
227
        newt = Tree()
183
228
        newt.add(b"a", 0, ZERO_SHA)
184
229
        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))])
 
230
            [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
 
231
             ((b'a', b'a'), (stat.S_IFREG | 0o644, 0), (a.id, ZERO_SHA))])
187
232
 
188
233
    def test_versioned_replace_by_dir(self):
189
234
        self.build_tree(['a'])
199
244
        newt.add(b"a", stat.S_IFDIR, newa.id)
200
245
        self.expectDelta([
201
246
            ((b'', b''),
202
 
            (stat.S_IFDIR, stat.S_IFDIR),
203
 
            (oldt.id, newt.id)),
 
247
             (stat.S_IFDIR, stat.S_IFDIR),
 
248
             (oldt.id, newt.id)),
204
249
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
205
250
            ], want_unversioned=False)
206
251
        self.expectDelta([
207
252
            ((b'', b''),
208
 
            (stat.S_IFDIR, stat.S_IFDIR),
209
 
            (oldt.id, newt.id)),
 
253
             (stat.S_IFDIR, stat.S_IFDIR),
 
254
             (oldt.id, newt.id)),
210
255
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
211
256
            ], want_unversioned=True)
212
257
 
217
262
        newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
218
263
        self.expectDelta([
219
264
            ((None, b''),
220
 
            (None, stat.S_IFDIR),
221
 
            (None, newt.id)),
 
265
             (None, stat.S_IFDIR),
 
266
             (None, newt.id)),
222
267
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
223
268
            ], [b'a'], want_unversioned=True)
 
269
 
 
270
    def test_submodule(self):
 
271
        self.build_tree(['a/'])
 
272
        a = Blob.from_string(b'irrelevant\n')
 
273
        with self.wt.lock_tree_write():
 
274
            (index, index_path) = self.wt._lookup_index(b'a')
 
275
            index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0)
 
276
            self.wt._index_dirty = True
 
277
        t = Tree()
 
278
        t.add(b"a", S_IFGITLINK, a.id)
 
279
        self.store.add_object(t)
 
280
        self.expectDelta([], tree_id=t.id)