Skip to content

fix: respect specified paths in git repository#263

Merged
kezhenxu94 merged 3 commits into
apache:mainfrom
jhult:fix/respect-paths-git
Apr 6, 2026
Merged

fix: respect specified paths in git repository#263
kezhenxu94 merged 3 commits into
apache:mainfrom
jhult:fix/respect-paths-git

Conversation

@jhult

@jhult jhult commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixed header check/fix commands to respect specified file paths even when in a git repository
  • Previously, specifying paths in a git repo would incorrectly check all tracked files instead of just the specified paths
  • Now supports individual files, directories, and glob patterns correctly in all contexts

Changes

  • Added matchPaths() function in pkg/header/check.go to filter files using glob pattern matching
  • Updated listFiles() to respect configured paths when in git repositories
  • Updated help text for header check and header fix commands to clarify accepted path types
  • Added TestMatchPaths() to verify pattern matching behavior

Testing

  • All existing tests pass
  • New TestMatchPaths() validates exact file matches, glob patterns, and double-star patterns
  • Verified behavior with single files, multiple files, and glob patterns in git repositories

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 check and header fix commands
  • 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.

Comment thread pkg/header/check_test.go
Comment thread pkg/header/check.go
Comment thread commands/header_fix.go Outdated
@wu-sheng wu-sheng added the enhancement New feature or request label Feb 18, 2026
Comment thread commands/header_check.go Outdated
Comment on lines +46 to +51
var filteredArgs []string
for _, arg := range args {
if header.MatchPaths(arg, h.Paths) {
filteredArgs = append(filteredArgs, arg)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Both check and fix commands now do h.Paths = args without MatchPaths filtering.

@wu-sheng

wu-sheng commented Apr 5, 2026

Copy link
Copy Markdown
Member

@jhult Are you still working on this?

jhult added 3 commits April 5, 2026 15:46
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.
@jhult
jhult requested a review from kezhenxu94 April 5, 2026 20:49
@jhult

jhult commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

@kezhenxu94 - this is ready for another review.

@kezhenxu94 kezhenxu94 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kezhenxu94
kezhenxu94 merged commit 6ac3558 into apache:main Apr 6, 2026
2 checks passed
@jhult
jhult deleted the fix/respect-paths-git branch April 6, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants