58
61
def test_conflict_list(self):
59
62
self.assertIsInstance(
60
self.tree.conflicts(),
61
_mod_conflicts.ConflictList)
63
self.tree.conflicts(),
64
_mod_conflicts.ConflictList)
63
66
def test_add_conflict(self):
64
67
self.build_tree(['conflicted'])
65
68
self.tree.add(['conflicted'])
66
69
with self.tree.lock_tree_write():
67
self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + (FLAG_STAGEMASK, )
70
self.tree.index[b'conflicted'] = self.tree.index[b'conflicted'][:9] + \
68
72
self.tree._index_dirty = True
69
73
conflicts = self.tree.conflicts()
70
74
self.assertEqual(1, len(conflicts))
87
91
self.tree._ignoremanager = None
88
92
self.assertTrue(self.tree.is_ignored('a'))
94
def test_add_submodule_dir(self):
95
subtree = self.make_branch_and_tree('asub', format='git')
96
subtree.commit('Empty commit')
97
self.tree.add(['asub'])
98
with self.tree.lock_read():
99
entry = self.tree.index[b'asub']
100
self.assertEqual(entry.mode, S_IFGITLINK)
101
self.assertEqual([], list(subtree.unknowns()))
103
def test_add_submodule_file(self):
104
os.mkdir('.git/modules')
105
subbranch = self.make_branch('.git/modules/asub', format='git-bare')
107
with open('asub/.git', 'w') as f:
108
f.write('gitdir: ../.git/modules/asub\n')
109
subtree = _mod_workingtree.WorkingTree.open('asub')
110
subtree.commit('Empty commit')
111
self.tree.add(['asub'])
112
with self.tree.lock_read():
113
entry = self.tree.index[b'asub']
114
self.assertEqual(entry.mode, S_IFGITLINK)
115
self.assertEqual([], list(subtree.unknowns()))
118
class GitWorkingTreeFileTests(TestCaseWithTransport):
121
super(GitWorkingTreeFileTests, self).setUp()
122
self.tree = self.make_branch_and_tree('actual', format="git")
123
self.build_tree_contents(
124
[('linked/',), ('linked/.git', 'gitdir: ../actual/.git')])
125
self.wt = _mod_workingtree.WorkingTree.open('linked')
128
self.build_tree(['linked/somefile'])
129
self.wt.add(["somefile"])
130
self.wt.commit("Add somefile")
91
133
class TreeDeltaFromGitChangesTests(TestCase):
98
140
tree_delta_from_git_changes(changes, default_mapping,
99
(GitFileIdMap({}, default_mapping),
100
GitFileIdMap({}, default_mapping))))
141
(GitFileIdMap({}, default_mapping),
142
GitFileIdMap({}, default_mapping))))
102
144
def test_missing(self):
103
145
delta = TreeDelta()
104
146
delta.removed.append(('a', b'a-id', 'file'))
105
changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0), (b'a' * 40, b'a' * 40))]
147
changes = [((b'a', b'a'), (stat.S_IFREG | 0o755, 0),
148
(b'a' * 40, b'a' * 40))]
106
149
self.assertEqual(
108
151
tree_delta_from_git_changes(changes, default_mapping,
109
(GitFileIdMap({u'a': b'a-id'}, default_mapping),
110
GitFileIdMap({u'a': b'a-id'}, default_mapping))))
152
(GitFileIdMap({u'a': b'a-id'}, default_mapping),
153
GitFileIdMap({u'a': b'a-id'}, default_mapping))))
113
156
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
116
159
super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
117
160
self.wt = self.make_branch_and_tree('.', format='git')
161
self.store = self.wt.branch.repository._git.object_store
119
163
def expectDelta(self, expected_changes,
120
expected_extras=None, want_unversioned=False):
121
store = self.wt.branch.repository._git.object_store
123
tree_id = store[self.wt.branch.repository._git.head()].tree
164
expected_extras=None, want_unversioned=False,
168
tree_id = self.store[self.wt.branch.repository._git.head()].tree
126
171
with self.wt.lock_read():
127
172
changes, extras = changes_between_git_tree_and_working_copy(
128
store, tree_id, self.wt, want_unversioned=want_unversioned)
173
self.store, tree_id, self.wt, want_unversioned=want_unversioned)
129
174
self.assertEqual(expected_changes, list(changes))
130
175
if expected_extras is None:
131
176
expected_extras = set()
183
228
newt.add(b"a", 0, ZERO_SHA)
184
229
self.expectDelta(
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))])
230
[((b'', b''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
231
((b'a', b'a'), (stat.S_IFREG | 0o644, 0), (a.id, ZERO_SHA))])
188
233
def test_versioned_replace_by_dir(self):
189
234
self.build_tree(['a'])
199
244
newt.add(b"a", stat.S_IFDIR, newa.id)
200
245
self.expectDelta([
202
(stat.S_IFDIR, stat.S_IFDIR),
247
(stat.S_IFDIR, stat.S_IFDIR),
204
249
((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
205
250
], want_unversioned=False)
206
251
self.expectDelta([
208
(stat.S_IFDIR, stat.S_IFDIR),
253
(stat.S_IFDIR, stat.S_IFDIR),
210
255
((b'a', b'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
211
256
], want_unversioned=True)
217
262
newt.add(b"a", stat.S_IFREG | 0o644, newa.id)
218
263
self.expectDelta([
220
(None, stat.S_IFDIR),
265
(None, stat.S_IFDIR),
222
267
((None, b'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
223
268
], [b'a'], want_unversioned=True)
270
def test_submodule(self):
271
self.build_tree(['a/'])
272
a = Blob.from_string(b'irrelevant\n')
273
with self.wt.lock_tree_write():
274
(index, index_path) = self.wt._lookup_index(b'a')
275
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0)
276
self.wt._index_dirty = True
278
t.add(b"a", S_IFGITLINK, a.id)
279
self.store.add_object(t)
280
self.expectDelta([], tree_id=t.id)