Skip to content

Commit 093429d

Browse files
omer-rothclaude
andcommitted
CM-70014: update dependencies (Aug 2026)
- marshmallow 3.26.2 -> 4.0.1 (capped <4.1.0; 4.1+ drops Python 3.9) - rich 13.9.4 -> 15.0.0 - gitpython 3.1.50 -> 3.1.57 (floor raised to 3.1.51) - pyinstaller 6.20.0 -> 6.21.0 - poetry.lock refreshed (7-day solver cooldown) GitPython only inverts the `R` flag when diffing the index against HEAD, not against the empty tree, so pre-commit scans of a repository with no commits yet sent staged content as removed lines. Centralize the diff in get_staged_diff_index() so both call sites get a patch oriented with staged content as additions, and assert that orientation in tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e62b533 commit 093429d

5 files changed

Lines changed: 694 additions & 374 deletions

File tree

cycode/cli/apps/scan/commit_range_scanner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
get_diff_file_content,
2828
get_diff_file_path,
2929
get_pre_commit_modified_documents,
30-
get_safe_head_reference_for_diff,
30+
get_staged_diff_index,
3131
parse_commit_range,
3232
)
3333
from cycode.cli.files_collector.documents_walk_ignore import filter_documents_with_cycodeignore
@@ -360,8 +360,7 @@ def _scan_sca_pre_commit(ctx: typer.Context, repo_path: str) -> None:
360360
def _scan_secret_pre_commit(ctx: typer.Context, repo_path: str) -> None:
361361
progress_bar = ctx.obj['progress_bar']
362362
repo = git_proxy.get_repo(repo_path)
363-
head_reference = get_safe_head_reference_for_diff(repo)
364-
diff_index = repo.index.diff(head_reference, create_patch=True, R=True)
363+
_, diff_index = get_staged_diff_index(repo)
365364

366365
progress_bar.set_section_length(ScanProgressBarSection.PREPARE_LOCAL_FILES, len(diff_index))
367366

cycode/cli/files_collector/commit_range_documents.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from cycode.logger import get_logger
1616

1717
if TYPE_CHECKING:
18-
from git import Diff, Repo
18+
from git import Diff, DiffIndex, Repo
1919

2020
from cycode.cli.utils.progress_bar import BaseProgressBar, ProgressBarSection
2121

@@ -47,6 +47,23 @@ def get_safe_head_reference_for_diff(repo: 'Repo') -> str:
4747
return consts.GIT_EMPTY_TREE_OBJECT
4848

4949

50+
def get_staged_diff_index(repo: 'Repo') -> tuple[str, 'DiffIndex']:
51+
"""Diff the index against HEAD, or against the empty tree in repositories with no commits.
52+
53+
GitPython only inverts the `R` flag for HEAD, so `R` must be off for the empty tree to keep
54+
staged content showing up as added lines in both cases.
55+
56+
Args:
57+
repo: Git repository object
58+
59+
Returns:
60+
The reference that was diffed against, and the resulting diff index
61+
"""
62+
head_reference = get_safe_head_reference_for_diff(repo)
63+
reverse = head_reference == consts.GIT_HEAD_COMMIT_REV
64+
return head_reference, repo.index.diff(head_reference, create_patch=True, R=reverse)
65+
66+
5067
def _does_reach_to_max_commits_to_scan_limit(commit_ids: list[str], max_commits_count: Optional[int]) -> bool:
5168
if max_commits_count is None:
5269
return False
@@ -411,8 +428,7 @@ def get_pre_commit_modified_documents(
411428
diff_documents = []
412429

413430
repo = git_proxy.get_repo(repo_path)
414-
head_reference = get_safe_head_reference_for_diff(repo)
415-
diff_index = repo.index.diff(head_reference, create_patch=True, R=True)
431+
head_reference, diff_index = get_staged_diff_index(repo)
416432
progress_bar.set_section_length(progress_bar_section, len(diff_index))
417433
for diff in diff_index:
418434
progress_bar.update(progress_bar_section)

0 commit comments

Comments
 (0)