Skip to content

Commit bb9d599

Browse files
authored
vcspull add - Bug fixes to disregard cwd in workspace dir calculation (#483)
why: - path-first adds run from inside the workspace emitted './' instead of the tilde-shortened label - UX regressions reintroduced ambiguity for users relying on matching config paths what: - allow workspace_root_label callers to bypass the cwd short-circuit - ensure path-first CLI flows default to tilde-labelled workspaces unless explicitly asked for './' - promote the regression test from xfail to an assertion verification: - UV_CACHE_DIR=/tmp/uv-cache uv run ruff check . --fix --show-fixes - UV_CACHE_DIR=/tmp/uv-cache uv run ruff format . - UV_CACHE_DIR=/tmp/uv-cache uv run mypy - UV_CACHE_DIR=/tmp/uv-cache uv run py.test -k workspace_label -vv
2 parents 8c79f19 + 9cf8d0e commit bb9d599

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ $ uvx --from 'vcspull' --prerelease allow vcspull
3333

3434
_Upcoming changes will be written here._
3535

36+
### Bug Fixes
37+
38+
#### `vcspull add` keeps tilde workspace labels in path-first mode (#482, #483)
39+
40+
- Running `vcspull add ~/study/python/…` from inside the workspace now logs the
41+
workspace as `~/study/python/` instead of `./`, preserving tilde-shortened
42+
labels for path-first imports.
43+
3644
## vcspull v1.45.0 (2025-11-02)
3745

3846
### Bug Fixes

src/vcspull/cli/add.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ def handle_add_command(args: argparse.Namespace) -> None:
201201
repo_path,
202202
)
203203

204+
workspace_root_arg = getattr(args, "workspace_root_path", None)
204205
workspace_root_input = (
205-
args.workspace_root_path
206-
if getattr(args, "workspace_root_path", None)
206+
workspace_root_arg
207+
if workspace_root_arg is not None
207208
else repo_path.parent.as_posix()
208209
)
209210

@@ -212,6 +213,7 @@ def handle_add_command(args: argparse.Namespace) -> None:
212213
workspace_path,
213214
cwd=cwd,
214215
home=pathlib.Path.home(),
216+
preserve_cwd_label=workspace_root_arg in {".", "./"},
215217
)
216218

217219
summary_url = display_url or config_url
@@ -479,11 +481,18 @@ def _aggregate_items(items: list[tuple[str, t.Any]]) -> dict[str, t.Any]:
479481
cwd=cwd,
480482
)
481483
workspace_label = workspace_map.get(workspace_path)
484+
485+
if workspace_root_path is None:
486+
preserve_workspace_label = path is None
487+
else:
488+
preserve_workspace_label = workspace_root_path in {".", "./"}
489+
482490
if workspace_label is None:
483491
workspace_label = workspace_root_label(
484492
workspace_path,
485493
cwd=cwd,
486494
home=home,
495+
preserve_cwd_label=preserve_workspace_label,
487496
)
488497
workspace_map[workspace_path] = workspace_label
489498
raw_config.setdefault(workspace_label, {})

src/vcspull/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,13 @@ def workspace_root_label(
588588
*,
589589
cwd: pathlib.Path | None = None,
590590
home: pathlib.Path | None = None,
591+
preserve_cwd_label: bool = True,
591592
) -> str:
592593
"""Create a normalized label for a workspace root path."""
593594
cwd = cwd or pathlib.Path.cwd()
594595
home = home or pathlib.Path.home()
595596

596-
if workspace_path == cwd:
597+
if preserve_cwd_label and workspace_path == cwd:
597598
return "./"
598599

599600
try:

tests/cli/test_add.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,3 +890,45 @@ def test_add_repo_no_merge_preserves_duplicate_sections(
890890
expected_repos = set(expected_original_repos) | {new_repo_name}
891891
assert combined_repos == expected_repos, f"{test_id}: repositories mismatch"
892892
assert contains_new_repo, f"{test_id}: new repo missing from duplicate sections"
893+
894+
895+
def test_handle_add_command_workspace_label_from_workspace_root(
896+
tmp_path: pathlib.Path,
897+
monkeypatch: MonkeyPatch,
898+
caplog: t.Any,
899+
) -> None:
900+
"""CLI add should label workspace roots with their tilde path even from root cwd."""
901+
caplog.set_level(logging.INFO)
902+
903+
monkeypatch.setenv("HOME", str(tmp_path))
904+
905+
workspace_root = tmp_path / "study/python"
906+
repo_path = workspace_root / "pytest-docker"
907+
init_git_repo(repo_path, remote_url="https://github.com/avast/pytest-docker")
908+
909+
monkeypatch.chdir(workspace_root)
910+
911+
config_file = tmp_path / ".vcspull.yaml"
912+
913+
args = argparse.Namespace(
914+
repo_path=str(repo_path),
915+
url=None,
916+
override_name=None,
917+
config=str(config_file),
918+
workspace_root_path=None,
919+
dry_run=False,
920+
assume_yes=True,
921+
merge_duplicates=True,
922+
)
923+
924+
handle_add_command(args)
925+
926+
expected_label = "~/study/python/"
927+
assert expected_label in caplog.text
928+
929+
import yaml
930+
931+
with config_file.open(encoding="utf-8") as fh:
932+
config_data = yaml.safe_load(fh)
933+
934+
assert expected_label in config_data

0 commit comments

Comments
 (0)