Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(workspace): stop dropping the repo you pointed at when it is a submodule (#2196)

formatme386aeea29460
diff --git a/packages/core/src/repowise/core/workspace/scanner.py b/packages/core/src/repowise/core/workspace/scanner.py
index 2cb6bd8b9..841b24b34 100644
--- a/packages/core/src/repowise/core/workspace/scanner.py
+++ b/packages/core/src/repowise/core/workspace/scanner.py
@@ -88,7 +88,10 @@ def scan_for_repos(
- If *root* itself is a git repo, returns a single-element result.
- Stops descending once a ``.git`` boundary is found (no nested repos).
- Skips common junk directories (``node_modules``, ``.venv``, etc.).
- - Submodules (``.git`` is a file) are excluded unless *include_submodules* is True.
+ - Submodules (``.git`` is a file) found *during the walk* are excluded
+ unless *include_submodules* is True. The flag never applies to *root*
+ itself: that is the repo the caller explicitly pointed at, not something
+ discovery turned up, so it is always eligible.
"""
root = Path(root).resolve()
@@ -134,17 +137,21 @@ def scan_for_repos(
# If root is a git repo and no sub-repos found → single-repo result
# If root is a git repo AND sub-repos found → include root in the list
+ #
+ # Neither branch consults ``include_submodules``. That flag decides whether
+ # the walk descends into submodules it *discovers*; the root is not a
+ # discovery, it is the path the caller named. Gating it here meant that
+ # running `repowise init` inside a submodule that itself contains ordinary
+ # nested clones built a workspace out of the clones and silently left the
+ # targeted repo unindexed and unselectable.
if root_is_repo:
if not found:
# Pure single-repo — no sub-repos
- if root_is_sub and not include_submodules:
- return ScanResult(repos=[], root=root)
aliases = _generate_aliases([(root, root)])
repo = _make_repo(root, root, aliases[root], root_is_sub)
return ScanResult(repos=[repo], root=root)
# Root + sub-repos → workspace mode; add root to the list
- if not root_is_sub or include_submodules:
- found.insert(0, (root, root_is_sub))
+ found.insert(0, (root, root_is_sub))
# Sort by relative path for deterministic ordering
found.sort(key=lambda item: item[0].relative_to(root).as_posix())
diff --git a/tests/unit/workspace/test_scanner.py b/tests/unit/workspace/test_scanner.py
index b69099920..b0d1b3f49 100644
--- a/tests/unit/workspace/test_scanner.py
+++ b/tests/unit/workspace/test_scanner.py
@@ -193,12 +193,48 @@ class TestScanSubmodules:
sub = next(r for r in result.repos if r.name == "sub-repo")
assert sub.is_submodule is True
- def test_submodule_at_root_excluded(self, tmp_path: Path) -> None:
- """Root itself is a submodule and include_submodules=False."""
+ def test_root_submodule_is_scannable_on_its_own(self, tmp_path: Path) -> None:
+ """`include_submodules` filters discovery, never the path you named.
+
+ Pointing repowise at a directory is the decision to index it. Returning
+ nothing here left `repowise init` inside any submodule with no repo to
+ work on.
+ """
(tmp_path / ".git").write_text("gitdir: ../.git/modules/x")
result = scan_for_repos(tmp_path, include_submodules=False)
- assert len(result.repos) == 0
+ assert [r.path for r in result.repos] == [tmp_path.resolve()]
+ assert result.repos[0].is_submodule is True
+
+ def test_root_submodule_leads_its_own_workspace(self, tmp_path: Path) -> None:
+ """A submodule holding ordinary clones must head the workspace list.
+
+ The real topology this comes from: `silo` is a submodule of a parent
+ checkout and carries two plain nested clones. The clones are not
+ submodules, so they are discovered whatever the flag says, which used to
+ flip the run into workspace mode and then drop the one repo the user was
+ standing in -- unselectable, unindexed, and with no hint why.
+ """
+ (tmp_path / ".git").write_text("gitdir: ../.git/modules/silo")
+ _make_repo(tmp_path, "server_bases/Exorth-rsps")
+ _make_repo(tmp_path, "tools/osrs-world-map-object-dumper")
+
+ result = scan_for_repos(tmp_path, include_submodules=False)
+
+ assert result.repos[0].path == tmp_path.resolve()
+ assert result.repos[0].is_submodule is True
+ assert [r.name for r in result.repos[1:]] == [
+ "Exorth-rsps",
+ "osrs-world-map-object-dumper",
+ ]
+
+ def test_discovered_submodule_still_respects_the_flag(self, tmp_path: Path) -> None:
+ """The root rule must not leak into discovery: a submodule *found* under
+ a plain root stays excluded by default."""
+ _make_repo(tmp_path, "main-repo")
+ _make_submodule(tmp_path, "sub-repo")
+
+ assert [r.name for r in scan_for_repos(tmp_path).repos] == ["main-repo"]
# ---------------------------------------------------------------------------