From 5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Wed, 23 Jun 2021 02:22:34 +0100 Subject: Update typing-extensions version in requirements.txt --- git/repo/base.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 55682411..5abd4961 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -3,12 +3,13 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php - import logging import os import re import warnings +from gitdb.exc import BadObject + from git.cmd import ( Git, handle_process_output @@ -529,7 +530,7 @@ class Repo(object): :note: Takes all arguments known to iter_commits method""" return (c.tree for c in self.iter_commits(*args, **kwargs)) - def tree(self, rev: Union['Commit', 'Tree', None] = None) -> 'Tree': + def tree(self, rev: Union['Commit', 'Tree', str, None] = None) -> 'Tree': """The Tree object for the given treeish revision Examples:: @@ -618,6 +619,23 @@ class Repo(object): raise return True + def is_valid_object(self, sha: str, object_type: str = None) -> bool: + try: + complete_sha = self.odb.partial_to_complete_sha_hex(sha) + object_info = self.odb.info(complete_sha) + if object_type: + if object_info.type == object_type.encode(): + return True + else: + log.debug("Commit hash points to an object of type '%s'. Requested were objects of type '%s'", + object_info.type.decode(), object_type) + return False + else: + return True + except BadObject: + log.debug("Commit hash is invalid.") + return False + def _get_daemon_export(self) -> bool: if self.git_dir: filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE) -- cgit v1.2.1 From 42e4f5e26b812385df65f8f32081035e2fb2a121 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Thu, 24 Jun 2021 05:52:48 +0100 Subject: Add types to tree.Tree --- git/repo/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 5abd4961..77947731 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -7,6 +7,7 @@ import logging import os import re import warnings +from gitdb.db.loose import LooseObjectDB from gitdb.exc import BadObject @@ -100,7 +101,7 @@ class Repo(object): # Subclasses may easily bring in their own custom types by placing a constructor or type here GitCommandWrapperType = Git - def __init__(self, path: Optional[PathLike] = None, odbt: Type[GitCmdObjectDB] = GitCmdObjectDB, + def __init__(self, path: Optional[PathLike] = None, odbt: Type[LooseObjectDB] = GitCmdObjectDB, search_parent_directories: bool = False, expand_vars: bool = True) -> None: """Create a new Repo instance -- cgit v1.2.1 From c3903d8e03af5c1e01c1a96919b926c55f45052e Mon Sep 17 00:00:00 2001 From: Yobmod Date: Thu, 24 Jun 2021 14:27:13 +0100 Subject: Make IterableList generic and update throughout --- git/repo/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 77947731..52727504 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -309,7 +309,7 @@ class Repo(object): return self._bare @property - def heads(self) -> 'IterableList': + def heads(self) -> 'IterableList[Head]': """A list of ``Head`` objects representing the branch heads in this repo @@ -317,7 +317,7 @@ class Repo(object): return Head.list_items(self) @property - def references(self) -> 'IterableList': + def references(self) -> 'IterableList[Reference]': """A list of Reference objects representing tags, heads and remote references. :return: IterableList(Reference, ...)""" @@ -342,7 +342,7 @@ class Repo(object): return HEAD(self, 'HEAD') @property - def remotes(self) -> 'IterableList': + def remotes(self) -> 'IterableList[Remote]': """A list of Remote objects allowing to access and manipulate remotes :return: ``git.IterableList(Remote, ...)``""" return Remote.list_items(self) @@ -358,13 +358,13 @@ class Repo(object): #{ Submodules @property - def submodules(self) -> 'IterableList': + def submodules(self) -> 'IterableList[Submodule]': """ :return: git.IterableList(Submodule, ...) of direct submodules available from the current head""" return Submodule.list_items(self) - def submodule(self, name: str) -> 'IterableList': + def submodule(self, name: str) -> 'Submodule': """ :return: Submodule with the given name :raise ValueError: If no such submodule exists""" try: @@ -396,7 +396,7 @@ class Repo(object): #}END submodules @property - def tags(self) -> 'IterableList': + def tags(self) -> 'IterableList[TagReference]': """A list of ``Tag`` objects that are available in this repo :return: ``git.IterableList(TagReference, ...)`` """ return TagReference.list_items(self) -- cgit v1.2.1