| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e59d9ba commit 333c6ba
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -608,7 +608,7 @@ def add( | |||
| 608 | 608 | # END verify url | |
| 609 | 609 | ||
| 610 | 610 | ## See #525 for ensuring git URLs in config-files are valid under Windows. | |
| 611 | - url = Git.polish_url(url) | ||
| 611 | + url = Git.polish_url(url, expand_vars=False) | ||
| 612 | 612 | ||
| 613 | 613 | # It's important to add the URL to the parent config, to let `git submodule` know. | |
| 614 | 614 | # Otherwise there is a '-' character in front of the submodule listing: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -808,7 +808,7 @@ def create(cls, repo: "Repo", name: str, url: str, allow_unsafe_protocols: bool | |||
| 808 | 808 | """ | |
| 809 | 809 | scmd = "add" | |
| 810 | 810 | kwargs["insert_kwargs_after"] = scmd | |
| 811 | - url = Git.polish_url(url) | ||
| 811 | + url = Git.polish_url(url, expand_vars=False) | ||
| 812 | 812 | if not allow_unsafe_protocols: | |
| 813 | 813 | Git.check_unsafe_protocols(url) | |
| 814 | 814 | repo.git.remote(scmd, "--", name, url, **kwargs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ | |
| 5 | 5 | ||
| 6 | 6 | import gc | |
| 7 | + import os | ||
| 7 | 8 | import os.path as osp | |
| 8 | 9 | from pathlib import Path | |
| 9 | 10 | import random | |
@@ -685,6 +686,14 @@ def test_multiple_urls(self, rw_repo): | |||
| 685 | 686 | # Will raise fatal: Will not delete all non-push URLs. | |
| 686 | 687 | self.assertRaises(GitCommandError, remote.delete_url, test3) | |
| 687 | 688 | ||
| 689 | + @with_rw_repo("HEAD", bare=False) | ||
| 690 | + def test_create_does_not_expand_environment_variables_in_url(self, rw_repo): | ||
| 691 | + url = "https://example.com/${GITPYTHON_TEST_SECRET}/repo.git" | ||
| 692 | + with mock.patch.dict(os.environ, {"GITPYTHON_TEST_SECRET": "sensitive-value"}): | ||
| 693 | + remote = rw_repo.create_remote("untrusted", url) | ||
| 694 | + | ||
| 695 | + assert remote.url == url | ||
| 696 | + | ||
| 688 | 697 | def test_fetch_error(self): | |
| 689 | 698 | rem = self.rorepo.remote("origin") | |
| 690 | 699 | msg = ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1355,6 +1355,20 @@ def test_add_no_clone_multi_options_argument(self, rwdir): | |||
| 1355 | 1355 | with self.assertRaises(cp.NoOptionError): | |
| 1356 | 1356 | sm_config.get_value("core", "eol") | |
| 1357 | 1357 | ||
| 1358 | + @with_rw_directory | ||
| 1359 | + def test_add_does_not_expand_environment_variables_in_url(self, rwdir): | ||
| 1360 | + parent = git.Repo.init(osp.join(rwdir, "parent")) | ||
| 1361 | + url = osp.join(rwdir, "${GITPYTHON_TEST_SECRET}") | ||
| 1362 | + source = git.Repo.init(url) | ||
| 1363 | + Path(source.working_tree_dir, "file").write_text("content") | ||
| 1364 | + source.index.add(["file"]) | ||
| 1365 | + source.index.commit("initial") | ||
| 1366 | + | ||
| 1367 | + with mock.patch.dict(os.environ, {"GITPYTHON_TEST_SECRET": "sensitive-value"}): | ||
| 1368 | + sm = Submodule.add(parent, "new", "new", url) | ||
| 1369 | + | ||
| 1370 | + assert sm.url == Git.polish_url(url, expand_vars=False) | ||
| 1371 | + | ||
| 1358 | 1372 | @with_rw_repo("HEAD") | |
| 1359 | 1373 | def test_submodule_add_unsafe_url(self, rw_repo): | |
| 1360 | 1374 | with tempfile.TemporaryDirectory() as tdir: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments