Skip to content

Fix directory pathspec matching in reset and add test#534

Merged
svarlamov merged 1 commit intomainfrom
devin/1771275017-reset-directory-pathspec
Feb 16, 2026
Merged

Fix directory pathspec matching in reset and add test#534
svarlamov merged 1 commit intomainfrom
devin/1771275017-reset-directory-pathspec

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 16, 2026

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

- 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>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@git-ai-cloud
Copy link

git-ai-cloud bot commented Feb 16, 2026

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

@git-ai-cloud-dev
Copy link

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@svarlamov svarlamov merged commit add0392 into main Feb 16, 2026
15 checks passed
@svarlamov svarlamov deleted the devin/1771275017-reset-directory-pathspec branch February 16, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify reset -- <pathspecs> supports directories

2 participants