/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,
35
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
36
from ...delta import TreeDelta
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
37
from ..mapping import (
38
    default_mapping,
39
    GitFileIdMap,
40
    )
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
41
from ..tree import (
42
    changes_between_git_tree_and_working_copy,
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
43
    tree_delta_from_git_changes,
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
44
    )
0.369.1 by Jelmer Vernooij
Implement conflict handling.
45
from ..workingtree import (
46
    FLAG_STAGEMASK,
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
47
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
48
from ...tests import (
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
49
    TestCase,
50
    TestCaseWithTransport,
51
    )
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
52
53
54
class GitWorkingTreeTests(TestCaseWithTransport):
55
56
    def setUp(self):
57
        super(GitWorkingTreeTests, self).setUp()
58
        self.tree = self.make_branch_and_tree('.', format="git")
59
0.369.1 by Jelmer Vernooij
Implement conflict handling.
60
    def test_conflict_list(self):
0.369.2 by Jelmer Vernooij
Fix tests.
61
        self.assertIsInstance(
62
                self.tree.conflicts(),
63
                _mod_conflicts.ConflictList)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
64
65
    def test_add_conflict(self):
66
        self.build_tree(['conflicted'])
67
        self.tree.add(['conflicted'])
68
        with self.tree.lock_tree_write():
7018.3.2 by Jelmer Vernooij
Fix some git tests.
69
            self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + (FLAG_STAGEMASK, )
0.415.3 by Jelmer Vernooij
Open index on demand.
70
            self.tree._index_dirty = True
0.369.1 by Jelmer Vernooij
Implement conflict handling.
71
        conflicts = self.tree.conflicts()
72
        self.assertEqual(1, len(conflicts))
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
73
74
    def test_revert_empty(self):
75
        self.build_tree(['a'])
76
        self.tree.add(['a'])
77
        self.assertTrue(self.tree.is_versioned('a'))
78
        self.tree.revert(['a'])
79
        self.assertFalse(self.tree.is_versioned('a'))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
80
7065.1.1 by Jelmer Vernooij
Properly handle ignored directories in Git.
81
    def test_is_ignored_directory(self):
82
        self.assertFalse(self.tree.is_ignored('a'))
83
        self.build_tree(['a/'])
84
        self.assertFalse(self.tree.is_ignored('a'))
85
        self.build_tree_contents([('.gitignore', 'a\n')])
86
        self.tree._ignoremanager = None
87
        self.assertTrue(self.tree.is_ignored('a'))
88
        self.build_tree_contents([('.gitignore', 'a/\n')])
89
        self.tree._ignoremanager = None
90
        self.assertTrue(self.tree.is_ignored('a'))
91
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
92
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
93
class TreeDeltaFromGitChangesTests(TestCase):
94
95
    def test_empty(self):
96
        delta = TreeDelta()
97
        changes = []
98
        self.assertEqual(
99
            delta,
100
            tree_delta_from_git_changes(changes, default_mapping,
101
                (GitFileIdMap({}, default_mapping),
102
                 GitFileIdMap({}, default_mapping))))
103
104
    def test_missing(self):
105
        delta = TreeDelta()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
106
        delta.removed.append(('a', b'a-id', 'file'))
7018.3.1 by Jelmer Vernooij
Fix git cache handling.
107
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0), (b'a' * 40, b'a' * 40))]
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
108
        self.assertEqual(
109
            delta,
110
            tree_delta_from_git_changes(changes, default_mapping,
7018.3.2 by Jelmer Vernooij
Fix some git tests.
111
                (GitFileIdMap({u'a': b'a-id'}, default_mapping),
112
                 GitFileIdMap({u'a': b'a-id'}, default_mapping))))
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
113
114
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
115
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
116
117
    def setUp(self):
118
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
119
        self.wt = self.make_branch_and_tree('.', format='git')
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
120
        self.store = self.wt.branch.repository._git.object_store
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
121
122
    def expectDelta(self, expected_changes,
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
123
                    expected_extras=None, want_unversioned=False,
124
                    tree_id=None):
