diff options
author | Yobmod <yobmod@gmail.com> | 2021-06-17 17:29:37 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-06-17 17:29:37 +0100 |
commit | 636f77bf8d58a482df0bde8c0a6a8828950a0788 (patch) | |
tree | e1207dbe034f82deacbb76369716779608e7056d /git/repo/base.py | |
parent | 567c892322776756e8d0095e89f39b25b9b01bc2 (diff) | |
parent | b0f79c58ad919e90261d1e332df79a4ad0bc40de (diff) | |
download | gitpython-636f77bf8d58a482df0bde8c0a6a8828950a0788.tar.gz |
fix conflict
Diffstat (limited to 'git/repo/base.py')
-rw-r--r-- | git/repo/base.py | 32 |
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) |