/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
2
# Copyright (C) 2011 Canonical Ltd.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
17
18
"""Tests for Git working trees."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
22
import os
23
import stat
24
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
25
from dulwich.index import IndexEntry
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
26
from dulwich.objects import (
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
27
    S_IFGITLINK,
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
28
    Blob,
29
    Tree,
30
    ZERO_SHA,
31
    )
32
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
33
from ... import (
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
34
    conflicts as _mod_conflicts,
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
35
    workingtree as _mod_workingtree,
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
36
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
37
from ...delta import TreeDelta
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
38
from ..mapping import (
39
    default_mapping,
40
    GitFileIdMap,
41
    )
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
42
from ..tree import (
43
    changes_between_git_tree_and_working_copy,
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
44
    tree_delta_from_git_changes,
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
45
    )
0.369.1 by Jelmer Vernooij
Implement conflict handling.
46
from ..workingtree import (
47
    FLAG_STAGEMASK,
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
48
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
49
from ...tests import (
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
50
    TestCase,
51
    TestCaseWithTransport,
52
    )
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
53
54
55
class GitWorkingTreeTests(TestCaseWithTransport):
56
57
    def setUp(self):
58
        super(GitWorkingTreeTests, self).setUp()
59
        self.tree = self.make_branch_and_tree('.', format="git")
60
0.369.1 by Jelmer Vernooij
Implement conflict handling.
61
    def test_conflict_list(self):
0.369.2 by Jelmer Vernooij
Fix tests.
62
        self.assertIsInstance(
7143.15.2 by Jelmer Vernooij
Run autopep8.
63
            self.tree.conflicts(),
64
            _mod_conflicts.ConflictList)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
65
66
    def test_add_conflict(self):
67
        self.build_tree(['conflicted'])
68
        self.tree.add(['conflicted'])
69
        with self.tree.lock_tree_write():
7143.15.2 by Jelmer Vernooij
Run autopep8.
70
            self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + \
71
                (FLAG_STAGEMASK, )
0.415.3 by Jelmer Vernooij
Open index on demand.
72
            self.tree._index_dirty = True
0.369.1 by Jelmer Vernooij
Implement conflict handling.
73
        conflicts = self.tree.conflicts()
74
        self.assertEqual(1, len(conflicts))
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
75
76
    def test_revert_empty(self):
77
        self.build_tree(['a'])
78
        self.tree.add(['a'])
79
        self.assertTrue(self.tree.is_versioned('a'))
80
        self.tree.revert(['a'])
81
        self.assertFalse(self.tree.is_versioned('a'))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
82
7065.1.1 by Jelmer Vernooij
Properly handle ignored directories in Git.
83
    def test_is_ignored_directory(self):
84
        self.assertFalse(self.tree.is_ignored('a'))
85
        self.build_tree(['a/'])
86
        self.assertFalse(self.tree.is_ignored('a'))
87
        self.build_tree_contents([('.gitignore', 'a\n')])
88
        self.tree._ignoremanager = None
89
        self.assertTrue(self.tree.is_ignored('a'))
90
        self.build_tree_contents([('.gitignore', 'a/\n')])
91
        self.tree._ignoremanager = None
92
        self.assertTrue(self.tree.is_ignored('a'))
93
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
94
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
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")
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
        self.build_tree_contents(
101
            [('linked/',), ('linked/.git', 'gitdir: ../actual/.git')])
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
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
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
110
class TreeDeltaFromGitChangesTests(TestCase):
111
112
    def test_empty(self):
113
        delta = TreeDelta()
114
        changes = []
115
        self.assertEqual(
116
            delta,
117
            tree_delta_from_git_changes(changes, default_mapping,
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
                                        (GitFileIdMap({}, default_mapping),
119
                                         GitFileIdMap({}, default_mapping))))
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
120
121
    def test_missing(self):
122
        delta = TreeDelta()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
123
        delta.removed.append(('a', b'a-id', 'file'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
125
                    (b'a' * 40, b'a' * 40))]
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
126
        self.assertEqual(
127
            delta,
128
            tree_delta_from_git_changes(changes, default_mapping,
7143.15.2 by Jelmer Vernooij
Run autopep8.
129
                                        (GitFileIdMap({u'a': b'a-id'}, default_mapping),
130
                                         GitFileIdMap({u'a': b'a-id'}, default_mapping))))
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
131
132
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
133
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
134
135
    def setUp(self):
136
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
137
        self.wt = self.make_branch_and_tree('.', format='git')
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
138
        self.store = self.wt.branch.repository._git.object_store
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
139
140
    def expectDelta(self, expected_changes,
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
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
0.415.3 by Jelmer Vernooij
Open index on demand.
148
        with self.wt.lock_read():
149
            changes, extras = changes_between_git_tree_and_working_copy(
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
150
                self.store, tree_id, self.wt, want_unversioned=want_unversioned)
0.415.3 by Jelmer Vernooij
Open index on demand.
151
            self.assertEqual(expected_changes, list(changes))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
152
        if expected_extras is None:
153
            expected_extras = set()
154
        self.assertEqual(set(expected_extras), set(extras))
155
156
    def test_empty(self):
157
        self.expectDelta(
7018.3.1 by Jelmer Vernooij
Fix git cache handling.
158
            [((None, b''), (None, stat.S_IFDIR), (None, Tree().id))])
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
159
160
    def test_added_file(self):
161
        self.build_tree(['a'])
162
        self.wt.add(['a'])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
163
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
164
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
165
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
166
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
167
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
168
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))])
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
169
170
    def test_added_unknown_file(self):
171
        self.build_tree(['a'])
172
        t = Tree()
173
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
174
            [((None, b''), (None, stat.S_IFDIR), (None, t.id))])
175
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
176
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
177
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
178
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
179
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
180
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
181
            [b'a'],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
182
            want_unversioned=True)
183
184
    def test_missing_added_file(self):
185
        self.build_tree(['a'])
186
        self.wt.add(['a'])
187
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
188
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
189
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
190
        t.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
191
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
192
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
193
             ((None, b'a'), (None, 0), (None, ZERO_SHA))],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
194
            [])
195
196
    def test_missing_versioned_file(self):
197
        self.build_tree(['a'])
198
        self.wt.add(['a'])
199
        self.wt.commit('')
200
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
201
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
202
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
203
        oldt.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
204
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
205
        newt.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
206
        self.expectDelta(
7143.15.2 by Jelmer Vernooij
Run autopep8.
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))])
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
209
210
    def test_versioned_replace_by_dir(self):
211
        self.build_tree(['a'])
212
        self.wt.add(['a'])
213
        self.wt.commit('')
214
        os.unlink('a')
215
        os.mkdir('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
216
        olda = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
217
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
218
        oldt.add(b"a", stat.S_IFREG | 0o644, olda.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
219
        newt = Tree()
220
        newa = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
221
        newt.add(b"a", stat.S_IFDIR, newa.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
222
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
223
            ((b'', b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
224
             (stat.S_IFDIR, stat.S_IFDIR),
225
             (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
226
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
227
            ], want_unversioned=False)
228
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
229
            ((b'', b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
230
             (stat.S_IFDIR, stat.S_IFDIR),
231
             (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
232
            ((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
233
            ], want_unversioned=True)
234
235
    def test_extra(self):
236
        self.build_tree(['a'])
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
237
        newa = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
238
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
239
        newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
240
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
241
            ((None, b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
242
             (None, stat.S_IFDIR),
243
             (None, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
244
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
245
            ], [b'a'], want_unversioned=True)
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
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():
7131.13.3 by Jelmer Vernooij
Fix python3 compatibility.
251
            (index, index_path) = self.wt._lookup_index(b'a')
7183.2.1 by Martin
Fix E999 lint error for Python 2 flake8
252
            index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0)
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
253
            self.wt._index_dirty = True
254
        t = Tree()
7183.2.1 by Martin
Fix E999 lint error for Python 2 flake8
255
        t.add(b"a", S_IFGITLINK, a.id)
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
256
        self.store.add_object(t)
257
        self.expectDelta([], tree_id=t.id)