Skip to content

Commit 64487ae

Browse files
committed
sync(fix): Preserve Mercurial remote settings
why: Loaded remotes use GitRemote objects that the Mercurial backend cannot consume, and wire mappings must omit their key name. what: Convert native path settings at the backend boundary and serialize Git and Mercurial fetch/push URLs separately. Verify selected-source updates through direct calls and owned workers.
1 parent c1cbfac commit 64487ae

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎src/vcspull/_internal/sync.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from libvcs import BaseSync, SyncPolicy, SyncResult, SyncTarget
1111
from libvcs._internal.shortcuts import create_project
1212
from libvcs._internal.types import VCSLiteral
13-
from libvcs.sync.git import GitOptions
13+
from libvcs.sync.git import GitOptions, GitRemote
1414
from libvcs.sync.hg import HgOptions
1515
from libvcs.sync.svn import SvnOptions
1616

@@ -41,6 +41,13 @@ def create_sync_project(
4141
}
4242
if "remotes" in repo:
4343
arguments["remotes"] = repo["remotes"]
44+
if vcs == "hg":
45+
arguments["remotes"] = {
46+
name: {"fetch_url": remote.fetch_url, "push_url": remote.push_url}
47+
if isinstance(remote, GitRemote)
48+
else remote
49+
for name, remote in repo["remotes"].items()
50+
}
4451
return create_project(vcs=vcs, **arguments)
4552

4653

‎src/vcspull/_internal/sync_process.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from libvcs import RecoveryToken, SyncConflict, SyncResult
2222
from libvcs.sync.git import GitRemote
23+
from libvcs.sync.hg import HgRemote
2324

2425
from vcspull._internal.sync import sync_result_data
2526

@@ -92,8 +93,8 @@ def _worker_command(control_fd: int) -> list[str]:
9293
def _json_default(value: t.Any) -> str | dict[str, t.Any]:
9394
if isinstance(value, os.PathLike):
9495
return str(os.fspath(value))
95-
if isinstance(value, GitRemote):
96-
return dataclasses.asdict(value)
96+
if isinstance(value, (GitRemote, HgRemote)):
97+
return {"fetch_url": value.fetch_url, "push_url": value.push_url}
9798
message = f"sync request contains unsupported {type(value).__name__}"
9899
raise TypeError(message)
99100

‎tests/test_sync.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,53 @@ def test_sync_honors_configured_drift_policy(
831831
assert repo.get_position() == original
832832

833833

834+
@pytest.mark.parametrize("worker", [False, True])
835+
def test_hg_configured_remote_reaches_native_sync(
836+
tmp_path: pathlib.Path,
837+
hg_repo: HgSync,
838+
worker: bool,
839+
) -> None:
840+
"""Loaded Mercurial paths retain pull selection and separate push URLs."""
841+
from vcspull._internal.sync_process import run_sync_process
842+
843+
upstream = HgSync(url=hg_repo.url, path=tmp_path / "upstream")
844+
upstream.obtain()
845+
(upstream.path / "next").write_text("new upstream revision\n")
846+
upstream.run(["add", "next"])
847+
upstream.run(["commit", "-m", "advance upstream"])
848+
expected = upstream.get_revision()
849+
push_url = (tmp_path / "push-only").as_uri()
850+
config = tmp_path / "repos.yaml"
851+
save_config_yaml(
852+
config,
853+
{
854+
str(tmp_path): {
855+
"project": {
856+
"repo": "hg+" + hg_repo.url,
857+
"path": str(hg_repo.path),
858+
"remotes": {
859+
"upstream": {
860+
"fetch_url": str(upstream.path),
861+
"push_url": push_url,
862+
}
863+
},
864+
"working_copy": {"branch": "default", "remote": "upstream"},
865+
}
866+
}
867+
},
868+
)
869+
entry = load_configs([config])[0]
870+
if worker:
871+
outcome = run_sync_process(
872+
entry, progress_callback=lambda *args: None, timeout=5, is_human=False
873+
)
874+
assert outcome.status == "synced", outcome.error
875+
else:
876+
assert update_repo(entry).result.ok
877+
assert hg_repo.get_revision() == expected
878+
assert hg_repo.remotes()["upstream"].push_url == push_url
879+
880+
834881
def test_sync_keeps_tag_selector_distinct_from_branch(
835882
tmp_path: pathlib.Path,
836883
create_git_remote_repo: CreateRepoFn,

0 commit comments

Comments
 (0)