Fix directory pathspec matching in reset and add test#534
Merged
Conversation
- Fix pathspec matching in reset_hooks.rs, rebase_authorship.rs, and checkout_hooks.rs to properly handle directory pathspecs by checking for trailing slash separator (e.g. 'src' now correctly matches 'src/file.txt' but not 'srcfile.txt') - Add test_reset_with_directory_pathspec test verifying that git reset <commit> -- <directory> preserves AI authorship for files outside the reset directory Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
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.
Fix directory pathspec matching in reset, checkout, and rebase authorship
Summary
Fixes a bug where pathspec matching used bare
starts_with(pathspec)without a directory separator check. This meant a pathspec likesrccould incorrectly match files likesrcutils/foo.txt(false positive). The fix ensures directory boundaries are respected by checking for a trailing/separator, consistent with the existing correct implementation instash_hooks.rs::file_matches_pathspecs.Files changed:
src/commands/hooks/reset_hooks.rs— checkpoint entry filtering during pathspec resetsrc/authorship/rebase_authorship.rs— file filtering inreconstruct_working_log_after_resetsrc/commands/hooks/checkout_hooks.rs—matches_any_pathspechelpertests/reset.rs— newtest_reset_with_directory_pathspectestCloses #234
Review & Testing Checklist for Human
srcshould matchsrc/file.txtbut NOTsrcfile.txt; pathspecsrc/(trailing slash) should also matchsrc/file.txtsrc/app.rsactually lost its AI attribution after reset. Consider whether this gap matters.checkout_hooks.rshas no dedicated test coverage — verify manually or add a test if concernedstash_hooks.rs::file_matches_pathspecs, this PR does not add glob pattern support (src/*). Confirm this is acceptable.Suggested test plan: Run
git reset <commit> -- <directory>in a repo with files in sibling directories (e.g.,src/andsrclib/) and confirm only the intended directory is affected.Notes