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