diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 08:17:32 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 08:17:32 +0800 |
commit | 38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2 (patch) | |
tree | 8ac0bc1540650cf3befff11735e1421de372fa92 /git/refs/head.py | |
parent | b30720ee4d9762a03eae4fa7cfa4b0190d81784d (diff) | |
parent | 43c00af7e542911cce638cfab49c6a6dc9349e55 (diff) | |
download | gitpython-38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2.tar.gz |
Merge branch 'black-fmt'
Diffstat (limited to 'git/refs/head.py')
-rw-r--r-- | git/refs/head.py | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/git/refs/head.py b/git/refs/head.py index d1d72c7b..26efc6cb 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -31,15 +31,16 @@ class HEAD(SymbolicReference): """Special case of a Symbolic Reference as it represents the repository's HEAD reference.""" - _HEAD_NAME = 'HEAD' - _ORIG_HEAD_NAME = 'ORIG_HEAD' + + _HEAD_NAME = "HEAD" + _ORIG_HEAD_NAME = "ORIG_HEAD" __slots__ = () - def __init__(self, repo: 'Repo', path: PathLike = _HEAD_NAME): + 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)) super(HEAD, self).__init__(repo, path) - self.commit: 'Commit' + self.commit: "Commit" def orig_head(self) -> SymbolicReference: """ @@ -47,9 +48,14 @@ class HEAD(SymbolicReference): to contain the previous value of HEAD""" return SymbolicReference(self.repo, self._ORIG_HEAD_NAME) - def reset(self, commit: Union[Commit_ish, SymbolicReference, str] = 'HEAD', - index: bool = True, working_tree: bool = False, - paths: Union[PathLike, Sequence[PathLike], None] = None, **kwargs: Any) -> 'HEAD': + def reset( + self, + commit: Union[Commit_ish, SymbolicReference, str] = "HEAD", + index: bool = True, + working_tree: bool = False, + paths: Union[PathLike, Sequence[PathLike], None] = None, + **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 commit as well. @@ -95,7 +101,7 @@ class HEAD(SymbolicReference): # END working tree handling try: - self.repo.git.reset(mode, commit, '--', paths, **kwargs) + self.repo.git.reset(mode, commit, "--", paths, **kwargs) except GitCommandError as e: # git nowadays may use 1 as status to indicate there are still unstaged # modifications after the reset @@ -124,12 +130,13 @@ class Head(Reference): >>> head.commit.hexsha '1c09f116cbc2cb4100fb6935bb162daa4723f455'""" + _common_path_default = "refs/heads" k_config_remote = "remote" - k_config_remote_ref = "merge" # branch to merge from remote + 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: @@ -141,7 +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. @@ -150,6 +157,7 @@ class Head(Reference): any references :return: self""" from .remote import RemoteReference + if remote_reference is not None and not isinstance(remote_reference, RemoteReference): raise ValueError("Incorrect parameter type: %r" % remote_reference) # END handle type @@ -162,18 +170,25 @@ class Head(Reference): writer.remove_section() else: writer.set_value(self.k_config_remote, remote_reference.remote_name) - writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head)) + writer.set_value( + self.k_config_remote_ref, + Head.to_full_path(remote_reference.remote_head), + ) return self - def tracking_branch(self) -> Union['RemoteReference', None]: + def tracking_branch(self) -> Union["RemoteReference", None]: """ :return: The remote_reference we are tracking, or None if we are not a tracking branch""" 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): - ref = Head(self.repo, Head.to_full_path(strip_quotes(reader.get_value(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)) return RemoteReference(self.repo, remote_refpath) # END handle have tracking branch @@ -181,7 +196,7 @@ class Head(Reference): # we are not a tracking branch return None - def rename(self, new_path: PathLike, force: bool = False) -> 'Head': + def rename(self, new_path: PathLike, force: bool = False) -> "Head": """Rename self to a new path :param new_path: @@ -202,7 +217,7 @@ class Head(Reference): self.path = "%s/%s" % (self._common_path_default, new_path) return self - def checkout(self, force: bool = False, **kwargs: Any) -> Union['HEAD', 'Head']: + def checkout(self, force: bool = False, **kwargs: Any) -> Union["HEAD", "Head"]: """Checkout this head by setting the HEAD to this reference, by updating the index to reflect the tree we point to and by updating the working tree to reflect the latest index. @@ -227,9 +242,9 @@ class Head(Reference): By default it is only allowed to checkout heads - everything else will leave the HEAD detached which is allowed and possible, but remains a special state that some tools might not be able to handle.""" - kwargs['f'] = force - if kwargs['f'] is False: - kwargs.pop('f') + kwargs["f"] = force + if kwargs["f"] is False: + kwargs.pop("f") self.repo.git.checkout(self, **kwargs) if self.repo.head.is_detached: @@ -237,7 +252,7 @@ class Head(Reference): else: return self.repo.active_branch - #{ Configuration + # { Configuration def _config_parser(self, read_only: bool) -> SectionConstraint[GitConfigParser]: if read_only: parser = self.repo.config_reader() @@ -259,4 +274,4 @@ class Head(Reference): to options of this head""" return self._config_parser(read_only=False) - #} END configuration + # } END configuration |