fix(git): prefer connections.proxy over legacy flat keys

Keep git proxy lookup aligned with layered config, with proxy_* fallback.
This commit is contained in:
Zhengshou Lai
2026-07-30 15:32:48 +08:00
parent 157872c233
commit ee85ed822a
+15 -5
View File
@@ -11,12 +11,22 @@ from mytoolkit.config import config
def _get_proxies() -> dict[str, str]:
"""Get git proxies from config."""
proxies = {}
"""Get git proxies from config.
Prefers hierarchical ``connections.proxy.<name>``; falls back to legacy
flat ``proxy_<name>`` keys for older configs.
"""
proxies: dict[str, str] = {}
nested = config.get("connections.proxy")
if isinstance(nested, dict):
for name, value in nested.items():
if isinstance(value, str) and value:
proxies[str(name)] = value
if proxies:
return proxies
for key, value in config.get_all().items():
if key.startswith("proxy_"):
name = key[6:] # Remove 'proxy_' prefix
proxies[name] = value
if key.startswith("proxy_") and isinstance(value, str) and value:
proxies[key[6:]] = value
return proxies