fix: preserve literal clone URLs by Byron · Pull Request #2172 · gitpython-developers/GitPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions git/cmd.py
7 changes: 4 additions & 3 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,9 @@ def _clone(
if multi_options:
multi = shlex.split(" ".join(multi_options))

clone_url = Git.polish_url(url, expand_vars=False)
if not allow_unsafe_protocols:
Git.check_unsafe_protocols(url)
Git.check_unsafe_protocols(clone_url)
if not allow_unsafe_options:
Git.check_unsafe_options(
options=Git._option_candidates([], kwargs),
Expand All @@ -1465,7 +1466,7 @@ def _clone(
proc = git.clone(
multi,
"--",
Git.polish_url(url),
clone_url,
clone_path,
with_extended_output=True,
as_process=True,
Expand Down Expand Up @@ -1505,7 +1506,7 @@ def _clone(
# escape the backslashes. Hence we undo the escaping just to be sure.
if repo.remotes:
with repo.remotes[0].config_writer as writer:
writer.set_value("url", Git.polish_url(repo.remotes[0].url))
writer.set_value("url", Git.polish_url(repo.remotes[0].url, expand_vars=False))
# END handle remote repo
return repo

Expand Down
15 changes: 9 additions & 6 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ def is_exec(fpath: str) -> bool:
return progs


def _cygexpath(drive: Optional[str], path: str) -> str:
def _cygexpath(drive: Optional[str], path: str, expand_vars: bool = True) -> str:
if osp.isabs(path) and not drive:
# Invoked from `cygpath()` directly with `D:Apps\123`?
# It's an error, leave it alone just slashes)
p = path # convert to str if AnyPath given
else:
p = path and osp.normpath(osp.expandvars(osp.expanduser(path)))
p = path and osp.normpath(osp.expandvars(osp.expanduser(path)) if expand_vars else path)
if osp.isabs(p):
if drive:
# Confusing, maybe a remote system should expand vars.
Expand Down Expand Up @@ -416,20 +416,23 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
)


def cygpath(path: str) -> str:
def cygpath(path: str, expand_vars: bool = True) -> str:
"""Use :meth:`git.cmd.Git.polish_url` instead, that works on any environment."""
path = os.fspath(path) # Ensure is str and not AnyPath.
# Fix to use Paths when 3.5 dropped. Or to be just str if only for URLs?
if not path.startswith(("/cygdrive", "//", "/proc/cygdrive")):
for regex, parser, recurse in _cygpath_parsers:
match = regex.match(path)
if match:
path = parser(*match.groups())
if parser is _cygexpath:
path = parser(*match.groups(), expand_vars=expand_vars)
else:
path = parser(*match.groups())
if recurse:
path = cygpath(path)
path = cygpath(path, expand_vars=expand_vars)
break
else:
path = _cygexpath(None, path)
path = _cygexpath(None, path, expand_vars=expand_vars)

return path

Expand Down
41 changes: 40 additions & 1 deletion test/test_clone.py
Loading