From 45d1cd59d39227ee6841042eab85116a59a26d22 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Thu, 11 Mar 2021 16:35:24 +0100 Subject: Remove support for Python 3.5 --- git/cmd.py | 9 --------- 1 file changed, 9 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index ec630d93..72ec0381 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -17,9 +17,7 @@ from subprocess import ( import subprocess import sys import threading -from collections import OrderedDict from textwrap import dedent -import warnings from git.compat import ( defenc, @@ -903,13 +901,6 @@ class Git(LazyMixin): def transform_kwargs(self, split_single_char_options=True, **kwargs): """Transforms Python style kwargs into git command line options.""" - # Python 3.6 preserves the order of kwargs and thus has a stable - # order. For older versions sort the kwargs by the key to get a stable - # order. - if sys.version_info[:2] < (3, 6): - kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0])) - warnings.warn("Python 3.5 support is deprecated and will be removed 2021-09-05.\n" + - "It does not preserve the order for key-word arguments and enforce lexical sorting instead.") args = [] for k, v in kwargs.items(): if isinstance(v, (list, tuple)): -- cgit v1.2.1 From 47f35d1ba2b9b75a9078592cf4c41728ac088793 Mon Sep 17 00:00:00 2001 From: mxrch Date: Fri, 21 May 2021 14:17:07 +0200 Subject: fixed case where progress was no longer shown if a single error occured --- git/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/util.py b/git/util.py index 76aaee49..edbd5f1e 100644 --- a/git/util.py +++ b/git/util.py @@ -470,7 +470,7 @@ class RemoteProgress(object): line_str = line self._cur_line = line_str - if self.error_lines or self._cur_line.startswith(('error:', 'fatal:')): + if self._cur_line.startswith(('error:', 'fatal:')): self.error_lines.append(self._cur_line) return -- cgit v1.2.1 From 1a04c15b1f77f908b1dd3983a27ee49c41b3a3e5 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Mon, 24 May 2021 17:34:42 -0400 Subject: improve index mode for files with executable bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fix for #430 in bebc4f56 (Use correct mode for executable files, 2016-05-19) is incomplete. It fails (in most cases) when files have modes which are not exactly 0644 or 0755. Git only cares whether the executable bit is set (or not). Ensure the mode we set for the index is either 100644 or 100755 based on whether the executable bit is set for the file owner. Do this similarly to how upstream git does it in cache.h¹. Add a test covering various file modes to help catch regressions. Fixes #1253 ¹ https://github.com/git/git/blob/v2.31.1/cache.h#L247 --- git/index/fun.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/index/fun.py b/git/index/fun.py index f40928c3..1012f480 100644 --- a/git/index/fun.py +++ b/git/index/fun.py @@ -11,6 +11,7 @@ from stat import ( S_ISDIR, S_IFMT, S_IFREG, + S_IXUSR, ) import subprocess @@ -115,7 +116,7 @@ def stat_mode_to_index_mode(mode): return S_IFLNK if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules return S_IFGITLINK - return S_IFREG | 0o644 | (mode & 0o111) # blobs with or without executable bit + return S_IFREG | (mode & S_IXUSR and 0o755 or 0o644) # blobs with or without executable bit def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream: IO[bytes], -- cgit v1.2.1 From 4fbf0ef97d6f59d2eb0f37b29716ba0de95c4457 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 3 Jun 2021 09:11:18 +0800 Subject: Don't raise on unknown line when parsing stale refs (#1262) --- git/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/remote.py b/git/remote.py index e17f7bb8..6ea4b2a1 100644 --- a/git/remote.py +++ b/git/remote.py @@ -612,7 +612,7 @@ class Remote(LazyMixin, Iterable): # * [would prune] origin/new_branch token = " * [would prune] " if not line.startswith(token): - raise ValueError("Could not parse git-remote prune result: %r" % line) + continue ref_name = line.replace(token, "") # sometimes, paths start with a full ref name, like refs/tags/foo, see #260 if ref_name.startswith(Reference._common_path_default + '/'): -- cgit v1.2.1 From a625d08801eacd94f373074d2c771103823954d0 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Thu, 3 Jun 2021 10:12:30 +0200 Subject: Adds _common_default to build _common_path_default --- git/refs/tag.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/refs/tag.py b/git/refs/tag.py index 8f88c522..4d84239e 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -18,7 +18,8 @@ class TagReference(Reference): print(tagref.tag.message)""" __slots__ = () - _common_path_default = "refs/tags" + _common_default = "tags" + _common_path_default = Reference._common_path_default + "/" + _common_default @property def commit(self): -- cgit v1.2.1 From abf9373865c319d2f1aaf188feef900bb8ebf933 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Thu, 3 Jun 2021 10:21:50 +0200 Subject: Fixes resolving of tag parameter for repo.tag I accessed private variables instead of adding getters, because other parts of the code do the same and I didn't know if there was a reason for it. E.g.: remote.py line 409: (...) RemoteReference._common_path_default (...) --- git/repo/base.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index e23ebb1a..540a5fe3 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -402,7 +402,18 @@ 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: PathLike): + 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 -- cgit v1.2.1 From 702bdf105205ca845a50b16d6703828d18e93003 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 3 Jun 2021 21:06:30 +0800 Subject: Fix flake8 --- git/repo/base.py | 1 - 1 file changed, 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index 540a5fe3..53698592 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -414,7 +414,6 @@ class Repo(object): else: return TagReference._common_path_default + '/' + path - def create_head(self, path: PathLike, commit: str = 'HEAD', force: bool = False, logmsg: Optional[str] = None ) -> 'SymbolicReference': -- cgit v1.2.1 From 7ca97dcef3131a11dd5ef41d674bb6bd36608608 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Thu, 3 Jun 2021 16:45:03 +0200 Subject: Removes PathLike type requirement for full_tag creation --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index 53698592..55682411 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -406,7 +406,7 @@ class Repo(object): return TagReference(self, full_path) @staticmethod - def _to_full_tag_path(path: PathLike): + def _to_full_tag_path(path): if path.startswith(TagReference._common_path_default + '/'): return path if path.startswith(TagReference._common_default + '/'): -- cgit v1.2.1 From 385a8c6c1a72dc34f69c5273c1b4c1285cc1d3c5 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Sat, 5 Jun 2021 12:15:38 +0200 Subject: Adds repo.is_valid_object check --- git/repo/base.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index 55682411..e7b1274b 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -3,12 +3,14 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php - +import binascii import logging import os import re import warnings +from gitdb.exc import BadObject + from git.cmd import ( Git, handle_process_output @@ -618,6 +620,23 @@ class Repo(object): raise return True + def is_valid_object(self, sha: str, object_type: Union['blob', 'commit', 'tree', 'tag'] = 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(f"Commit hash points to an object of type '{object_info.type.decode()}'. " + f"Requested were objects of type '{object_type}'") + return False + else: + return True + except BadObject as e: + 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 ac4fe6efbccc2ad5c2044bf36e34019363018630 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Sat, 5 Jun 2021 12:22:24 +0200 Subject: Fixes type check for is_valid_object --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index e7b1274b..b19503ee 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -620,7 +620,7 @@ class Repo(object): raise return True - def is_valid_object(self, sha: str, object_type: Union['blob', 'commit', 'tree', 'tag'] = None) -> bool: + 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) -- cgit v1.2.1 From 4832aa6bf82e4853f8f426fc06350540e2c8a9e7 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Sat, 5 Jun 2021 12:34:24 +0200 Subject: Removes local variable 'e' that is assigned to but never used --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index b19503ee..d38cf756 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -633,7 +633,7 @@ class Repo(object): return False else: return True - except BadObject as e: + except BadObject: log.debug("Commit hash is invalid.") return False -- cgit v1.2.1 From fb2461d84f97a72641ef1e878450aeab7cd17241 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Sat, 5 Jun 2021 12:35:41 +0200 Subject: Removes unused import --- git/repo/base.py | 1 - 1 file changed, 1 deletion(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index d38cf756..0db0bd0c 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -3,7 +3,6 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -import binascii import logging import os import re -- cgit v1.2.1 From 464504ce0069758fdb88b348e4a626a265fb3fe3 Mon Sep 17 00:00:00 2001 From: Robert Westman Date: Sat, 5 Jun 2021 12:39:44 +0200 Subject: Removes f-string syntax for p35 compatibility --- git/repo/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git') diff --git a/git/repo/base.py b/git/repo/base.py index 0db0bd0c..6cc56031 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -627,8 +627,8 @@ class Repo(object): if object_info.type == object_type.encode(): return True else: - log.debug(f"Commit hash points to an object of type '{object_info.type.decode()}'. " - f"Requested were objects of type '{object_type}'") + 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 -- cgit v1.2.1 From 820d3cc9ceda3e5690d627677883b7f9d349b326 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 16 Jun 2021 11:22:27 +0800 Subject: Revert "Remove support for Python 3.5" - fix CI for now. This reverts commit 45d1cd59d39227ee6841042eab85116a59a26d22. See #1201 which will hopefully help to get a proper fix soon. --- git/cmd.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index 4f58b314..d8b82352 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -17,7 +17,9 @@ from subprocess import ( import subprocess import sys import threading +from collections import OrderedDict from textwrap import dedent +import warnings from git.compat import ( defenc, @@ -1003,6 +1005,13 @@ class Git(LazyMixin): def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any) -> List[str]: """Transforms Python style kwargs into git command line options.""" + # Python 3.6 preserves the order of kwargs and thus has a stable + # order. For older versions sort the kwargs by the key to get a stable + # order. + if sys.version_info[:2] < (3, 6): + kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0])) + warnings.warn("Python 3.5 support is deprecated and will be removed 2021-09-05.\n" + + "It does not preserve the order for key-word arguments and enforce lexical sorting instead.") args = [] for k, v in kwargs.items(): if isinstance(v, (list, tuple)): -- cgit v1.2.1 From b0f79c58ad919e90261d1e332df79a4ad0bc40de Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 16 Jun 2021 11:27:07 +0800 Subject: Revert "Revert "Remove support for Python 3.5" - fix CI for now." This reverts commit 820d3cc9ceda3e5690d627677883b7f9d349b326. --- git/cmd.py | 9 --------- 1 file changed, 9 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index d8b82352..4f58b314 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -17,9 +17,7 @@ from subprocess import ( import subprocess import sys import threading -from collections import OrderedDict from textwrap import dedent -import warnings from git.compat import ( defenc, @@ -1005,13 +1003,6 @@ class Git(LazyMixin): def transform_kwargs(self, split_single_char_options: bool = True, **kwargs: Any) -> List[str]: """Transforms Python style kwargs into git command line options.""" - # Python 3.6 preserves the order of kwargs and thus has a stable - # order. For older versions sort the kwargs by the key to get a stable - # order. - if sys.version_info[:2] < (3, 6): - kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0])) - warnings.warn("Python 3.5 support is deprecated and will be removed 2021-09-05.\n" + - "It does not preserve the order for key-word arguments and enforce lexical sorting instead.") args = [] for k, v in kwargs.items(): if isinstance(v, (list, tuple)): -- cgit v1.2.1