Skip to content

Commit 039db68

Browse files
committed
fix(import[dry-run]) Include provenance tagging in dry-run change detection
why: The dry-run gate only checked added/updated/pruned counts but omitted provenance_tagged_count, causing "No changes to write" even when a real run would save provenance tags. The count was always 0 during dry-run because it was only incremented inside `if not dry_run`. what: - Restructure SKIP_UNCHANGED block to count provenance tagging regardless of dry_run, while only mutating config when not dry_run - Add needs_tag check for idempotent counting (only count when the tag is actually missing or different) - Add "[DRY-RUN] Would tag N repositories" report line - Include provenance_tagged_count in the "Would write to" gate - Add test_import_dry_run_provenance_tag_shows_write_message
1 parent 3f27231 commit 039db68

2 files changed

Lines changed: 82 additions & 10 deletions

File tree

src/vcspull/cli/import_cmd/_common.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,28 @@ def _run_import(
965965
updated_url_count += 1
966966
elif action == ImportAction.SKIP_UNCHANGED:
967967
skip_unchanged_count += 1
968-
if not dry_run and import_source:
968+
if import_source:
969969
live = raw_config[repo_workspace_label].get(repo.name)
970970
if isinstance(live, dict):
971-
if not isinstance(live.get("metadata"), dict):
972-
live["metadata"] = {}
973-
live.setdefault("metadata", {})["imported_from"] = import_source
974-
provenance_tagged_count += 1
971+
existing_meta = live.get("metadata")
972+
needs_tag = (
973+
not isinstance(existing_meta, dict)
974+
or existing_meta.get("imported_from") != import_source
975+
)
976+
if needs_tag:
977+
if not dry_run:
978+
if not isinstance(existing_meta, dict):
979+
live["metadata"] = {}
980+
live.setdefault("metadata", {})["imported_from"] = (
981+
import_source
982+
)
983+
provenance_tagged_count += 1
975984
elif isinstance(live, str):
976-
raw_config[repo_workspace_label][repo.name] = {
977-
"repo": live,
978-
"metadata": {"imported_from": import_source},
979-
}
985+
if not dry_run:
986+
raw_config[repo_workspace_label][repo.name] = {
987+
"repo": live,
988+
"metadata": {"imported_from": import_source},
989+
}
980990
provenance_tagged_count += 1
981991
elif action == ImportAction.SKIP_EXISTING:
982992
skip_existing_count += 1
@@ -1056,7 +1066,17 @@ def _run_import(
10561066
"[DRY-RUN] Skipped %s pinned repositories",
10571067
colors.info(str(skip_pinned_count)),
10581068
)
1059-
if added_count > 0 or updated_url_count > 0 or pruned_count > 0:
1069+
if provenance_tagged_count > 0:
1070+
log.info(
1071+
"[DRY-RUN] Would tag %s repositories with import provenance",
1072+
colors.info(str(provenance_tagged_count)),
1073+
)
1074+
if (
1075+
added_count > 0
1076+
or updated_url_count > 0
1077+
or pruned_count > 0
1078+
or provenance_tagged_count > 0
1079+
):
10601080
log.info(
10611081
"\n%s Dry run complete. Would write to %s",
10621082
colors.warning("→"),

tests/cli/test_import_repos.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,6 +4138,58 @@ def test_import_dry_run_no_changes_no_write_message(
41384138
assert "Would write to" not in caplog.text
41394139

41404140

4141+
def test_import_dry_run_provenance_tag_shows_write_message(
4142+
tmp_path: pathlib.Path,
4143+
monkeypatch: MonkeyPatch,
4144+
caplog: pytest.LogCaptureFixture,
4145+
) -> None:
4146+
"""Dry run reports 'Would write' when only provenance tagging is needed."""
4147+
caplog.set_level(logging.INFO)
4148+
monkeypatch.setenv("HOME", str(tmp_path))
4149+
workspace = tmp_path / "repos"
4150+
workspace.mkdir()
4151+
config_file = tmp_path / ".vcspull.yaml"
4152+
4153+
# Repo URL matches but NO imported_from tag → provenance tagging needed
4154+
save_config_yaml(
4155+
config_file,
4156+
{
4157+
"~/repos/": {
4158+
"repo1": {
4159+
"repo": _SSH,
4160+
},
4161+
},
4162+
},
4163+
)
4164+
4165+
importer = MockImporter(repos=[_make_repo("repo1")])
4166+
_run_import(
4167+
importer,
4168+
service_name="github",
4169+
target="testuser",
4170+
workspace=str(workspace),
4171+
mode="user",
4172+
language=None,
4173+
topics=None,
4174+
min_stars=0,
4175+
include_archived=False,
4176+
include_forks=False,
4177+
limit=100,
4178+
config_path_str=str(config_file),
4179+
dry_run=True,
4180+
yes=True,
4181+
output_json=False,
4182+
output_ndjson=False,
4183+
color="never",
4184+
sync=True,
4185+
import_source="github:testuser",
4186+
)
4187+
4188+
assert "Would tag 1 repositories" in caplog.text
4189+
assert "Would write to" in caplog.text
4190+
assert "No changes to write" not in caplog.text
4191+
4192+
41414193
# ---------------------------------------------------------------------------
41424194
# Collision / cross-source prune tests
41434195
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)