summaryrefslogtreecommitdiff
path: root/git/repo
diff options
context:
space:
mode:
Diffstat (limited to 'git/repo')
-rw-r--r--git/repo/__init__.py1
-rw-r--r--git/repo/base.py27
-rw-r--r--git/repo/fun.py16
3 files changed, 23 insertions, 21 deletions
diff --git a/git/repo/__init__.py b/git/repo/__init__.py
index 5619aa69..712df60d 100644
--- a/git/repo/__init__.py
+++ b/git/repo/__init__.py
@@ -1,4 +1,3 @@
"""Initialize the Repo package"""
# flake8: noqa
-from __future__ import absolute_import
from .base import *
diff --git a/git/repo/base.py b/git/repo/base.py
index 3214b528..64f32bd3 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -83,10 +83,10 @@ class Repo(object):
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
git = cast('Git', None) # Must exist, or __del__ will fail in case we raise on `__init__()`
- working_dir = None # type: Optional[PathLike]
- _working_tree_dir = None # type: Optional[PathLike]
- git_dir = "" # type: PathLike
- _common_dir = "" # type: PathLike
+ working_dir: Optional[PathLike] = None
+ _working_tree_dir: Optional[PathLike] = None
+ git_dir: PathLike = ""
+ _common_dir: PathLike = ""
# precompiled regex
re_whitespace = re.compile(r'\s+')
@@ -221,7 +221,7 @@ class Repo(object):
self._working_tree_dir = None
# END working dir handling
- self.working_dir = self._working_tree_dir or self.common_dir # type: Optional[PathLike]
+ self.working_dir: Optional[PathLike] = self._working_tree_dir or self.common_dir
self.git = self.GitCommandWrapperType(self.working_dir)
# special handling, in special times
@@ -426,7 +426,7 @@ class Repo(object):
For more documentation, please see the Head.create method.
:return: newly created Head Reference"""
- return Head.create(self, path, commit, force, logmsg)
+ return Head.create(self, path, commit, logmsg, force)
def delete_head(self, *heads: 'SymbolicReference', **kwargs: Any) -> None:
"""Delete the given heads
@@ -518,7 +518,7 @@ class Repo(object):
repository = configuration file for this repository only"""
return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self)
- def commit(self, rev: Optional[str] = None
+ def commit(self, rev: Union[str, Commit_ish, None] = None
) -> Commit:
"""The Commit object for the specified revision
@@ -551,7 +551,8 @@ class Repo(object):
return self.head.commit.tree
return self.rev_parse(str(rev) + "^{tree}")
- def iter_commits(self, rev: Optional[TBD] = None, paths: Union[PathLike, Sequence[PathLike]] = '',
+ def iter_commits(self, rev: Union[str, Commit, 'SymbolicReference', None] = None,
+ paths: Union[PathLike, Sequence[PathLike]] = '',
**kwargs: Any) -> Iterator[Commit]:
"""A list of Commit objects representing the history of a given ref/commit
@@ -590,7 +591,7 @@ class Repo(object):
raise ValueError("Please specify at least two revs, got only %i" % len(rev))
# end handle input
- res = [] # type: List[Union[Commit_ish, None]]
+ res: List[Union[Commit_ish, None]] = []
try:
lines = self.git.merge_base(*rev, **kwargs).splitlines() # List[str]
except GitCommandError as err:
@@ -812,7 +813,7 @@ class Repo(object):
line = next(stream) # when exhausted, causes a StopIteration, terminating this function
except StopIteration:
return
- split_line = line.split() # type: Tuple[str, str, str, str]
+ split_line: Tuple[str, str, str, str] = line.split()
hexsha, orig_lineno_str, lineno_str, num_lines_str = split_line
lineno = int(lineno_str)
num_lines = int(num_lines_str)
@@ -878,10 +879,10 @@ class Repo(object):
return self.blame_incremental(rev, file, **kwargs)
data = self.git.blame(rev, '--', file, p=True, stdout_as_string=False, **kwargs)
- commits = {} # type: Dict[str, Any]
- blames = [] # type: List[List[Union[Optional['Commit'], List[str]]]]
+ commits: Dict[str, TBD] = {}
+ blames: List[List[Union[Optional['Commit'], List[str]]]] = []
- info = {} # type: Dict[str, Any] # use Any until TypedDict available
+ info: Dict[str, TBD] = {} # use Any until TypedDict available
keepends = True
for line in data.splitlines(keepends):
diff --git a/git/repo/fun.py b/git/repo/fun.py
index e96b62e0..7d5c7823 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -1,5 +1,4 @@
"""Package with general repository related functions"""
-from git.refs.tag import Tag
import os
import stat
from string import digits
@@ -19,11 +18,14 @@ from git.cmd import Git
# Typing ----------------------------------------------------------------------
from typing import Union, Optional, cast, TYPE_CHECKING
-from git.types import PathLike
+
+
if TYPE_CHECKING:
+ from git.types import PathLike
from .base import Repo
from git.db import GitCmdObjectDB
from git.objects import Commit, TagObject, Blob, Tree
+ from git.refs.tag import Tag
# ----------------------------------------------------------------------------
@@ -37,7 +39,7 @@ def touch(filename: str) -> str:
return filename
-def is_git_dir(d: PathLike) -> bool:
+def is_git_dir(d: 'PathLike') -> bool:
""" This is taken from the git setup.c:is_git_directory
function.
@@ -59,7 +61,7 @@ def is_git_dir(d: PathLike) -> bool:
return False
-def find_worktree_git_dir(dotgit: PathLike) -> Optional[str]:
+def find_worktree_git_dir(dotgit: 'PathLike') -> Optional[str]:
"""Search for a gitdir for this worktree."""
try:
statbuf = os.stat(dotgit)
@@ -78,7 +80,7 @@ def find_worktree_git_dir(dotgit: PathLike) -> Optional[str]:
return None
-def find_submodule_git_dir(d: PathLike) -> Optional[PathLike]:
+def find_submodule_git_dir(d: 'PathLike') -> Optional['PathLike']:
"""Search for a submodule repo."""
if is_git_dir(d):
return d
@@ -122,7 +124,7 @@ def name_to_object(repo: 'Repo', name: str, return_ref: bool = False
:param return_ref: if name specifies a reference, we will return the reference
instead of the object. Otherwise it will raise BadObject or BadName
"""
- hexsha = None # type: Union[None, str, bytes]
+ hexsha: Union[None, str, bytes] = None
# is it a hexsha ? Try the most common ones, which is 7 to 40
if repo.re_hexsha_shortened.match(name):
@@ -162,7 +164,7 @@ def name_to_object(repo: 'Repo', name: str, return_ref: bool = False
return Object.new_from_sha(repo, hex_to_bin(hexsha))
-def deref_tag(tag: Tag) -> 'TagObject':
+def deref_tag(tag: 'Tag') -> 'TagObject':
"""Recursively dereference a tag and return the resulting object"""
while True:
try: