Skip to content

Commit 1ecb6c1

Browse files
committed
types/config(fix[ConfigDict,extract_repos]): Add workspace_root field to repo configs
why: workspace_root field was showing as empty strings in JSON output from list and status commands. This field is essential for identifying which workspace section a repository belongs to, especially for automation and tooling that processes vcspull output. what: - Add workspace_root field to ConfigDict TypedDict in types.py - Set workspace_root in extract_repos() to preserve original directory label - Include workspace_root in check_repo_status() return value - Update test fixtures to include workspace_root field for type compliance The workspace_root now correctly shows labels like "~/study/ai/" or "~/work/python/" in JSON output, matching the keys from .vcspull.yaml config.
1 parent ac4c006 commit 1ecb6c1

5 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/vcspull/cli/status.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ def check_repo_status(repo: ConfigDict, detailed: bool = False) -> dict[str, t.A
9090
"""
9191
repo_path = pathlib.Path(str(repo.get("path", "")))
9292
repo_name = repo.get("name", "unknown")
93+
workspace_root = repo.get("workspace_root", "")
9394

9495
status: dict[str, t.Any] = {
9596
"name": repo_name,
9697
"path": str(repo_path),
98+
"workspace_root": workspace_root,
9799
"exists": False,
98100
"is_git": False,
99101
"clean": None,

src/vcspull/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def extract_repos(
108108
if "name" not in conf:
109109
conf["name"] = repo
110110

111+
if "workspace_root" not in conf:
112+
conf["workspace_root"] = directory
113+
111114
if "path" not in conf:
112115
conf["path"] = expand_dir(
113116
pathlib.Path(expand_dir(pathlib.Path(directory), cwd=cwd))

src/vcspull/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ConfigDict(TypedDict):
6060
name: str
6161
path: pathlib.Path
6262
url: str
63+
workspace_root: str
6364
remotes: NotRequired[GitSyncRemoteDict | None]
6465
shell_command_after: NotRequired[list[str] | None]
6566

tests/fixtures/example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,35 @@
4646
"name": "linux",
4747
"path": pathlib.Path("/home/me/myproject/study/linux"),
4848
"url": "git+git://git.kernel.org/linux/torvalds/linux.git",
49+
"workspace_root": "/home/me/myproject/study/",
4950
},
5051
{
5152
"vcs": "git",
5253
"name": "freebsd",
5354
"path": pathlib.Path("/home/me/myproject/study/freebsd"),
5455
"url": "git+https://github.com/freebsd/freebsd.git",
56+
"workspace_root": "/home/me/myproject/study/",
5557
},
5658
{
5759
"vcs": "git",
5860
"name": "sphinx",
5961
"path": pathlib.Path("/home/me/myproject/study/sphinx"),
6062
"url": "hg+https://bitbucket.org/birkenfeld/sphinx",
63+
"workspace_root": "/home/me/myproject/study/",
6164
},
6265
{
6366
"vcs": "git",
6467
"name": "docutils",
6568
"path": pathlib.Path("/home/me/myproject/study/docutils"),
6669
"url": "svn+http://svn.code.sf.net/p/docutils/code/trunk",
70+
"workspace_root": "/home/me/myproject/study/",
6771
},
6872
{
6973
"vcs": "git",
7074
"name": "kaptan",
7175
"url": "git+git@github.com:tony/kaptan.git",
7276
"path": pathlib.Path("/home/me/myproject/github_projects/kaptan"),
77+
"workspace_root": "/home/me/myproject/github_projects/",
7378
"remotes": {
7479
"upstream": GitRemote(
7580
name="upstream",
@@ -88,13 +93,15 @@
8893
"name": ".vim",
8994
"path": pathlib.Path("/home/me/myproject/.vim"),
9095
"url": "git+git@github.com:tony/vim-config.git",
96+
"workspace_root": "/home/me/myproject",
9197
"shell_command_after": ["ln -sf /home/me/.vim/.vimrc /home/me/.vimrc"],
9298
},
9399
{
94100
"vcs": "git",
95101
"name": ".tmux",
96102
"path": pathlib.Path("/home/me/myproject/.tmux"),
97103
"url": "git+git@github.com:tony/tmux-config.git",
104+
"workspace_root": "/home/me/myproject",
98105
"shell_command_after": ["ln -sf /home/me/.tmux/.tmux.conf /home/me/.tmux.conf"],
99106
},
100107
]

tests/test_sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def test_updating_remote(
268268
"name": "myclone",
269269
"path": tmp_path / "study/myrepo/myclone",
270270
"url": f"git+file://{dummy_repo}",
271+
"workspace_root": str(tmp_path / "study/myrepo/"),
271272
"remotes": {
272273
mirror_name: GitRemote(
273274
name=mirror_name,

0 commit comments

Comments
 (0)