diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-07-20 07:04:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-20 07:04:18 +0800 |
commit | cfd653aeeb3cb807f2cd2ae9fff5568880ac67da (patch) | |
tree | 8514389e82efdcdcdeaab5d3a85553883f28117c /git/repo/fun.py | |
parent | acbd6bad9ded9a1d59e80e71d334d64b0244f5cd (diff) | |
parent | 600df043e76924d43a4f9f88f4e3241740f34c77 (diff) | |
download | gitpython-cfd653aeeb3cb807f2cd2ae9fff5568880ac67da.tar.gz |
Merge pull request #1295 from Yobmod/main
Add types to refs
Diffstat (limited to 'git/repo/fun.py')
-rw-r--r-- | git/repo/fun.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/git/repo/fun.py b/git/repo/fun.py index e96b62e0..7d5c7823 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -1,5 +1,4 @@ """Package with general repository related functions""" -from git.refs.tag import Tag import os import stat from string import digits @@ -19,11 +18,14 @@ from git.cmd import Git # Typing ---------------------------------------------------------------------- from typing import Union, Optional, cast, TYPE_CHECKING -from git.types import PathLike + + if TYPE_CHECKING: + from git.types import PathLike from .base import Repo from git.db import GitCmdObjectDB from git.objects import Commit, TagObject, Blob, Tree + from git.refs.tag import Tag # ---------------------------------------------------------------------------- @@ -37,7 +39,7 @@ def touch(filename: str) -> str: return filename -def is_git_dir(d: PathLike) -> bool: +def is_git_dir(d: 'PathLike') -> bool: """ This is taken from the git setup.c:is_git_directory function. @@ -59,7 +61,7 @@ def is_git_dir(d: PathLike) -> bool: return False -def find_worktree_git_dir(dotgit: PathLike) -> Optional[str]: +def find_worktree_git_dir(dotgit: 'PathLike') -> Optional[str]: """Search for a gitdir for this worktree.""" try: statbuf = os.stat(dotgit) @@ -78,7 +80,7 @@ def find_worktree_git_dir(dotgit: PathLike) -> Optional[str]: return None -def find_submodule_git_dir(d: PathLike) -> Optional[PathLike]: +def find_submodule_git_dir(d: 'PathLike') -> Optional['PathLike']: """Search for a submodule repo.""" if is_git_dir(d): return d @@ -122,7 +124,7 @@ def name_to_object(repo: 'Repo', name: str, return_ref: bool = False :param return_ref: if name specifies a reference, we will return the reference instead of the object. Otherwise it will raise BadObject or BadName """ - hexsha = None # type: Union[None, str, bytes] + hexsha: Union[None, str, bytes] = None # is it a hexsha ? Try the most common ones, which is 7 to 40 if repo.re_hexsha_shortened.match(name): @@ -162,7 +164,7 @@ def name_to_object(repo: 'Repo', name: str, return_ref: bool = False return Object.new_from_sha(repo, hex_to_bin(hexsha)) -def deref_tag(tag: Tag) -> 'TagObject': +def deref_tag(tag: 'Tag') -> 'TagObject': """Recursively dereference a tag and return the resulting object""" while True: try: |