[PR #534] Fix directory pathspec matching in reset and add test #545

Closed
opened 2026-03-02 04:13:55 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/git-ai-project/git-ai/pull/534

State: closed
Merged: Yes


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 like src could incorrectly match files like srcutils/foo.txt (false positive). The fix ensures directory boundaries are respected by checking for a trailing / separator, consistent with the existing correct implementation in stash_hooks.rs::file_matches_pathspecs.

Files changed:

  • src/commands/hooks/reset_hooks.rs — checkpoint entry filtering during pathspec reset
  • src/authorship/rebase_authorship.rs — file filtering in reconstruct_working_log_after_reset
  • src/commands/hooks/checkout_hooks.rsmatches_any_pathspec helper
  • tests/reset.rs — new test_reset_with_directory_pathspec test

Closes #234

Review & Testing Checklist for Human

  • Verify the matching logic handles edge cases: pathspec src should match src/file.txt but NOT srcfile.txt; pathspec src/ (trailing slash) should also match src/file.txt
  • The test only asserts that files outside the reset directory retain AI authorship — it does not verify that src/app.rs actually lost its AI attribution after reset. Consider whether this gap matters.
  • The fix in checkout_hooks.rs has no dedicated test coverage — verify manually or add a test if concerned
  • Note: unlike stash_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/ and srclib/) and confirm only the intended directory is affected.

Notes


Open with Devin
**Original Pull Request:** https://github.com/git-ai-project/git-ai/pull/534 **State:** closed **Merged:** Yes --- # 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 like `src` could incorrectly match files like `srcutils/foo.txt` (false positive). The fix ensures directory boundaries are respected by checking for a trailing `/` separator, consistent with the existing correct implementation in `stash_hooks.rs::file_matches_pathspecs`. **Files changed:** - `src/commands/hooks/reset_hooks.rs` — checkpoint entry filtering during pathspec reset - `src/authorship/rebase_authorship.rs` — file filtering in `reconstruct_working_log_after_reset` - `src/commands/hooks/checkout_hooks.rs` — `matches_any_pathspec` helper - `tests/reset.rs` — new `test_reset_with_directory_pathspec` test Closes #234 ## Review & Testing Checklist for Human - [ ] Verify the matching logic handles edge cases: pathspec `src` should match `src/file.txt` but NOT `srcfile.txt`; pathspec `src/` (trailing slash) should also match `src/file.txt` - [ ] The test only asserts that files **outside** the reset directory retain AI authorship — it does **not** verify that `src/app.rs` actually lost its AI attribution after reset. Consider whether this gap matters. - [ ] The fix in `checkout_hooks.rs` has no dedicated test coverage — verify manually or add a test if concerned - [ ] Note: unlike `stash_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/` and `srclib/`) and confirm only the intended directory is affected. ### Notes - [Link to Devin run](https://app.devin.ai/sessions/5b637e49b5b74c2991b3f8ef17e25a2c) - Requested by: @svarlamov <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/534" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end -->
kerem 2026-03-02 04:13:55 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#545
No description provided.