Skip to content

Fix staged file detection when git diff prefix settings are customized - #591

Open
electrofelix wants to merge 3 commits into
cycodehq:mainfrom
electrofelix:fix-diff-noprefix
Open

electrofelix wants to merge 3 commits into
cycodehq:mainfrom
electrofelix:fix-diff-noprefix

Conversation

@electrofelix

@electrofelix electrofelix commented Nov 12, 2026 •

Copy link
Copy Markdown

What: Pass --src-prefix=a/ and --dst-prefix=b/ on every
create_patch=True diff in commit_range_documents.py, via one shared
GIT_DIFF_PREFIXES constant. Add a parametrized regression test.

Why: GitPython parses patch output assuming the default a/ and b/
path prefixes. If a user's git config sets diff.noprefix=true, or
custom diff.srcPrefix / diff.dstPrefix values, GitPython finds no
file paths in the diff. The pre-commit scan then sees zero staged files
and fails even though files are staged:

Error: The scan could not be completed - relevant files to scan are
not found. Enable verbose mode to see more details.

Reproduce (before this change):

git config --global diff.noprefix true
git add <any file>
cycode scan -t secret pre-commit   # error above

cycode scan -t secret path <file> still works, since it does not use
the staged diff. With diff.noprefix set, nine existing tests in
test_commit_range_documents.py also fail locally; they pass again with
this change.

Tests: test_staged_diff_keeps_paths_with_non_default_diff_prefix_config
runs with diff.noprefix=true and with custom prefixes. Both cases fail
without the fix and pass with it. ruff check and ruff format pass.


Made with Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
@electrofelix

Copy link
Copy Markdown
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 git diff or git log -p outputs.

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.

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.
@omer-roth

Copy link
Copy Markdown
Collaborator

Thank you @electrofelix for taking sharing your time in looking into this.
I'm going to merge it and it will be available in the next version of the CLI

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.

2 participants