Skip to content

Commit 6466809

Browse files
committed
cli/discover(fix[path-privacy]): hide scan and repo paths
why: discover still logged absolute directories when skipping repos without remotes or when no repositories were found. what: - wrap repo_path/item and scan_dir in PrivatePath for warning/info logs - capture this behavior with a new test that forces missing remotes via monkeypatch and asserts the log text uses the tilde forms
1 parent 314a85a commit 6466809

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/vcspull/cli/discover.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def discover_repos(
404404
log.warning(
405405
"Could not determine remote URL for git repository "
406406
"at %s. Skipping.",
407-
repo_path,
407+
PrivatePath(repo_path),
408408
)
409409
continue
410410

@@ -420,7 +420,7 @@ def discover_repos(
420420
log.warning(
421421
"Could not determine remote URL for git repository "
422422
"at %s. Skipping.",
423-
item,
423+
PrivatePath(item),
424424
)
425425
continue
426426

@@ -433,7 +433,7 @@ def discover_repos(
433433
Fore.YELLOW,
434434
Style.RESET_ALL,
435435
Fore.BLUE,
436-
scan_dir,
436+
PrivatePath(scan_dir),
437437
Style.RESET_ALL,
438438
)
439439
return

tests/cli/test_discover.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import logging
56
import pathlib
67
import re
78
import subprocess
@@ -809,6 +810,41 @@ def _fake_save(path: pathlib.Path, data: dict[str, t.Any]) -> None:
809810
assert "Successfully updated" in caplog.text
810811

811812

813+
def test_discover_logs_redact_scan_and_repo_paths(
814+
user_path: pathlib.Path,
815+
caplog: pytest.LogCaptureFixture,
816+
monkeypatch: MonkeyPatch,
817+
) -> None:
818+
"""Warnings and info logs should display PrivatePath-collapsed values."""
819+
scan_dir = user_path / "projects"
820+
repo_dir = scan_dir / "demo"
821+
(repo_dir / ".git").mkdir(parents=True, exist_ok=True)
822+
823+
caplog.set_level(logging.INFO, logger="vcspull.cli.discover")
824+
825+
monkeypatch.setattr(
826+
"vcspull.cli.discover.get_git_origin_url",
827+
lambda _path: None,
828+
)
829+
830+
config_file = user_path / ".vcspull.yaml"
831+
config_file.write_text("{}\n", encoding="utf-8")
832+
833+
discover_repos(
834+
scan_dir_str=str(scan_dir),
835+
config_file_path_str=str(config_file),
836+
recursive=False,
837+
workspace_root_override=None,
838+
yes=True,
839+
dry_run=True,
840+
)
841+
842+
repo_display = str(PrivatePath(repo_dir))
843+
scan_display = str(PrivatePath(scan_dir))
844+
assert repo_display in caplog.text
845+
assert scan_display in caplog.text
846+
847+
812848
def test_discover_user_config_prefers_absolute_workspace_label(
813849
tmp_path: pathlib.Path,
814850
monkeypatch: MonkeyPatch,

0 commit comments

Comments
 (0)