Skip to content

Commit 3f27231

Browse files
committed
fix(import[dry-run]) Gate "Would write to" on having actual changes
why: The dry-run path unconditionally printed "Would write to ..." even when all repos were SKIP_UNCHANGED, misleading users into thinking a write would occur. what: - Gate the "Would write to" message on added/updated/pruned counts > 0 - Show "No changes to write" when no modifications would be made - Add test verifying no-changes dry run produces correct message
1 parent 8405666 commit 3f27231

2 files changed

Lines changed: 63 additions & 5 deletions

File tree

src/vcspull/cli/import_cmd/_common.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,11 +1056,17 @@ def _run_import(
10561056
"[DRY-RUN] Skipped %s pinned repositories",
10571057
colors.info(str(skip_pinned_count)),
10581058
)
1059-
log.info(
1060-
"\n%s Dry run complete. Would write to %s",
1061-
colors.warning("→"),
1062-
colors.muted(display_config_path),
1063-
)
1059+
if added_count > 0 or updated_url_count > 0 or pruned_count > 0:
1060+
log.info(
1061+
"\n%s Dry run complete. Would write to %s",
1062+
colors.warning("→"),
1063+
colors.muted(display_config_path),
1064+
)
1065+
else:
1066+
log.info(
1067+
"%s Dry run complete. No changes to write.",
1068+
colors.success("✓"),
1069+
)
10641070
return 0
10651071

10661072
if (

tests/cli/test_import_repos.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,6 +4086,58 @@ def test_import_dry_run_shows_summary_counts(
40864086
assert "Dry run complete" in caplog.text
40874087

40884088

4089+
def test_import_dry_run_no_changes_no_write_message(
4090+
tmp_path: pathlib.Path,
4091+
monkeypatch: MonkeyPatch,
4092+
caplog: pytest.LogCaptureFixture,
4093+
) -> None:
4094+
"""Dry run with zero changes says 'No changes' instead of 'Would write'."""
4095+
caplog.set_level(logging.INFO)
4096+
monkeypatch.setenv("HOME", str(tmp_path))
4097+
workspace = tmp_path / "repos"
4098+
workspace.mkdir()
4099+
config_file = tmp_path / ".vcspull.yaml"
4100+
4101+
# All repos already match → SKIP_UNCHANGED, no adds/updates/prunes
4102+
save_config_yaml(
4103+
config_file,
4104+
{
4105+
"~/repos/": {
4106+
"repo1": {
4107+
"repo": _SSH,
4108+
"metadata": {"imported_from": "github:testuser"},
4109+
},
4110+
},
4111+
},
4112+
)
4113+
4114+
importer = MockImporter(repos=[_make_repo("repo1")])
4115+
_run_import(
4116+
importer,
4117+
service_name="github",
4118+
target="testuser",
4119+
workspace=str(workspace),
4120+
mode="user",
4121+
language=None,
4122+
topics=None,
4123+
min_stars=0,
4124+
include_archived=False,
4125+
include_forks=False,
4126+
limit=100,
4127+
config_path_str=str(config_file),
4128+
dry_run=True,
4129+
yes=True,
4130+
output_json=False,
4131+
output_ndjson=False,
4132+
color="never",
4133+
sync=True,
4134+
import_source="github:testuser",
4135+
)
4136+
4137+
assert "No changes to write" in caplog.text
4138+
assert "Would write to" not in caplog.text
4139+
4140+
40894141
# ---------------------------------------------------------------------------
40904142
# Collision / cross-source prune tests
40914143
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)