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 |
||
|
0.369.2
by Jelmer Vernooij
Fix tests. |
31 |
from .... import conflicts as _mod_conflicts |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
32 |
from ..workingtree import ( |
33 |
FLAG_STAGEMASK, |
|
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
34 |
changes_between_git_tree_and_working_copy, |
|
0.262.1
by Jelmer Vernooij
Fix WorkingTree.conflicts(). |
35 |
)
|
|
0.200.1642
by Jelmer Vernooij
Use relative imports in tests. |
36 |
from ....tests import TestCaseWithTransport |
|
0.262.1
by Jelmer Vernooij
Fix WorkingTree.conflicts(). |
37 |
|
38 |
||
39 |
class GitWorkingTreeTests(TestCaseWithTransport): |
|
40 |
||
41 |
def setUp(self): |
|
42 |
super(GitWorkingTreeTests, self).setUp() |
|
43 |
self.tree = self.make_branch_and_tree('.', format="git") |
|
44 |
||
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
45 |
def test_conflict_list(self): |
|
0.369.2
by Jelmer Vernooij
Fix tests. |
46 |
self.assertIsInstance( |
47 |
self.tree.conflicts(), |
|
48 |
_mod_conflicts.ConflictList) |
|
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
49 |
|
50 |
def test_add_conflict(self): |
|
51 |
self.build_tree(['conflicted']) |
|
52 |
self.tree.add(['conflicted']) |
|
53 |
with self.tree.lock_tree_write(): |
|
54 |
self.tree.index['conflicted'] = self.tree.index['conflicted'][:9] + (FLAG_STAGEMASK, ) |
|
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
55 |
self.tree._index_dirty = True |
|
0.369.1
by Jelmer Vernooij
Implement conflict handling. |
56 |
conflicts = self.tree.conflicts() |
57 |
self.assertEqual(1, len(conflicts)) |
|
|
0.385.1
by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir. |
58 |
|
59 |
def test_revert_empty(self): |
|
60 |
self.build_tree(['a']) |
|
61 |
self.tree.add(['a']) |
|
62 |
self.assertTrue(self.tree.is_versioned('a')) |
|
63 |
self.tree.revert(['a']) |
|
64 |
self.assertFalse(self.tree.is_versioned('a')) |
|
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
65 |
|
66 |
||
67 |
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport): |
|
68 |
||
69 |
def setUp(self): |
|
70 |
super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp() |
|
71 |
self.wt = self.make_branch_and_tree('.', format='git') |
|
72 |
||
73 |
def expectDelta(self, expected_changes, |
|
74 |
expected_extras=None, want_unversioned=False): |
|
75 |
store = self.wt.branch.repository._git.object_store |
|
76 |
try: |
|
77 |
tree_id = store[self.wt.branch.repository._git.head()].tree |
|
78 |
except KeyError: |
|
79 |
tree_id = None |
|
|
0.415.3
by Jelmer Vernooij
Open index on demand. |
80 |
with self.wt.lock_read(): |
81 |
changes, extras = changes_between_git_tree_and_working_copy( |
|
82 |
store, tree_id, self.wt, want_unversioned=want_unversioned) |
|
83 |
self.assertEqual(expected_changes, list(changes)) |
|
|
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
84 |
if expected_extras is None: |
85 |
expected_extras = set() |
|
86 |
self.assertEqual(set(expected_extras), set(extras)) |
|
87 |
||
88 |
def test_empty(self): |
|
89 |
self.expectDelta( |
|
90 |
[((None, ''), (None, stat.S_IFDIR), (None, Tree().id))]) |
|
91 |
||
92 |
def test_added_file(self): |
|
93 |
self.build_tree(['a']) |
|
94 |
self.wt.add(['a']) |
|
95 |
a = Blob.from_string('contents of a\n') |
|
96 |
t = Tree() |
|
97 |
t.add("a", stat.S_IFREG | 0o644, a.id) |
|
98 |
self.expectDelta( |
|
99 |
[((None, ''), (None, stat.S_IFDIR), (None, t.id)), |
|
100 |
((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))]) |
|
101 |
||
102 |
def test_added_unknown_file(self): |
|
103 |
self.build_tree(['a']) |
|
104 |
t = Tree() |
|
105 |
self.expectDelta( |
|
106 |
[((None, ''), (None, stat.S_IFDIR), (None, t.id))]) |
|
107 |
a = Blob.from_string('contents of a\n') |
|
108 |
t = Tree() |
|
109 |
t.add("a", stat.S_IFREG | 0o644, a.id) |
|
110 |
self.expectDelta( |
|
111 |
[((None, ''), (None, stat.S_IFDIR), (None, t.id)), |
|
112 |
((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))], |
|
113 |
['a'], |
|
114 |
want_unversioned=True) |
|
115 |
||
116 |
def test_missing_added_file(self): |
|
117 |
self.build_tree(['a']) |
|
118 |
self.wt.add(['a']) |
|
119 |
os.unlink('a') |
|
120 |
a = Blob.from_string('contents of a\n') |
|
121 |
t = Tree() |
|
122 |
t.add("a", 0, ZERO_SHA) |
|
123 |
self.expectDelta( |
|
124 |
[((None, ''), (None, stat.S_IFDIR), (None, t.id)), |
|
125 |
((None, 'a'), (None, 0), (None, ZERO_SHA))], |
|
126 |
[])
|
|
127 |
||
128 |
def test_missing_versioned_file(self): |
|
129 |
self.build_tree(['a']) |
|
130 |
self.wt.add(['a']) |
|
131 |
self.wt.commit('') |
|
132 |
os.unlink('a') |
|
133 |
a = Blob.from_string('contents of a\n') |
|
134 |
oldt = Tree() |
|
135 |
oldt.add("a", stat.S_IFREG | 0o644, a.id) |
|
136 |
newt = Tree() |
|
137 |
newt.add("a", 0, ZERO_SHA) |
|
138 |
self.expectDelta( |
|
139 |
[(('', ''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)), |
|
140 |
(('a', 'a'), (stat.S_IFREG|0o644, 0), (a.id, ZERO_SHA))]) |
|
141 |
||
142 |
def test_versioned_replace_by_dir(self): |
|
143 |
self.build_tree(['a']) |
|
144 |
self.wt.add(['a']) |
|
145 |
self.wt.commit('') |
|
146 |
os.unlink('a') |
|
147 |
os.mkdir('a') |
|
148 |
olda = Blob.from_string('contents of a\n') |
|
149 |
oldt = Tree() |
|
150 |
oldt.add("a", stat.S_IFREG | 0o644, olda.id) |
|
151 |
newt = Tree() |
|
152 |
newa = Tree() |
|
153 |
newt.add("a", stat.S_IFDIR, newa.id) |
|
154 |
self.expectDelta([ |
|
155 |
(('', ''), |
|
156 |
(stat.S_IFDIR, stat.S_IFDIR), |
|
157 |
(oldt.id, newt.id)), |
|
158 |
(('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id)) |
|
159 |
], want_unversioned=False) |
|
160 |
self.expectDelta([ |
|
161 |
(('', ''), |
|
162 |
(stat.S_IFDIR, stat.S_IFDIR), |
|
163 |
(oldt.id, newt.id)), |
|
164 |
(('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id)) |
|
165 |
], want_unversioned=True) |
|
166 |
||
167 |
def test_extra(self): |
|
168 |
self.build_tree(['a']) |
|
169 |
newa = Blob.from_string('contents of a\n') |
|
170 |
newt = Tree() |
|
171 |
newt.add("a", stat.S_IFREG | 0o644, newa.id) |
|
172 |
self.expectDelta([ |
|
173 |
((None, ''), |
|
174 |
(None, stat.S_IFDIR), |
|
175 |
(None, newt.id)), |
|
176 |
((None, 'a'), (None, stat.S_IFREG | 0o644), (None, newa.id)) |
|
177 |
], ['a'], want_unversioned=True) |