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.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
20 |
import os |
21 |
import stat |
|
22 |
||
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
23 |
from dulwich.index import IndexEntry |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
24 |
from dulwich.objects import ( |
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
25 |
S_IFGITLINK, |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
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 |
7358.11.3
by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes. |
36 |
from ...tree import TreeChange |
6977.1.2
by Jelmer Vernooij
Deal with missing files properly in 'bzr st'. |
37 |
from ..mapping import ( |
38 |
default_mapping, |
|
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 |
||
7265.3.1
by Jelmer Vernooij
Properly ignore .git files. |
92 |
def test_add_submodule_dir(self): |
93 |
subtree = self.make_branch_and_tree('asub', format='git') |
|
94 |
subtree.commit('Empty commit') |
|
95 |
self.tree.add(['asub']) |
|
96 |
with self.tree.lock_read(): |
|
97 |
entry = self.tree.index[b'asub'] |
|
98 |
self.assertEqual(entry.mode, S_IFGITLINK) |
|
99 |
self.assertEqual([], list(subtree.unknowns())) |
|
100 |
||
101 |
def test_add_submodule_file(self): |
|
102 |
os.mkdir('.git/modules') |
|
103 |
subbranch = self.make_branch('.git/modules/asub', format='git-bare') |
|
104 |
os.mkdir('asub') |
|
105 |
with open('asub/.git', 'w') as f: |
|
106 |
f.write('gitdir: ../.git/modules/asub\n') |
|
107 |
subtree = _mod_workingtree.WorkingTree.open('asub') |
|
108 |
subtree.commit('Empty commit') |
|
109 |
self.tree.add(['asub']) |
|
110 |
with self.tree.lock_read(): |
|
111 |
entry = self.tree.index[b'asub'] |
|
112 |
self.assertEqual(entry.mode, S_IFGITLINK) |
|
113 |
self.assertEqual([], list(subtree.unknowns())) |
|
114 |
||
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
115 |
|
7131.3.1
by Jelmer Vernooij
When opening working trees with .git files, open the right control transport. |
116 |
class GitWorkingTreeFileTests(TestCaseWithTransport): |
117 |
||
118 |
def setUp(self): |
|
119 |
super(GitWorkingTreeFileTests, self).setUp() |
|
120 |
self.tree = self.make_branch_and_tree('actual', format="git") |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
121 |
self.build_tree_contents( |
122 |
[('linked/',), ('linked/.git', 'gitdir: ../actual/.git')]) |
|
7131.3.1
by Jelmer Vernooij
When opening working trees with .git files, open the right control transport. |
123 |
self.wt = _mod_workingtree.WorkingTree.open('linked') |
124 |
||
125 |
def test_add(self): |
|
126 |
self.build_tree(['linked/somefile']) |
|
127 |
self.wt.add(["somefile"]) |
|
128 |
self.wt.commit("Add somefile") |
|
129 |
||
130 |
||
6977.1.2
by Jelmer Vernooij
Deal with missing files properly in 'bzr st'. |
131 |
class TreeDeltaFromGitChangesTests(TestCase): |
132 |
||
133 |
def test_empty(self): |
|
134 |
delta = TreeDelta() |
|
135 |
changes = [] |
|
136 |
self.assertEqual( |
|
137 |
delta, |
|
7358.13.1
by Jelmer Vernooij
Drop file id roundtripping support in Git. |
138 |
tree_delta_from_git_changes(changes, (default_mapping, default_mapping))) |
6977.1.2
by Jelmer Vernooij
Deal with missing files properly in 'bzr st'. |
139 |
|
140 |
def test_missing(self): |
|
141 |
delta = TreeDelta() |
|
7358.11.6
by Jelmer Vernooij
merge trunk. |
142 |
delta.removed.append(TreeChange(b'git:a', ('a', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', None), (True, False))) |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
143 |
changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0), |
144 |
(b'a' * 40, b'a' * 40))] |
|
6977.1.2
by Jelmer Vernooij
Deal with missing files properly in 'bzr st'. |
145 |
self.assertEqual( |
146 |
delta, |
|
7358.13.1
by Jelmer Vernooij
Drop file id roundtripping support in Git. |
147 |
tree_delta_from_git_changes(changes, (default_mapping, default_mapping))) |
6977.1.2
by Jelmer Vernooij
Deal with missing files properly in 'bzr st'. |
148 |
|
149 |
||
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
150 |
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport): |
151 |
||
152 |
def setUp(self): |
|
153 |
super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp() |
|
154 |
self.wt = self.make_branch_and_tree('.', format='git') |
|
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
155 |
self.store = self.wt.branch.repository._git.object_store |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
156 |
|
157 |
def expectDelta(self, expected_changes, |
|
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
158 |
expected_extras=None, want_unversioned=False, |
159 |
tree_id=None): |
|
160 |
if tree_id is None: |
|
161 |
try: |
|
162 |
tree_id = self.store[self.wt.branch.repository._git.head()].tree |
|
163 |
except KeyError: |
|
164 |
tree_id = None |
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
165 |
with self.wt.lock_read(): |
166 |
changes, extras = changes_between_git_tree_and_working_copy( |
|
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
167 |
self.store, tree_id, self.wt, want_unversioned=want_unversioned) |
0.415.3
by Jelmer Vernooij
Open index on demand. |
168 |
self.assertEqual(expected_changes, list(changes)) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
169 |
if expected_extras is None: |
170 |
expected_extras = set() |
|
171 |
self.assertEqual(set(expected_extras), set(extras)) |
|
172 |
||
173 |
def test_empty(self): |
|
174 |
self.expectDelta( |
|
7018.3.1
by Jelmer Vernooij
Fix git cache handling. |
175 |
[((None, b''), (None, stat.S_IFDIR), (None, Tree().id))]) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
176 |
|
177 |
def test_added_file(self): |
|
178 |
self.build_tree(['a']) |
|
179 |
self.wt.add(['a']) |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
180 |
a = Blob.from_string(b'contents of a\n') |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
181 |
t = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
182 |
t.add(b"a", stat.S_IFREG | 0o644, a.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
183 |
self.expectDelta( |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
184 |
[((None, b''), (None, stat.S_IFDIR), (None, t.id)), |
185 |
((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. |
186 |
|
187 |
def test_added_unknown_file(self): |
|
188 |
self.build_tree(['a']) |
|
189 |
t = Tree() |
|
190 |
self.expectDelta( |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
191 |
[((None, b''), (None, stat.S_IFDIR), (None, t.id))]) |
192 |
a = Blob.from_string(b'contents of a\n') |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
193 |
t = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
194 |
t.add(b"a", stat.S_IFREG | 0o644, a.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
195 |
self.expectDelta( |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
196 |
[((None, b''), (None, stat.S_IFDIR), (None, t.id)), |
197 |
((None, b'a'), (None, stat.S_IFREG | 0o644), (None, a.id))], |
|
198 |
[b'a'], |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
199 |
want_unversioned=True) |
200 |
||
201 |
def test_missing_added_file(self): |
|
202 |
self.build_tree(['a']) |
|
203 |
self.wt.add(['a']) |
|
204 |
os.unlink('a') |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
205 |
a = Blob.from_string(b'contents of a\n') |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
206 |
t = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
207 |
t.add(b"a", 0, ZERO_SHA) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
208 |
self.expectDelta( |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
209 |
[((None, b''), (None, stat.S_IFDIR), (None, t.id)), |
210 |
((None, b'a'), (None, 0), (None, ZERO_SHA))], |
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
211 |
[])
|
212 |
||
213 |
def test_missing_versioned_file(self): |
|
214 |
self.build_tree(['a']) |
|
215 |
self.wt.add(['a']) |
|
216 |
self.wt.commit('') |
|
217 |
os.unlink('a') |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
218 |
a = Blob.from_string(b'contents of a\n') |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
219 |
oldt = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
220 |
oldt.add(b"a", stat.S_IFREG | 0o644, a.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
221 |
newt = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
222 |
newt.add(b"a", 0, ZERO_SHA) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
223 |
self.expectDelta( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
224 |
[((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)), |
225 |
((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. |
226 |
|
227 |
def test_versioned_replace_by_dir(self): |
|
228 |
self.build_tree(['a']) |
|
229 |
self.wt.add(['a']) |
|
230 |
self.wt.commit('') |
|
231 |
os.unlink('a') |
|
232 |
os.mkdir('a') |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
233 |
olda = Blob.from_string(b'contents of a\n') |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
234 |
oldt = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
235 |
oldt.add(b"a", stat.S_IFREG | 0o644, olda.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
236 |
newt = Tree() |
237 |
newa = Tree() |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
238 |
newt.add(b"a", stat.S_IFDIR, newa.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
239 |
self.expectDelta([ |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
240 |
((b'', b''), |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
241 |
(stat.S_IFDIR, stat.S_IFDIR), |
242 |
(oldt.id, newt.id)), |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
243 |
((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. |
244 |
], want_unversioned=False) |
245 |
self.expectDelta([ |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
246 |
((b'', b''), |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
247 |
(stat.S_IFDIR, stat.S_IFDIR), |
248 |
(oldt.id, newt.id)), |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
249 |
((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. |
250 |
], want_unversioned=True) |
251 |
||
252 |
def test_extra(self): |
|
253 |
self.build_tree(['a']) |
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
254 |
newa = Blob.from_string(b'contents of a\n') |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
255 |
newt = Tree() |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
256 |
newt.add(b"a", stat.S_IFREG | 0o644, newa.id) |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
257 |
self.expectDelta([ |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
258 |
((None, b''), |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
259 |
(None, stat.S_IFDIR), |
260 |
(None, newt.id)), |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
261 |
((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id)) |
262 |
], [b'a'], want_unversioned=True) |
|
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
263 |
|
264 |
def test_submodule(self): |
|
7296.1.3
by Jelmer Vernooij
Fix submodule test. |
265 |
self.subtree = self.make_branch_and_tree('a', format="git") |
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
266 |
a = Blob.from_string(b'irrelevant\n') |
7296.1.3
by Jelmer Vernooij
Fix submodule test. |
267 |
self.build_tree_contents([('a/.git/HEAD', a.id)]) |
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
268 |
with self.wt.lock_tree_write(): |
7131.13.3
by Jelmer Vernooij
Fix python3 compatibility. |
269 |
(index, index_path) = self.wt._lookup_index(b'a') |
7183.2.1
by Martin
Fix E999 lint error for Python 2 flake8 |
270 |
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. |
271 |
self.wt._index_dirty = True |
272 |
t = Tree() |
|
7183.2.1
by Martin
Fix E999 lint error for Python 2 flake8 |
273 |
t.add(b"a", S_IFGITLINK, a.id) |
7131.13.1
by Jelmer Vernooij
Don't show a delta for unchanged submodules. |
274 |
self.store.add_object(t) |
275 |
self.expectDelta([], tree_id=t.id) |
|
7452.1.1
by Jelmer Vernooij
Don't show submodules that are not checked out as deltas. |
276 |
|
277 |
def test_submodule_not_checked_out(self): |
|
278 |
a = Blob.from_string(b'irrelevant\n') |
|
279 |
with self.wt.lock_tree_write(): |
|
280 |
(index, index_path) = self.wt._lookup_index(b'a') |
|
281 |
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0) |
|
282 |
self.wt._index_dirty = True |
|
283 |
os.mkdir(self.wt.abspath('a')) |
|
284 |
t = Tree() |
|
285 |
t.add(b"a", S_IFGITLINK, a.id) |
|
286 |
self.store.add_object(t) |
|
287 |
self.expectDelta([], tree_id=t.id) |