Add optional submodule scanning - #160
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds opt-in --include-submodules scanning for initialized Git submodules across local detection workflows.
Changes:
- Adds bounded recursive submodule discovery.
- Includes submodule data in detection, manifests, dependencies, layout, and line counts.
- Updates CLI flags, documentation, and tests.
Review findings:
cmd/brief/diff.go— Moderate (3 votes): changed gitlink paths are filtered out after the scan, removing submodule detections.detect/detect.go— Moderate (2 votes): relative roots can cause line counting to include files excluded by the project walk.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Summary |
|---|---|
README.md |
Documents submodule scanning behavior. |
detect/submodules.go |
Discovers submodules and analysis roots. |
detect/detect.go |
Integrates submodules across detection paths and line counts. |
detect/detect_test.go |
Tests scanning, bounds, and counters. |
cmd/brief/threat.go |
Propagates the shared scanning flag. |
cmd/brief/main.go |
Adds the scan flag. |
cmd/brief/main_test.go |
Tests CLI flag behavior. |
cmd/brief/enrich.go |
Adds the enrichment flag. |
cmd/brief/diff.go |
Adds the diff flag and scans changed content. |
Suppressed comments (4)
detect/detect.go:781
- This route override applies equally to names from
SkipDirs, so an explicit--skip=vendoror--skip=nativeis silently ignored when the path leads to an initialized submodule.--include-submodulesneeds to bypass default exclusions to reach submodules belowvendor, but it should not defeat the caller's additional exclusions.
if skipDir {
if !route {
return false
}
nextRouteOnly = true
detect/detect.go:173
loadSubmodulesFromrecords direct submodules even when their path is deeper thanScanDepth(the depth check only guards recursive discovery), so this loop still runsgit ls-filesover the entire out-of-scope submodule in--tracked --include-submodulesmode. A large submodule that the bounded filesystem walk will reject at line 786 can therefore still consume unbounded index output and memory; skip initialized submodules whosepathDepthexceeds the configured depth before loading their indexes.
submoduleRoot := filepath.Join(abs, submodule.Path)
detect/submodules.go:63
loadSubmodulesis also called fromshouldSkipDirPathduring ordinary scans, so this budget is applied even whenIncludeSubmodulesis false. A.gitmoduleswith more entries thanScanLimittherefore setsscanTruncatedand aborts the default walk before its filesystem-entry limit, changing the documented default behavior and potentially hiding root files. Apply the submodule-entry limit only when inclusion is enabled.
if e.ScanLimit > 0 && e.submoduleEntries >= e.ScanLimit {
e.scanTruncated = true
return
detect/submodules.go:107
- Presence of
.gitalone does not prove that the submodule worktree is available: a stale gitdir file can point to a removed path, and an arbitrary.gitdirectory also passes. Include mode will then walk leftover files and report languages/manifests for an unavailable submodule, contrary to the requested missing-content behavior. Validate the worktree with Git before returning true.
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
return false
}
_, err = os.Lstat(filepath.Join(root, ".git"))
return err == nil
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
andrew
force-pushed
the
feature/include-submodules
branch
from
August 27, 2026 14:38
dd5d0d0 to
c9f2d93
Compare
andrew
force-pushed
the
feature/include-submodules
branch
from
August 27, 2026 14:44
c9f2d93 to
b1907dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
--include-submodulesto local scan commands so initialized Git submodules participate in language, tool, manifest, dependency, layout, and line-count detection. Submodules remain excluded by default, and uninitialized worktrees and neighboring skipped directories remain excluded.Keeps submodule discovery within
--scan-depthand--scan-limit.Closes #158
Closes #152