diff options
Diffstat (limited to 'git/refs')
| -rw-r--r-- | git/refs/head.py | 38 | ||||
| -rw-r--r-- | git/refs/log.py | 17 | ||||
| -rw-r--r-- | git/refs/reference.py | 8 | ||||
| -rw-r--r-- | git/refs/remote.py | 6 | ||||
| -rw-r--r-- | git/refs/symbolic.py | 71 | ||||
| -rw-r--r-- | git/refs/tag.py | 2 |
6 files changed, 35 insertions, 107 deletions
diff --git a/git/refs/head.py b/git/refs/head.py index befdc135..26efc6cb 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -38,9 +38,7 @@ class HEAD(SymbolicReference): def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME): if path != self._HEAD_NAME: - raise ValueError( - "HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path) - ) + raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path)) super(HEAD, self).__init__(repo, path) self.commit: "Commit" @@ -56,7 +54,7 @@ class HEAD(SymbolicReference): index: bool = True, working_tree: bool = False, paths: Union[PathLike, Sequence[PathLike], None] = None, - **kwargs: Any + **kwargs: Any, ) -> "HEAD": """Reset our HEAD to the given commit optionally synchronizing the index and working tree. The reference we refer to will be set to @@ -98,9 +96,7 @@ class HEAD(SymbolicReference): if working_tree: mode = "--hard" if not index: - raise ValueError( - "Cannot reset the working tree if the index is not reset as well" - ) + raise ValueError("Cannot reset the working tree if the index is not reset as well") # END working tree handling @@ -140,13 +136,7 @@ class Head(Reference): k_config_remote_ref = "merge" # branch to merge from remote @classmethod - def delete( - cls, - repo: "Repo", - *heads: "Union[Head, str]", - force: bool = False, - **kwargs: Any - ) -> None: + def delete(cls, repo: "Repo", *heads: "Union[Head, str]", force: bool = False, **kwargs: Any) -> None: """Delete the given heads :param force: @@ -158,9 +148,7 @@ class Head(Reference): flag = "-D" repo.git.branch(flag, *heads) - def set_tracking_branch( - self, remote_reference: Union["RemoteReference", None] - ) -> "Head": + def set_tracking_branch(self, remote_reference: Union["RemoteReference", None]) -> "Head": """ Configure this branch to track the given remote reference. This will alter this branch's configuration accordingly. @@ -170,9 +158,7 @@ class Head(Reference): :return: self""" from .remote import RemoteReference - if remote_reference is not None and not isinstance( - remote_reference, RemoteReference - ): + if remote_reference is not None and not isinstance(remote_reference, RemoteReference): raise ValueError("Incorrect parameter type: %r" % remote_reference) # END handle type @@ -198,18 +184,12 @@ class Head(Reference): from .remote import RemoteReference reader = self.config_reader() - if reader.has_option(self.k_config_remote) and reader.has_option( - self.k_config_remote_ref - ): + if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref): ref = Head( self.repo, - Head.to_full_path( - strip_quotes(reader.get_value(self.k_config_remote_ref)) - ), - ) - remote_refpath = RemoteReference.to_full_path( - join_path(reader.get_value(self.k_config_remote), ref.name) + Head.to_full_path(strip_quotes(reader.get_value(self.k_config_remote_ref))), ) + remote_refpath = RemoteReference.to_full_path(join_path(reader.get_value(self.k_config_remote), ref.name)) return RemoteReference(self.repo, remote_refpath) # END handle have tracking branch diff --git a/git/refs/log.py b/git/refs/log.py index 908f93d1..a5f4de58 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -118,10 +118,7 @@ class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]): elif len(fields) == 2: info, msg = fields else: - raise ValueError( - "Line must have up to two TAB-separated fields." - " Got %s" % repr(line_str) - ) + raise ValueError("Line must have up to two TAB-separated fields." " Got %s" % repr(line_str)) # END handle first split oldhexsha = info[:40] @@ -247,9 +244,7 @@ class RefLog(List[RefLogEntry], Serializable): for i in range(index + 1): line = fp.readline() if not line: - raise IndexError( - f"Index file ended at line {i+1}, before given index was reached" - ) + raise IndexError(f"Index file ended at line {i+1}, before given index was reached") # END abort on eof # END handle runup @@ -304,9 +299,7 @@ class RefLog(List[RefLogEntry], Serializable): assure_directory_exists(filepath, is_file=True) first_line = message.split("\n")[0] if isinstance(config_reader, Actor): - committer = ( - config_reader # mypy thinks this is Actor | Gitconfigparser, but why? - ) + committer = config_reader # mypy thinks this is Actor | Gitconfigparser, but why? else: committer = Actor.committer(config_reader) entry = RefLogEntry( @@ -335,9 +328,7 @@ class RefLog(List[RefLogEntry], Serializable): """Write this instance's data to the file we are originating from :return: self""" if self._path is None: - raise ValueError( - "Instance was not initialized with a path, use to_file(...) instead" - ) + raise ValueError("Instance was not initialized with a path, use to_file(...) instead") # END assert path self.to_file(self._path) return self diff --git a/git/refs/reference.py b/git/refs/reference.py index 9b946ec4..ca43cc43 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -26,9 +26,7 @@ def require_remote_ref_path(func: Callable[..., _T]) -> Callable[..., _T]: def wrapper(self: T_References, *args: Any) -> _T: if not self.is_remote(): - raise ValueError( - "ref path does not point to a remote reference: %s" % self.path - ) + raise ValueError("ref path does not point to a remote reference: %s" % self.path) return func(self, *args) # END wrapper @@ -59,9 +57,7 @@ class Reference(SymbolicReference, LazyMixin, IterableObj): :param check_path: if False, you can provide any path. Otherwise the path must start with the default path prefix of this type.""" if check_path and not str(path).startswith(self._common_path_default + "/"): - raise ValueError( - f"Cannot instantiate {self.__class__.__name__!r} from path {path}" - ) + raise ValueError(f"Cannot instantiate {self.__class__.__name__!r} from path {path}") self.path: str # SymbolicReference converts to string atm super(Reference, self).__init__(repo, path) diff --git a/git/refs/remote.py b/git/refs/remote.py index 8ac6bcd2..ec10c5a1 100644 --- a/git/refs/remote.py +++ b/git/refs/remote.py @@ -33,7 +33,7 @@ class RemoteReference(Head): common_path: Union[PathLike, None] = None, remote: Union["Remote", None] = None, *args: Any, - **kwargs: Any + **kwargs: Any, ) -> Iterator["RemoteReference"]: """Iterate remote references, and if given, constrain them to the given remote""" common_path = common_path or cls._common_path_default @@ -48,9 +48,7 @@ class RemoteReference(Head): # tightening the types of arguments in subclasses and recommends Any or # "type: ignore". (See https://github.com/python/typing/issues/241) @classmethod - def delete( - cls, repo: "Repo", *refs: "RemoteReference", **kwargs: Any # type: ignore - ) -> None: + def delete(cls, repo: "Repo", *refs: "RemoteReference", **kwargs: Any) -> None: # type: ignore """Delete the given remote references :note: diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 6d9ebb96..33c3bf15 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -127,13 +127,8 @@ class SymbolicReference(object): # I looked at master on 2017-10-11, # commit 111ef79afe, after tag v2.15.0-rc1 # from repo https://github.com/git/git.git - if ( - line.startswith("# pack-refs with:") - and "peeled" not in line - ): - raise TypeError( - "PackingType of packed-Refs not understood: %r" % line - ) + if line.startswith("# pack-refs with:") and "peeled" not in line: + raise TypeError("PackingType of packed-Refs not understood: %r" % line) # END abort if we do not understand the packing scheme continue # END parse comment @@ -154,9 +149,7 @@ class SymbolicReference(object): # alright. @classmethod - def dereference_recursive( - cls, repo: "Repo", ref_path: Union[PathLike, None] - ) -> str: + def dereference_recursive(cls, repo: "Repo", ref_path: Union[PathLike, None]) -> str: """ :return: hexsha stored in the reference at the given ref_path, recursively dereferencing all intermediate references as required @@ -178,9 +171,7 @@ class SymbolicReference(object): tokens: Union[None, List[str], Tuple[str, str]] = None repodir = _git_dir(repo, ref_path) try: - with open( - os.path.join(repodir, str(ref_path)), "rt", encoding="UTF-8" - ) as fp: + with open(os.path.join(repodir, str(ref_path)), "rt", encoding="UTF-8") as fp: value = fp.read().rstrip() # Don't only split on spaces, but on whitespace, which allows to parse lines like # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo @@ -212,9 +203,7 @@ class SymbolicReference(object): raise ValueError("Failed to parse reference information from %r" % ref_path) @classmethod - def _get_ref_info( - cls, repo: "Repo", ref_path: Union[PathLike, None] - ) -> Union[Tuple[str, None], Tuple[None, str]]: + def _get_ref_info(cls, repo: "Repo", ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]: """Return: (str(sha), str(target_ref_path)) if available, the sha the file at rela_path points to, or None. target_ref_path is the reference we point to, or None""" @@ -227,9 +216,7 @@ class SymbolicReference(object): always point to the actual object as it gets re-created on each query""" # have to be dynamic here as we may be a tag which can point to anything # Our path will be resolved to the hexsha which will be used accordingly - return Object.new_from_sha( - self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path)) - ) + return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path))) def _get_commit(self) -> "Commit": """ @@ -242,9 +229,7 @@ class SymbolicReference(object): # END dereference tag if obj.type != Commit.type: - raise TypeError( - "Symbolic Reference pointed to object %r, commit was required" % obj - ) + raise TypeError("Symbolic Reference pointed to object %r, commit was required" % obj) # END handle type return obj @@ -321,9 +306,7 @@ class SymbolicReference(object): to a reference, but to a commit""" sha, target_ref_path = self._get_ref_info(self.repo, self.path) if target_ref_path is None: - raise TypeError( - "%s is a detached symbolic reference as it points to %r" % (self, sha) - ) + raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) return self.from_path(self.repo, target_ref_path) def set_reference( @@ -454,9 +437,7 @@ class SymbolicReference(object): # correct to allow overriding the committer on a per-commit level. # See https://github.com/gitpython-developers/GitPython/pull/146 try: - committer_or_reader: Union[ - "Actor", "GitConfigParser" - ] = self.commit.committer + committer_or_reader: Union["Actor", "GitConfigParser"] = self.commit.committer except ValueError: committer_or_reader = self.repo.config_reader() # end handle newly cloned repositories @@ -466,9 +447,7 @@ class SymbolicReference(object): if message is None: message = "" - return RefLog.append_entry( - committer_or_reader, RefLog.path(self), oldbinsha, newbinsha, message - ) + return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha, newbinsha, message) def log_entry(self, index: int) -> "RefLogEntry": """:return: RefLogEntry at the given index @@ -525,9 +504,7 @@ class SymbolicReference(object): # If we deleted the last line and this one is a tag-reference object, # we drop it as well if (line.startswith("#") or full_ref_path != line_ref) and ( - not dropped_last_line - or dropped_last_line - and not line.startswith("^") + not dropped_last_line or dropped_last_line and not line.startswith("^") ): new_lines.append(line) dropped_last_line = False @@ -635,9 +612,7 @@ class SymbolicReference(object): already exists. :note: This does not alter the current HEAD, index or Working Tree""" - return cls._create( - repo, path, cls._resolve_ref_on_create, reference, force, logmsg - ) + return cls._create(repo, path, cls._resolve_ref_on_create, reference, force, logmsg) def rename(self, new_path: PathLike, force: bool = False) -> "SymbolicReference": """Rename self to a new path @@ -694,9 +669,7 @@ class SymbolicReference(object): # walk loose refs # Currently we do not follow links - for root, dirs, files in os.walk( - join_path_native(repo.common_dir, common_path) - ): + for root, dirs, files in os.walk(join_path_native(repo.common_dir, common_path)): if "refs" not in root.split(os.sep): # skip non-refs subfolders refs_id = [d for d in dirs if d == "refs"] if refs_id: @@ -707,9 +680,7 @@ class SymbolicReference(object): if f == "packed-refs": continue abs_path = to_native_path_linux(join_path(root, f)) - rela_paths.add( - abs_path.replace(to_native_path_linux(repo.common_dir) + "/", "") - ) + rela_paths.add(abs_path.replace(to_native_path_linux(repo.common_dir) + "/", "")) # END for each file in root directory # END for each directory to walk @@ -752,16 +723,10 @@ class SymbolicReference(object): List is lexicographically sorted The returned objects represent actual subclasses, such as Head or TagReference""" - return ( - r - for r in cls._iter_items(repo, common_path) - if r.__class__ == SymbolicReference or not r.is_detached - ) + return (r for r in cls._iter_items(repo, common_path) if r.__class__ == SymbolicReference or not r.is_detached) @classmethod - def from_path( - cls: Type[T_References], repo: "Repo", path: PathLike - ) -> T_References: + def from_path(cls: Type[T_References], repo: "Repo", path: PathLike) -> T_References: """ :param path: full .git-directory-relative path name to the Reference to instantiate :note: use to_full_path() if you only have a partial path of a known Reference Type @@ -795,9 +760,7 @@ class SymbolicReference(object): pass # END exception handling # END for each type to try - raise ValueError( - "Could not find reference type suitable to handle path %r" % path - ) + raise ValueError("Could not find reference type suitable to handle path %r" % path) def is_remote(self) -> bool: """:return: True if this symbolic reference points to a remote branch""" diff --git a/git/refs/tag.py b/git/refs/tag.py index 96494148..0295b54d 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -81,7 +81,7 @@ class TagReference(Reference): reference: Union[str, "SymbolicReference"] = "HEAD", logmsg: Union[str, None] = None, force: bool = False, - **kwargs: Any + **kwargs: Any, ) -> "TagReference": """Create a new tag reference. |
