◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
20 changes: 12 additions & 8 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
log.addHandler(logging.NullHandler())


# The configuration level of a configuration file.
CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository")

# Section pattern to detect conditional includes.
# https://git-scm.com/docs/git-config#_conditional_includes
CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch):(.+)\"")


class MetaParserBuilder(abc.ABCMeta): # noqa: B024
Expand Down Expand Up @@ -283,12 +285,14 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):
"""

# { Configuration
# The lock type determines the type of lock to use in new configuration readers.
# They must be compatible to the LockFile interface.
# A suitable alternative would be the BlockingLockFile
t_lock = LockFile
re_comment = re.compile(r"^\s*[#;]")

# } END configuration

optvalueonly_source = r"\s*(?P<option>[^:=\s][^:=]*)"
Expand All @@ -299,8 +303,8 @@ class GitConfigParser(cp.RawConfigParser, metaclass=MetaParserBuilder):

del optvalueonly_source

# list of RawConfigParser methods able to change the instance
_mutating_methods_ = ("add_section", "remove_section", "remove_option", "set")

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

__all__ = ("Diffable", "DiffIndex", "Diff", "NULL_TREE")

# Special object to compare against the empty tree in diffs.
NULL_TREE = object()

_octal_byte_re = re.compile(rb"\\([0-9]{3})")

Expand Down
6 changes: 4 additions & 2 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):

__slots__ = ("repo", "version", "entries", "_extension_data", "_file_path")

_VERSION = 2 # Latest version we support.

S_IFGITLINK = S_IFGITLINK # A submodule.

def __init__(self, repo: "Repo", file_path: Union[PathLike, None] = None) -> None:
"""Initialize this Index instance, optionally from the given ``file_path``.
Expand Down
4 changes: 3 additions & 1 deletion git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
# ------------------------------------------------------------------------------------


S_IFGITLINK = S_IFLNK | S_IFDIR # A submodule.
CE_NAMEMASK_INV = ~CE_NAMEMASK

__all__ = (
Expand Down
11 changes: 6 additions & 5 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class UpdateProgress(RemoteProgress):
UPDWKTREE = UpdateProgress.UPDWKTREE


# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import
# mechanism which cause plenty of trouble of the only reason for packages and
# modules is refactoring - subpackages shouldn't depend on parent packages
class Submodule(IndexObject, TraversableIterableObj):
"""Implements access to a git submodule. They are special in that their sha
represents a commit in the submodule's repository which is to be checked out
Expand All @@ -95,10 +95,11 @@ class Submodule(IndexObject, TraversableIterableObj):
k_modules_file = ".gitmodules"
k_head_option = "branch"
k_head_default = "master"
k_default_mode = stat.S_IFDIR | stat.S_IFLNK # Submodules are directories with link-status.

# This is a bogus type for base class compatibility.
type: Literal["submodule"] = "submodule" # type: ignore

__slots__ = ("_parent_commit", "_url", "_branch_path", "_name", "__weakref__")

Expand Down
31 changes: 20 additions & 11 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ class Repo:
'working_tree_dir' is the working tree directory, but will return None
if we are a bare repository.

'git_dir' is the .git repository directory, which is always set."""

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: PathLike
_working_tree_dir: Optional[PathLike] = None
git_dir: PathLike
_common_dir: PathLike = ""

# precompiled regex
re_whitespace = re.compile(r"\s+")
re_hexsha_only = re.compile(r"^[0-9A-Fa-f]{40}$")
re_hexsha_shortened = re.compile(r"^[0-9A-Fa-f]{4,40}$")
Expand All @@ -133,24 +134,32 @@ class Repo:
re_tab_full_line = re.compile(r"^\t(.*)$")

unsafe_git_clone_options = [
# This option allows users to execute arbitrary commands.
# https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---upload-packltupload-packgt
"--upload-pack",
"-u",
# Users can override configuration variables
# like `protocol.allow` or `core.gitProxy` to execute arbitrary commands.
# https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---configltkeygtltvaluegt
"--config",
"-c",
]

# invariants
# represents the configuration level of a configuration file
config_level: ConfigLevels_Tup = ("system", "user", "global", "repository")

# Subclass configuration
# Subclasses may easily bring in their own custom types by placing a constructor or type here
GitCommandWrapperType = Git

def __init__(
self,
Expand Down
4 changes: 2 additions & 2 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ class RemoteProgress:
"_cur_line",
"_seen_ops",
"error_lines", # Lines that started with 'error:' or 'fatal:'.
"other_lines",
) # Lines not denoting progress (i.e.g. push-infos).
re_op_absolute = re.compile(r"(remote: )?([\w\s]+):\s+()(\d+)()(.*)")
re_op_relative = re.compile(r"(remote: )?([\w\s]+):\s+(\d+)% \((\d+)/(\d+)\)(.*)")

Expand Down
Toggle all file notes Toggle all file annotations