Skip to content

Commit d352bb4

Browse files
committed
feat(import[dry-run]) Display action summary counts in dry-run mode
why: Dry-run output only showed "Dry run complete" without any summary of what would happen, making it hard for users to preview changes. what: - Add [DRY-RUN] prefixed summary lines for add, update, prune, unchanged, existing, and pinned counts before the "Dry run complete" message - Add test verifying summary counts appear in dry-run caplog output Fixes #527
1 parent 95f0bb4 commit d352bb4

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/vcspull/cli/import_cmd/_common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,36 @@ def _run_import(
10101010
return 1
10111011

10121012
if dry_run:
1013+
if added_count > 0:
1014+
log.info(
1015+
"[DRY-RUN] Would add %s repositories",
1016+
colors.info(str(added_count)),
1017+
)
1018+
if updated_url_count > 0:
1019+
log.info(
1020+
"[DRY-RUN] Would update %s repository URLs",
1021+
colors.info(str(updated_url_count)),
1022+
)
1023+
if pruned_count > 0:
1024+
log.info(
1025+
"[DRY-RUN] Would prune %s stale entries",
1026+
colors.info(str(pruned_count)),
1027+
)
1028+
if skip_unchanged_count > 0:
1029+
log.info(
1030+
"[DRY-RUN] %s repositories unchanged",
1031+
colors.info(str(skip_unchanged_count)),
1032+
)
1033+
if skip_existing_count > 0:
1034+
log.info(
1035+
"[DRY-RUN] Skipped %s existing repositories",
1036+
colors.info(str(skip_existing_count)),
1037+
)
1038+
if skip_pinned_count > 0:
1039+
log.info(
1040+
"[DRY-RUN] Skipped %s pinned repositories",
1041+
colors.info(str(skip_pinned_count)),
1042+
)
10131043
log.info(
10141044
"\n%s Dry run complete. Would write to %s",
10151045
colors.warning("→"),

tests/cli/test_import_repos.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,6 +3722,67 @@ def test_import_prune_dry_run(
37223722
assert "stale-repo" in final_config["~/repos/"]
37233723

37243724

3725+
def test_import_dry_run_shows_summary_counts(
3726+
tmp_path: pathlib.Path,
3727+
monkeypatch: MonkeyPatch,
3728+
caplog: pytest.LogCaptureFixture,
3729+
) -> None:
3730+
"""--dry-run displays summary counts (add, prune, unchanged)."""
3731+
caplog.set_level(logging.INFO)
3732+
monkeypatch.setenv("HOME", str(tmp_path))
3733+
workspace = tmp_path / "repos"
3734+
workspace.mkdir()
3735+
config_file = tmp_path / ".vcspull.yaml"
3736+
3737+
# Existing: unchanged repo + stale repo (will be pruned)
3738+
save_config_yaml(
3739+
config_file,
3740+
{
3741+
"~/repos/": {
3742+
"repo1": {
3743+
"repo": _SSH,
3744+
"metadata": {"imported_from": "github:testuser"},
3745+
},
3746+
"stale-repo": {
3747+
"repo": "git+git@github.com:testuser/stale-repo.git",
3748+
"metadata": {"imported_from": "github:testuser"},
3749+
},
3750+
}
3751+
},
3752+
)
3753+
3754+
# Remote has repo1 (unchanged) + repo2 (new). stale-repo is missing → prune.
3755+
importer = MockImporter(
3756+
repos=[_make_repo("repo1"), _make_repo("repo2")],
3757+
)
3758+
_run_import(
3759+
importer,
3760+
service_name="github",
3761+
target="testuser",
3762+
workspace=str(workspace),
3763+
mode="user",
3764+
language=None,
3765+
topics=None,
3766+
min_stars=0,
3767+
include_archived=False,
3768+
include_forks=False,
3769+
limit=100,
3770+
config_path_str=str(config_file),
3771+
dry_run=True,
3772+
yes=True,
3773+
output_json=False,
3774+
output_ndjson=False,
3775+
color="never",
3776+
sync=True,
3777+
import_source="github:testuser",
3778+
)
3779+
3780+
assert "[DRY-RUN] Would add 1 repositories" in caplog.text
3781+
assert "[DRY-RUN] Would prune 1 stale entries" in caplog.text
3782+
assert "[DRY-RUN] 1 repositories unchanged" in caplog.text
3783+
assert "Dry run complete" in caplog.text
3784+
3785+
37253786
def test_import_parser_has_prune_flag() -> None:
37263787
"""The shared parent parser must expose --prune."""
37273788
from vcspull.cli.import_cmd._common import _create_shared_parent

0 commit comments

Comments
 (0)