Repository navigation
Fix staged file detection when git diff prefix settings are customized - #591
Open
electrofelix wants to merge 3 commits into
Open
electrofelix wants to merge 3 commits into
electrofelix wants to merge 3 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
electrofelix
requested review from
avishaiamiel and
omer-roth
as code owners
November 12, 2026 14:04
Author
|
I'd been running into this for a while and only today uncovered it was because of my preference for an easier copy and paste of any paths emitted from I don't make much use of it, but had it from times before agents were ubiquitous. Still probably good to handle it as otherwise the scan will pass without the files being scanned. |
omer-roth
reviewed
Nov 16, 2026
Address review feedback: replace the GIT_DIFF_PREFIXES constant spread across six call sites with one helper that always passes create_patch=True and the a/ b/ prefixes. Trim the comment to the settings that matter.
Collaborator
|
Thank you @electrofelix for taking sharing your time in looking into this. |
omer-roth
approved these changes
Nov 19, 2026
omer-roth
approved these changes
Nov 19, 2026
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.
What: Pass
--src-prefix=a/and--dst-prefix=b/on everycreate_patch=Truediff incommit_range_documents.py, via one sharedGIT_DIFF_PREFIXESconstant. Add a parametrized regression test.Why: GitPython parses patch output assuming the default
a/andb/path prefixes. If a user's git config sets
diff.noprefix=true, orcustom
diff.srcPrefix/diff.dstPrefixvalues, GitPython finds nofile paths in the diff. The pre-commit scan then sees zero staged files
and fails even though files are staged:
Reproduce (before this change):
cycode scan -t secret path <file>still works, since it does not usethe staged diff. With
diff.noprefixset, nine existing tests intest_commit_range_documents.pyalso fail locally; they pass again withthis change.
Tests:
test_staged_diff_keeps_paths_with_non_default_diff_prefix_configruns with
diff.noprefix=trueand with custom prefixes. Both cases failwithout the fix and pass with it.
ruff checkandruff formatpass.Made with Cursor