/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
25
from dulwich.objects import (
26
    Blob,
27
    Tree,
28
    ZERO_SHA,
29
    )
30
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
31
from ... import (
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
32
    conflicts as _mod_conflicts,
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
33
    workingtree as _mod_workingtree,
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
34
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
35
from ...delta import TreeDelta
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
36
from ..mapping import (
37
    default_mapping,
38
    GitFileIdMap,
39
    )
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
40
from ..tree import (
41
    changes_between_git_tree_and_working_copy,
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
42
    tree_delta_from_git_changes,
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
43
    )
0.369.1 by Jelmer Vernooij
Implement conflict handling.
44
from ..workingtree import (
45
    FLAG_STAGEMASK,
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
46
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
47
from ...tests import (
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
48
    TestCase,
49
    TestCaseWithTransport,
50
    )
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
51
52
53
class GitWorkingTreeTests(TestCaseWithTransport):
54
55
    def setUp(self):
56
        super(GitWorkingTreeTests, self).setUp()
57
        self.tree = self.make_branch_and_tree('.', format="git")
58
0.369.1 by Jelmer Vernooij
Implement conflict handling.
59
    def test_conflict_list(self):
0.369.2 by Jelmer Vernooij
Fix tests.
60
        self.assertIsInstance(
7143.15.2 by Jelmer Vernooij
Run autopep8.
61
            self.tree.conflicts(),
62
            _mod_conflicts.ConflictList)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
63
64
    def test_add_conflict(self):
65
        self.build_tree(['conflicted'])
66
        self.tree.add(['conflicted'])
67
        with self.tree.lock_tree_write():
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
            self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + \
69
                (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
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
93
class GitWorkingTreeFileTests(TestCaseWithTransport):
94
95
    def setUp(self):
96
        super(GitWorkingTreeFileTests, self).setUp()
97
        self.tree = self.make_branch_and_tree('actual', format="git")
7143.15.2 by Jelmer Vernooij
Run autopep8.
98
        self.build_tree_contents(
99
            [('linked/',), ('linked/.git', 'gitdir: ../actual/.git')])
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
100
        self.wt = _mod_workingtree.WorkingTree.open('linked')
101
102
    def test_add(self):
103
        self.build_tree(['linked/somefile'])
104
        self.wt.add(["somefile"])
105
        self.wt.commit("Add somefile")
106
107
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
108
class TreeDeltaFromGitChangesTests(TestCase):
109
110
    def test_empty(self):
111
        delta = TreeDelta()
112
        changes = []
113
        self.assertEqual(
114
            delta,
115
            tree_delta_from_git_changes(changes, default_mapping,
7143.15.2 by Jelmer Vernooij
Run autopep8.
116
                                        (GitFileIdMap({}, default_mapping),
117
                                         GitFileIdMap({}, default_mapping))))
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
118
119
    def test_missing(self):
120
        delta = TreeDelta()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
121
        delta.removed.append(('a', b'a-id', 'file'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
122
        changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
123
                    (b'a' * 40, b'a' * 40))]
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
124
        self.assertEqual(
125
            delta,
126
            tree_delta_from_git_changes(changes, default_mapping,
7143.15.2 by Jelmer Vernooij
Run autopep8.
127
                                        (GitFileIdMap({u'a': b'a-id'}, default_mapping),
128
                                         GitFileIdMap({u'a': b'a-id'}, default_mapping))))
6977.1.2 by Jelmer Vernooij
Deal with missing files properly in 'bzr st'.
129
130
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
131
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
132
133
    def setUp(self):
134
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
135
        self.wt = self.make_branch_and_tree('.', format='git')
136
137
    def expectDelta(self, expected_changes,
138
                    expected_extras=None, want_unversioned=False):
139
        store = self.wt.branch.repository._git.object_store
140
        try:
141
            tree_id = store[self.wt.branch.repository._git.head()].tree
142
        except KeyError:
143
            tree_id = None
0.415.3 by Jelmer Vernooij
Open index on demand.
144
        with self.wt.lock_read():
145
            changes, extras = changes_between_git_tree_and_working_copy(
146
                store, tree_id, self.wt, want_unversioned=want_unversioned)
147
            self.assertEqual(expected_changes, list(changes))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
148
        if expected_extras is None:
149
            expected_extras = set()
150
        self.assertEqual(set(expected_extras), set(extras))
151
152
    def test_empty(self):
153
        self.expectDelta(
7018.3.1 by Jelmer Vernooij
Fix git cache handling.
154
            [((None, b''), (None, stat.S_IFDIR), (None, Tree().id))])
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
155
156
    def test_added_file(self):
157
        self.build_tree(['a'])
158
        self.wt.add(['a'])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
159
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
160
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
161
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
162
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
163
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
164
             ((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.
165
166
    def test_added_unknown_file(self):
167
        self.build_tree(['a'])
168
        t = Tree()
169
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
170
            [((None, b''), (None, stat.S_IFDIR), (None, t.id))])
171
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
172
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
173
        t.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
174
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
175
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
176
             ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
177
            [b'a'],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
178
            want_unversioned=True)
179
180
    def test_missing_added_file(self):
181
        self.build_tree(['a'])
182
        self.wt.add(['a'])
183
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
184
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
185
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
186
        t.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
187
        self.expectDelta(
6973.13.2 by Jelmer Vernooij
Fix some more tests.
188
            [((None, b''), (None, stat.S_IFDIR), (None, t.id)),
189
             ((None, b'a'), (None, 0), (None, ZERO_SHA))],
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
190
            [])
191
192
    def test_missing_versioned_file(self):
193
        self.build_tree(['a'])
194
        self.wt.add(['a'])
195
        self.wt.commit('')
196
        os.unlink('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
197
        a = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
198
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
199
        oldt.add(b"a", stat.S_IFREG | 0o644, a.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
200
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
201
        newt.add(b"a", 0, ZERO_SHA)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
202
        self.expectDelta(
7143.15.2 by Jelmer Vernooij
Run autopep8.
203
            [((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
204
             ((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.
205
206
    def test_versioned_replace_by_dir(self):
207
        self.build_tree(['a'])
208
        self.wt.add(['a'])
209
        self.wt.commit('')
210
        os.unlink('a')
211
        os.mkdir('a')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
212
        olda = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
213
        oldt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
214
        oldt.add(b"a", stat.S_IFREG | 0o644, olda.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
215
        newt = Tree()
216
        newa = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
217
        newt.add(b"a", stat.S_IFDIR, newa.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
218
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
219
            ((b'', b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
220
             (stat.S_IFDIR, stat.S_IFDIR),
221
             (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
222
            ((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.
223
            ], want_unversioned=False)
224
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
225
            ((b'', b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
226
             (stat.S_IFDIR, stat.S_IFDIR),
227
             (oldt.id, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
228
            ((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.
229
            ], want_unversioned=True)
230
231
    def test_extra(self):
232
        self.build_tree(['a'])
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
233
        newa = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
234
        newt = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
235
        newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
236
        self.expectDelta([
6973.13.2 by Jelmer Vernooij
Fix some more tests.
237
            ((None, b''),
7143.15.2 by Jelmer Vernooij
Run autopep8.
238
             (None, stat.S_IFDIR),
239
             (None, newt.id)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
240
            ((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
241
            ], [b'a'], want_unversioned=True)