125
        if tree_id is None:
126
            try:
127
                tree_id = self.store[self.wt.branch.repository._git.head()].tree
128
            except KeyError:
129
                tree_id = None
0.415.3 by Jelmer Vernooij
Open index on demand.
130
        with self.wt.lock_read():
131
            changes, extras = changes_between_git_tree_and_working_copy(
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
132
                self.store, tree_id, self.wt, want_unversioned=want_unversioned)
0.415.3 by Jelmer Vernooij
Open index on demand.
133
            self.assertEqual(expected_changes, list(changes))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
134
        if expected_extras is None:
135
            expected_extras = set()
136
        self.assertEqual(set(expected_extras), set(extras))
137
138
    def test_empty(self):
139
        self.expectDelta(
7018.3.1 by Jelmer Vernooij
Fix git cache handling.
140
            [((None, b''), (None, stat.S_IFDIR), (None, Tree().id))])
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
141
142
    def test_added_file(self):
143
        self.build_tree(['a'])
144
        self.wt.add(['a'])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
145
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
146
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
147
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
148
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
149
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
150
             ((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.
151
152
    def test_added_unknown_file(self):
153
        self.build_tree(['a'])
154
        t = Tree()
155
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
156
            [((None, b''), (None, stat.S_IFDIR), (None, t.id))])
157
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
158
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
159
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
160
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
161
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
162
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
163
            [b'a'],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
164
            want_unversioned=True)
165
166
    def test_missing_added_file(self):
167
        self.build_tree(['a'])
168
        self.wt.add(['a'])
169
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
170
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
171
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
172
        t.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
173
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
174
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
175
             ((None, b'a'), (None, 0), (None, ZERO_SHA))],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
176
            [])
177
178
    def test_missing_versioned_file(self):
179
        self.build_tree(['a'])
180
        self.wt.add(['a'])
181
        self.wt.commit('')
182
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
183
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
184
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
185
        oldt.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
186
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
187
        newt.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
188
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
189
                [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
190
                 ((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.
191
192
    def test_versioned_replace_by_dir(self):
193
        self.build_tree(['a'])
194
        self.wt.add(['a'])
195
        self.wt.commit('')
196
        os.unlink('a')
197
        os.mkdir('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
198
        olda = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
199
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
200
        oldt.add(b"a", stat.S_IFREG | 0o644, olda.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
201
        newt = Tree()
202
        newa = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
203
        newt.add(b"a", stat.S_IFDIR, newa.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
204
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
205
            ((b'', b''),
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
206
            (stat.S_IFDIR, stat.S_IFDIR),
207
            (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
208
            ((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.
209
            ], want_unversioned=False)
210
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
211
            ((b'', b''),
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
212
            (stat.S_IFDIR, stat.S_IFDIR),
213
            (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
214
            ((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.
215
            ], want_unversioned=True)
216
217
    def test_extra(self):
218
        self.build_tree(['a'])
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
219
        newa = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
220
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
221
        newt.add(b"a", stat.S_IFREG | 0o644, 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
            ((None, b''),
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
224
            (None, stat.S_IFDIR),
225
            (None, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
226
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
227
            ], [b'a'], want_unversioned=True)
7131.13.1 by Jelmer Vernooij
Don't show a delta for unchanged submodules.
228
229
    def test_submodule(self):
230
        self.build_tree(['a/'])
231
        a = Blob.from_string(b'irrelevant\n')
232
        with self.wt.lock_tree_write():
233
            (index, index_path) = self.wt._lookup_index('a')
234
            index[b'a'] = IndexEntry(
235
                    0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0)
236
            self.wt._index_dirty = True
237
        t = Tree()
238
        t.add(b"a", S_IFGITLINK , a.id)
239
        self.store.add_object(t)
240
        self.expectDelta([], tree_id=t.id)