summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-06-23 02:22:34 +0100
committerYobmod <yobmod@gmail.com>2021-06-23 02:22:34 +0100
commit5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904 (patch)
treee9030835ef3a199a650e9d948c03eea99a09696d /git/repo/base.py
parent7ca97dcef3131a11dd5ef41d674bb6bd36608608 (diff)
downloadgitpython-5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904.tar.gz
Update typing-extensions version in requirements.txt
Diffstat (limited to 'git/repo/base.py')
-rw-r--r--git/repo/base.py22
1 files changed, 20 insertions, 2 deletions
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)