Skip to content

Commit 27a0f20

Browse files
[pre-commit.ci] pre-commit autoupdate (#430)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Saugat Pachhai (सौगात) <[email protected]>
1 parent 983f20d commit 27a0f20

File tree

12 files changed

+103
-86
lines changed

12 files changed

+103
-86
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: sort-simple-yaml
2121
- id: trailing-whitespace
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: 'v0.12.4'
23+
rev: 'v0.12.5'
2424
hooks:
2525
- id: ruff-check
2626
args: [--fix, --exit-non-zero-on-fix]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ show_error_codes = true
103103
show_error_context = true
104104
show_traceback = true
105105
pretty = true
106-
check_untyped_defs = false
106+
check_untyped_defs = true
107107
# Warnings
108108
warn_no_return = true
109109
warn_redundant_casts = true

src/scmrepo/git/backend/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def is_ignored(self, path: str) -> bool:
4040

4141
@property
4242
@abstractmethod
43-
def root_dir(self) -> str:
43+
def root_dir(self) -> Optional[str]:
4444
pass
4545

4646
@staticmethod

src/scmrepo/git/backend/dulwich/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ def _find_submodules(self) -> dict[str, str]:
204204
205205
Submodule paths will be relative to Git repo root.
206206
"""
207+
207208
from dulwich.config import ConfigFile, parse_submodules
208209

209210
submodules: dict[str, str] = {}
211+
assert self.root_dir
210212
config_path = os.path.join(self.root_dir, ".gitmodules")
211213
if os.path.isfile(config_path):
212214
config = ConfigFile.from_path(config_path)
@@ -218,7 +220,7 @@ def close(self):
218220
self.repo.close()
219221

220222
@property
221-
def root_dir(self) -> str:
223+
def root_dir(self) -> Optional[str]:
222224
return self.repo.path
223225

224226
@classmethod
@@ -355,6 +357,7 @@ def _expand_paths(self, paths: list[str], force: bool = False) -> Iterator[str]:
355357
# path relative to the submodule root.
356358
fs_path = relpath(path, self.root_dir)
357359
for sm_path in self._submodules.values():
360+
assert self.root_dir
358361
if fs_path.startswith(sm_path):
359362
path = os.path.join(
360363
self.root_dir,
@@ -648,8 +651,13 @@ def push_refspecs( # noqa: C901
648651
def update_refs(refs):
649652
from dulwich.objects import ZERO_SHA
650653

654+
_refspecs = (
655+
os.fsencode(refspecs)
656+
if isinstance(refspecs, str)
657+
else [os.fsencode(refspec) for refspec in refspecs]
658+
)
651659
selected_refs.extend(
652-
parse_reftuples(self.repo.refs, refs, refspecs, force=force)
660+
parse_reftuples(self.repo.refs, refs, _refspecs, force=force)
653661
)
654662
new_refs = {}
655663
for lh, rh, _ in selected_refs:

src/scmrepo/git/backend/gitpython.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ def is_ignored(self, path: "Union[str, os.PathLike[str]]") -> bool:
161161
return bool(func(str(path)))
162162

163163
@property
164-
def root_dir(self) -> str:
165-
return self.repo.working_tree_dir
164+
def root_dir(self) -> Optional[str]:
165+
d = self.repo.working_tree_dir
166+
return os.fspath(d) if d is not None else d
166167

167168
@staticmethod
168169
@requires_git
@@ -241,7 +242,7 @@ def is_sha(rev):
241242

242243
@property
243244
def dir(self) -> str:
244-
return self.repo.git_dir
245+
return os.fspath(self.repo.git_dir)
245246

246247
def add(
247248
self,
@@ -262,7 +263,7 @@ def add(
262263
paths = [path for path in paths if not self.is_ignored(path)]
263264
self.git.add(*paths, **kwargs)
264265
else:
265-
self.repo.index.add(paths)
266+
self.repo.index.add(paths if isinstance(paths, str) else list(paths))
266267
except AssertionError as exc:
267268
# NOTE: GitPython is not currently able to handle index version >= 3.
268269
# See https://github.com/iterative/dvc/issues/610 for more details.
@@ -301,7 +302,7 @@ def fetch(
301302
kwargs["force"] = True
302303
if unshallow:
303304
kwargs["unshallow"] = True
304-
infos = self.repo.remote(name=remote).fetch(**kwargs)
305+
infos = self.repo.remote(name=remote).fetch(**kwargs) # type: ignore[arg-type]
305306
for info in infos:
306307
if info.flags & info.ERROR:
307308
raise SCMError(f"fetch failed: {info.note}")
@@ -350,7 +351,7 @@ def active_branch(self):
350351

351352
def active_branch_remote(self) -> str:
352353
try:
353-
return self.repo.active_branch.tracking_branch()
354+
return self.repo.active_branch.tracking_branch() # type: ignore[return-value]
354355
except (TypeError, ValueError) as exc:
355356
raise SCMError("No active branch tracking remote") from exc
356357

@@ -428,15 +429,15 @@ def resolve_commit(self, rev: str) -> "GitCommit":
428429
return GitCommit(
429430
commit.hexsha,
430431
commit.committed_date,
431-
commit.committer_tz_offset,
432-
commit.message,
432+
commit.committer_tz_offset, # type: ignore[arg-type]
433+
commit.message, # type: ignore[arg-type]
433434
[str(parent) for parent in commit.parents],
434-
commit.committer.name,
435-
commit.committer.email,
436-
commit.author.name,
437-
commit.author.email,
435+
commit.committer.name, # type: ignore[arg-type]
436+
commit.committer.email, # type: ignore[arg-type]
437+
commit.author.name, # type: ignore[arg-type]
438+
commit.author.email, # type: ignore[arg-type]
438439
commit.authored_date,
439-
commit.author_tz_offset,
440+
commit.author_tz_offset, # type: ignore[arg-type]
440441
)
441442

442443
def set_ref(
@@ -744,6 +745,8 @@ def get_tag(self, name: str) -> Optional[Union[str, "GitTag"]]:
744745
if not ref.tag:
745746
return ref.commit.hexsha
746747
tag = ref.tag
748+
assert tag.tagger.email
749+
assert tag.tagger.name
747750
return GitTag(
748751
tag.tag,
749752
tag.hexsha,

0 commit comments

Comments
 (0)