fix: respect specified paths in git repository#263
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where specifying file paths in a git repository would incorrectly check all tracked files instead of just the specified paths. The changes add a matchPaths() function to filter git candidates using glob pattern matching and update command help text to clarify supported path types.
Changes:
- Added
matchPaths()function to filter files by glob patterns - Modified
listFiles()to respect configured paths when in git repositories - Updated help text for
header checkandheader fixcommands - Added test coverage for the new pattern matching logic
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/header/check.go | Added matchPaths() function and integrated it into listFiles() to filter git candidates |
| pkg/header/check_test.go | Added TestMatchPaths() to validate pattern matching behavior |
| commands/header_check.go | Updated command help text to document accepted path types |
| commands/header_fix.go | Updated command help text to document accepted path types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var filteredArgs []string | ||
| for _, arg := range args { | ||
| if header.MatchPaths(arg, h.Paths) { | ||
| filteredArgs = append(filteredArgs, arg) | ||
| } | ||
| } |
There was a problem hiding this comment.
Hi, I think when we pass the paths to the CLI args we intend to check that files regardless of the config file. The args here should be highest priority even if they are not configured in config file
There was a problem hiding this comment.
Fixed. Both check and fix commands now do h.Paths = args without MatchPaths filtering.
|
@jhult Are you still working on this? |
Add matchPaths function to filter git repository files by specified paths, enabling header check/fix to work with files, directories, and glob patterns. Previously, specifying paths in a git repo would check all tracked files.
When paths are passed as CLI args to check/fix commands, set h.Paths = args directly so CLI args take highest priority over config-defined paths. Aligns the fix command with check by using the full check→fix flow, enabling directories and glob patterns as CLI args. Also exports matchPaths as MatchPaths for use in commands.
Add fallback logic in MatchPaths to match files within directory patterns (e.g., "pkg/header/" matches "pkg/header/check.go"), consistent with tryMatchPatten in config.go. Also fix typo in test case pattern for directory without trailing slash.
|
@kezhenxu94 - this is ready for another review. |
Summary
Changes
matchPaths()function inpkg/header/check.goto filter files using glob pattern matchinglistFiles()to respect configured paths when in git repositoriesheader checkandheader fixcommands to clarify accepted path typesTestMatchPaths()to verify pattern matching behaviorTesting
TestMatchPaths()validates exact file matches, glob patterns, and double-star patterns