summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/repo/base.py')
-rw-r--r--git/repo/base.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 2d2e915c..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
@@ -402,7 +403,17 @@ class Repo(object):
def tag(self, path: PathLike) -> TagReference:
""":return: TagReference Object, reference pointing to a Commit or Tag
:param path: path to the tag reference, i.e. 0.1.5 or tags/0.1.5 """
- return TagReference(self, path)
+ full_path = self._to_full_tag_path(path)
+ return TagReference(self, full_path)
+
+ @staticmethod
+ def _to_full_tag_path(path):
+ if path.startswith(TagReference._common_path_default + '/'):
+ return path
+ if path.startswith(TagReference._common_default + '/'):
+ return Reference._common_path_default + '/' + path
+ else:
+ return TagReference._common_path_default + '/' + path
def create_head(self, path: PathLike, commit: str = 'HEAD',
force: bool = False, logmsg: Optional[str] = None
@@ -608,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)