Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Sep 3, 2023
1 parent b1ea908 commit 18e7616
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 4 additions & 6 deletions breezy/git/tests/test_workingtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from dulwich import __version__ as dulwich_version
from dulwich.diff_tree import RenameDetector, tree_changes
from dulwich.index import IndexEntry
from dulwich.index import IndexEntry, ConflictedIndexEntry
from dulwich.object_store import OverlayObjectStore
from dulwich.objects import S_IFGITLINK, ZERO_SHA, Blob, Tree

Expand All @@ -33,7 +33,6 @@
from ...tests import TestCase, TestCaseWithTransport
from ..mapping import default_mapping
from ..tree import tree_delta_from_git_changes
from ..workingtree import FLAG_STAGEMASK


def changes_between_git_tree_and_working_copy(source_store, from_tree_sha, target,
Expand Down Expand Up @@ -65,8 +64,7 @@ def test_add_conflict(self):
self.build_tree(['conflicted'])
self.tree.add(['conflicted'])
with self.tree.lock_tree_write():
self.tree.index[b'conflicted'] = self.tree.index[b'conflicted']._replace(
flags=FLAG_STAGEMASK)
self.tree.index[b'conflicted'] = ConflictedIndexEntry(this=self.tree.index[b'conflicted'])
self.tree._index_dirty = True
conflicts = self.tree.conflicts()
self.assertEqual(1, len(conflicts))
Expand Down Expand Up @@ -338,7 +336,7 @@ def test_submodule(self):
self.build_tree_contents([('a/.git/HEAD', a.id)])
with self.wt.lock_tree_write():
(index, index_path) = self.wt._lookup_index(b'a')
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0, 0)
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id)
self.wt._index_dirty = True
t = Tree()
t.add(b"a", S_IFGITLINK, a.id)
Expand All @@ -349,7 +347,7 @@ def test_submodule_not_checked_out(self):
a = Blob.from_string(b'irrelevant\n')
with self.wt.lock_tree_write():
(index, index_path) = self.wt._lookup_index(b'a')
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id, 0, 0)
index[b'a'] = IndexEntry(0, 0, 0, 0, S_IFGITLINK, 0, 0, 0, a.id)
self.wt._index_dirty = True
os.mkdir(self.wt.abspath('a'))
t = Tree()
Expand Down
19 changes: 11 additions & 8 deletions breezy/git/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,8 @@ def _get_file_ie(self, name: str, path: str, value: Union[IndexEntry, Conflicted
sha = value.sha
size = value.size
elif isinstance(value, ConflictedIndexEntry):
if value.this is None:
raise _mod_transport.NoSuchFile(path)
mode = value.this.mode
sha = value.this.sha
size = value.this.size
Expand Down Expand Up @@ -1745,7 +1747,7 @@ def snapshot_workingtree(target: MutableGitIndexTree, want_unversioned: bool = F
# Report dirified directories to commit_tree first, so that they can be
# replaced with non-empty directories if they have contents.
dirified = []
trust_executable = target._supports_executable()
trust_executable = target._supports_executable() # type: ignore
for path, index_entry in target._recurse_index_entries():
index_entry = getattr(index_entry, 'this', index_entry)
try:
Expand Down Expand Up @@ -1784,21 +1786,22 @@ def snapshot_workingtree(target: MutableGitIndexTree, want_unversioned: bool = F
target.store.add_object(blob)
blobs[path] = (live_entry.sha, cleanup_mode(live_entry.mode))
if want_unversioned:
for extra in target._iter_files_recursive(include_dirs=False):
for extra in target._iter_files_recursive(include_dirs=False): # type: ignore
extra, accessible = osutils.normalized_filename(extra)
np = encode_git_path(extra)
if np in blobs:
continue
st = target._lstat(extra)
st = target._lstat(extra) # type: ignore
obj: Union[Tree, Blob]
if stat.S_ISDIR(st.st_mode):
blob = Tree()
obj = Tree()
elif stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode):
blob = blob_from_path_and_stat(
os.fsencode(target.abspath(extra)), st)
obj = blob_from_path_and_stat(
os.fsencode(target.abspath(extra)), st) # type: ignore
else:
continue
target.store.add_object(blob)
blobs[np] = (blob.id, cleanup_mode(st.st_mode))
target.store.add_object(obj)
blobs[np] = (obj.id, cleanup_mode(st.st_mode))
extras.add(np)
return commit_tree(
target.store, dirified + [(p, s, m) for (p, (s, m)) in blobs.items()]), extras

0 comments on commit 18e7616

Please sign in to comment.