fix: prevent environment expansion in remote URLs by Byron · Pull Request #2181 · 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
2 changes: 1 addition & 1 deletion git/objects/submodule/base.py
2 changes: 1 addition & 1 deletion git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def create(cls, repo: "Repo", name: str, url: str, allow_unsafe_protocols: bool
"""
scmd = "add"
kwargs["insert_kwargs_after"] = scmd
url = Git.polish_url(url)
url = Git.polish_url(url, expand_vars=False)
if not allow_unsafe_protocols:
Git.check_unsafe_protocols(url)
repo.git.remote(scmd, "--", name, url, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import os
import os.path as osp
from pathlib import Path
import random
Expand Down Expand Up @@ -685,6 +686,14 @@ def test_multiple_urls(self, rw_repo):
# Will raise fatal: Will not delete all non-push URLs.
self.assertRaises(GitCommandError, remote.delete_url, test3)

@with_rw_repo("HEAD", bare=False)
def test_create_does_not_expand_environment_variables_in_url(self, rw_repo):
url = "https://example.com/${GITPYTHON_TEST_SECRET}/repo.git"
with mock.patch.dict(os.environ, {"GITPYTHON_TEST_SECRET": "sensitive-value"}):
remote = rw_repo.create_remote("untrusted", url)

assert remote.url == url

def test_fetch_error(self):
rem = self.rorepo.remote("origin")
msg = (
Expand Down
14 changes: 14 additions & 0 deletions test/test_submodule.py
Loading