address review feedback and CI failures · gitpython-developers/GitPython@44e8cc5 · GitHub
Skip to content

Commit 44e8cc5

Browse files
codexByron
authored andcommitted
address review feedback and CI failures
Consolidate follow-up fixes from review and CI: - fix lint and mypy issues in reference log path handling - validate remote reference paths before invoking git branch deletion - add symlink escape coverage and reject symlink components in ref paths - clarify the symlink validation error message
1 parent 25ba54d commit 44e8cc5

4 files changed

Lines changed: 71 additions & 33 deletions

File tree

git/refs/log.py

Lines changed: 1 addition & 2 deletions

git/refs/remote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ def delete(cls, repo: "Repo", *refs: "RemoteReference", **kwargs: Any) -> None:
5858
`kwargs` are given for comparability with the base class method as we
5959
should not narrow the signature.
6060
"""
61+
for ref in refs:
62+
cls._check_ref_name_valid(ref.path)
63+
6164
repo.git.branch("-d", "-r", *refs)
6265
# The official deletion method will ignore remote symbolic refs - these are
6366
# generally ignored in the refs/ folder. We don't though and delete remainders
6467
# manually.
6568
for ref in refs:
66-
cls._check_ref_name_valid(ref.path)
6769
try:
6870
os.remove(cls._get_validated_path(repo.common_dir, ref.path))
6971
except OSError:

git/refs/symbolic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def abspath(self) -> PathLike:
114114
def _get_validated_path(base: PathLike, path: PathLike) -> str:
115115
path = os.fspath(path)
116116
base_path = os.path.realpath(os.fspath(base))
117+
cur_path = base_path
118+
for part in os.path.normpath(path).split(os.sep):
119+
if part in ("", "."):
120+
continue
121+
cur_path = os.path.join(cur_path, part)
122+
if os.path.islink(cur_path):
123+
raise ValueError("Reference path %r includes a symlink component" % path)
117124
abs_path = os.path.realpath(os.path.join(base_path, path))
118125
try:
119126
common_path = os.path.commonpath([base_path, abs_path])

test/test_refs.py

Lines changed: 60 additions & 30 deletions

0 commit comments

Comments
 (0)