Fix TOML save order: write scalars before sections

TOML sections capture all subsequent keys until the next section.
default_remote was being written after [remotes] section, making
it appear as part of remotes dict instead of top-level config.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Adam Ladachowski
2026-02-14 02:51:48 +01:00
parent 318cc91eb6
commit ec3f1afb41
+12 -4
View File
@@ -120,6 +120,18 @@ def save_config(config: dict[str, Any]) -> None:
CONFIG_DIR.mkdir(parents=True, exist_ok=True) CONFIG_DIR.mkdir(parents=True, exist_ok=True)
lines: list[str] = [] lines: list[str] = []
# Write scalar values first (before any sections)
for key, value in config.items():
if not isinstance(value, dict):
if isinstance(value, str):
lines.append(f'{key} = "{value}"')
else:
lines.append(f"{key} = {value}")
if lines:
lines.append("")
# Then write sections (dicts)
for key, value in config.items(): for key, value in config.items():
if isinstance(value, dict): if isinstance(value, dict):
lines.append(f"[{key}]") lines.append(f"[{key}]")
@@ -129,10 +141,6 @@ def save_config(config: dict[str, Any]) -> None:
else: else:
lines.append(f"{k} = {v}") lines.append(f"{k} = {v}")
lines.append("") lines.append("")
elif isinstance(value, str):
lines.append(f'{key} = "{value}"')
else:
lines.append(f"{key} = {value}")
CONFIG_FILE.write_text("\n".join(lines) + "\n") CONFIG_FILE.write_text("\n".join(lines) + "\n")