cycode 3.4.1.dev5__py3-none-any.whl → 3.4.2.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cycode/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '3.4.1.dev5' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
1
+ __version__ = '3.4.2.dev1' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
@@ -25,6 +25,7 @@ from cycode.cli.files_collector.commit_range_documents import (
25
25
  get_diff_file_content,
26
26
  get_diff_file_path,
27
27
  get_pre_commit_modified_documents,
28
+ get_safe_head_reference_for_diff,
28
29
  parse_commit_range_sast,
29
30
  parse_commit_range_sca,
30
31
  )
@@ -271,7 +272,9 @@ def _scan_sca_pre_commit(ctx: typer.Context, repo_path: str) -> None:
271
272
 
272
273
  def _scan_secret_pre_commit(ctx: typer.Context, repo_path: str) -> None:
273
274
  progress_bar = ctx.obj['progress_bar']
274
- diff_index = git_proxy.get_repo(repo_path).index.diff(consts.GIT_HEAD_COMMIT_REV, create_patch=True, R=True)
275
+ repo = git_proxy.get_repo(repo_path)
276
+ head_reference = get_safe_head_reference_for_diff(repo)
277
+ diff_index = repo.index.diff(head_reference, create_patch=True, R=True)
275
278
 
276
279
  progress_bar.set_section_length(ScanProgressBarSection.PREPARE_LOCAL_FILES, len(diff_index))
277
280
 
@@ -279,7 +282,11 @@ def _scan_secret_pre_commit(ctx: typer.Context, repo_path: str) -> None:
279
282
  for diff in diff_index:
280
283
  progress_bar.update(ScanProgressBarSection.PREPARE_LOCAL_FILES)
281
284
  documents_to_scan.append(
282
- Document(get_path_by_os(get_diff_file_path(diff)), get_diff_file_content(diff), is_git_diff_format=True)
285
+ Document(
286
+ get_path_by_os(get_diff_file_path(diff, repo=repo)),
287
+ get_diff_file_content(diff),
288
+ is_git_diff_format=True,
289
+ )
283
290
  )
284
291
  documents_to_scan = excluder.exclude_irrelevant_documents_to_scan(consts.SECRET_SCAN_TYPE, documents_to_scan)
285
292
 
cycode/cli/consts.py CHANGED
@@ -261,6 +261,7 @@ SCAN_STATUS_ERROR = 'Error'
261
261
  # git consts
262
262
  COMMIT_DIFF_DELETED_FILE_CHANGE_TYPE = 'D'
263
263
  GIT_HEAD_COMMIT_REV = 'HEAD'
264
+ GIT_EMPTY_TREE_OBJECT = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
264
265
  EMPTY_COMMIT_SHA = '0000000000000000000000000000000000000000'
265
266
  GIT_PUSH_OPTION_COUNT_ENV_VAR_NAME = 'GIT_PUSH_OPTION_COUNT'
266
267
  GIT_PUSH_OPTION_ENV_VAR_PREFIX = 'GIT_PUSH_OPTION_'
@@ -22,6 +22,31 @@ if TYPE_CHECKING:
22
22
  logger = get_logger('Commit Range Collector')
23
23
 
24
24
 
25
+ def get_safe_head_reference_for_diff(repo: 'Repo') -> str:
26
+ """Get a safe reference to use for diffing against the current HEAD.
27
+ In repositories with no commits, HEAD doesn't exist, so we return the empty tree hash.
28
+
29
+ Args:
30
+ repo: Git repository object
31
+
32
+ Returns:
33
+ Either "HEAD" string if commits exist, or empty tree hash if no commits exist
34
+ """
35
+ try:
36
+ repo.rev_parse(consts.GIT_HEAD_COMMIT_REV)
37
+ return consts.GIT_HEAD_COMMIT_REV
38
+ except Exception as e: # actually gitdb.exc.BadObject; no import because of lazy loading
39
+ logger.debug(
40
+ 'Repository has no commits, using empty tree hash for diffs, %s',
41
+ {'repo_path': repo.working_tree_dir},
42
+ exc_info=e,
43
+ )
44
+
45
+ # Repository has no commits, use the universal empty tree hash
46
+ # This is the standard Git approach for initial commits
47
+ return consts.GIT_EMPTY_TREE_OBJECT
48
+
49
+
25
50
  def _does_reach_to_max_commits_to_scan_limit(commit_ids: list[str], max_commits_count: Optional[int]) -> bool:
26
51
  if max_commits_count is None:
27
52
  return False
@@ -62,7 +87,7 @@ def collect_commit_range_diff_documents(
62
87
  for diff in diff_index:
63
88
  commit_documents_to_scan.append(
64
89
  Document(
65
- path=get_path_by_os(get_diff_file_path(diff)),
90
+ path=get_path_by_os(get_diff_file_path(diff, repo=repo)),
66
91
  content=get_diff_file_content(diff),
67
92
  is_git_diff_format=True,
68
93
  unique_id=commit_id,
@@ -141,7 +166,7 @@ def get_commit_range_modified_documents(
141
166
  for diff in modified_files_diff:
142
167
  progress_bar.update(progress_bar_section)
143
168
 
144
- file_path = get_path_by_os(get_diff_file_path(diff))
169
+ file_path = get_path_by_os(get_diff_file_path(diff, repo=repo))
145
170
 
146
171
  diff_documents.append(
147
172
  Document(
@@ -186,16 +211,24 @@ def parse_pre_receive_input() -> str:
186
211
  return pre_receive_input.splitlines()[0]
187
212
 
188
213
 
189
- def get_diff_file_path(diff: 'Diff', relative: bool = False) -> Optional[str]:
214
+ def get_diff_file_path(diff: 'Diff', relative: bool = False, repo: Optional['Repo'] = None) -> Optional[str]:
190
215
  if relative:
191
216
  # relative to the repository root
192
217
  return diff.b_path if diff.b_path else diff.a_path
193
218
 
219
+ # Try blob-based paths first (most reliable when available)
194
220
  if diff.b_blob:
195
221
  return diff.b_blob.abspath
196
222
  if diff.a_blob:
197
223
  return diff.a_blob.abspath
198
224
 
225
+ # Fallback: construct an absolute path from a relative path
226
+ # This handles renames and other cases where blobs might be None
227
+ if repo and repo.working_tree_dir:
228
+ target_path = diff.b_path if diff.b_path else diff.a_path
229
+ if target_path:
230
+ return os.path.abspath(os.path.join(repo.working_tree_dir, target_path))
231
+
199
232
  return None
200
233
 
201
234
 
@@ -213,12 +246,13 @@ def get_pre_commit_modified_documents(
213
246
  diff_documents = []
214
247
 
215
248
  repo = git_proxy.get_repo(repo_path)
216
- diff_index = repo.index.diff(consts.GIT_HEAD_COMMIT_REV, create_patch=True, R=True)
249
+ head_reference = get_safe_head_reference_for_diff(repo)
250
+ diff_index = repo.index.diff(head_reference, create_patch=True, R=True)
217
251
  progress_bar.set_section_length(progress_bar_section, len(diff_index))
218
252
  for diff in diff_index:
219
253
  progress_bar.update(progress_bar_section)
220
254
 
221
- file_path = get_path_by_os(get_diff_file_path(diff))
255
+ file_path = get_path_by_os(get_diff_file_path(diff, repo=repo))
222
256
 
223
257
  diff_documents.append(
224
258
  Document(
@@ -228,9 +262,11 @@ def get_pre_commit_modified_documents(
228
262
  )
229
263
  )
230
264
 
231
- file_content = _get_file_content_from_commit_diff(repo, consts.GIT_HEAD_COMMIT_REV, diff)
232
- if file_content:
233
- git_head_documents.append(Document(file_path, file_content))
265
+ # Only get file content from HEAD if HEAD exists (not the empty tree hash)
266
+ if head_reference == consts.GIT_HEAD_COMMIT_REV:
267
+ file_content = _get_file_content_from_commit_diff(repo, head_reference, diff)
268
+ if file_content:
269
+ git_head_documents.append(Document(file_path, file_content))
234
270
 
235
271
  if os.path.exists(file_path):
236
272
  file_content = get_file_content(file_path)
@@ -274,13 +310,13 @@ def parse_commit_range_sast(commit_range: str, path: str) -> tuple[Optional[str]
274
310
  else:
275
311
  # Git commands like 'git diff <commit>' compare against HEAD.
276
312
  from_spec = commit_range
277
- to_spec = 'HEAD'
313
+ to_spec = consts.GIT_HEAD_COMMIT_REV
278
314
 
279
315
  # If a spec is empty (e.g., from '..master'), default it to 'HEAD'
280
316
  if not from_spec:
281
- from_spec = 'HEAD'
317
+ from_spec = consts.GIT_HEAD_COMMIT_REV
282
318
  if not to_spec:
283
- to_spec = 'HEAD'
319
+ to_spec = consts.GIT_HEAD_COMMIT_REV
284
320
 
285
321
  try:
286
322
  # Use rev_parse to resolve each specifier to its full commit SHA
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cycode
3
- Version: 3.4.1.dev5
3
+ Version: 3.4.2.dev1
4
4
  Summary: Boost security in your dev lifecycle via SAST, SCA, Secrets & IaC scanning.
5
5
  Home-page: https://github.com/cycodehq/cycode-cli
6
6
  License: MIT
@@ -277,7 +277,7 @@ Perform the following steps to install the pre-commit hook:
277
277
  ```yaml
278
278
  repos:
279
279
  - repo: https://github.com/cycodehq/cycode-cli
280
- rev: v3.2.0
280
+ rev: v3.4.2
281
281
  hooks:
282
282
  - id: cycode
283
283
  stages:
@@ -289,7 +289,7 @@ Perform the following steps to install the pre-commit hook:
289
289
  ```yaml
290
290
  repos:
291
291
  - repo: https://github.com/cycodehq/cycode-cli
292
- rev: v3.2.0
292
+ rev: v3.4.2
293
293
  hooks:
294
294
  - id: cycode
295
295
  stages:
@@ -1,4 +1,4 @@
1
- cycode/__init__.py,sha256=_c9Sjr97k_fFNuaLGC3n7v1N5S9LdTI70Kr7aM8weLo,114
1
+ cycode/__init__.py,sha256=tyk-cmPAYJh__0HAgSy_VEBt6aZM1W1sW8kKzQPjso0,114
2
2
  cycode/__main__.py,sha256=Z3bD5yrA7yPvAChcADQrqCaZd0ChGI1gdiwALwbWJ6U,104
3
3
  cycode/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  cycode/cli/app.py,sha256=UC5A5TKIvlxOYKERfJykN8apTT0VyMY5pUjRh_LM-dw,6098
@@ -36,7 +36,7 @@ cycode/cli/apps/scan/aggregation_report.py,sha256=8f9kPfO7biNf5OsDZG6UhMPqG6ymoF
36
36
  cycode/cli/apps/scan/code_scanner.py,sha256=lWAcdtdeOmLe9zaXnItlbL-WIgnJ6d4iUeYiprxUJ34,11205
37
37
  cycode/cli/apps/scan/commit_history/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  cycode/cli/apps/scan/commit_history/commit_history_command.py,sha256=Yp_17vfjDqytjCqjXQ73HaDGH5_ertoLhoV7Cvt1Hhw,1104
39
- cycode/cli/apps/scan/commit_range_scanner.py,sha256=CbiwmLVMYZlQN89_aZcOuI3kqisoycHtugrei6PIkNg,12763
39
+ cycode/cli/apps/scan/commit_range_scanner.py,sha256=EMNadSkuetnEFlJHvnaXZJfZlSewK3tLjPu21JWS6g4,12939
40
40
  cycode/cli/apps/scan/detection_excluder.py,sha256=0zaNa1PxVshATHv8axp4e-xWvmuNQdg_r5DYsdQ9EVo,6432
41
41
  cycode/cli/apps/scan/path/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  cycode/cli/apps/scan/path/path_command.py,sha256=7M8nnohjB4SaNA7jv3mFODyX1wwwSmROe45e7E5GLbY,670
@@ -61,7 +61,7 @@ cycode/cli/apps/status/version_command.py,sha256=c6Iko_rmZo9T_kQSd3HUloBi40Qv7cj
61
61
  cycode/cli/cli_types.py,sha256=cI9_XPG9LDofh6e2qyPtegD76KZYzcPwLj8jFK3Kmp4,2790
62
62
  cycode/cli/config.py,sha256=EblYUlUA4lTp_lrL3gMG-cW7FUOTE1jtGIOljcLnEzk,250
63
63
  cycode/cli/console.py,sha256=vp-DHwlkwpwdsPyfwGdjsPF-6-Bi3f8W7G-W_YXCMH8,1914
64
- cycode/cli/consts.py,sha256=xowssaJU81d8v4jg0W29oD33BdqzIOi5GY_9LQZU-vI,8406
64
+ cycode/cli/consts.py,sha256=9K4uGu0n-SpTP1fMv0xzZGJD2cN301jEgzGG0LYQ5c8,8473
65
65
  cycode/cli/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
66
  cycode/cli/exceptions/custom_exceptions.py,sha256=Uh4Lqp4moTIFRTRtnT5b8dqb07L3wSAnAuFonS6-omQ,3610
67
67
  cycode/cli/exceptions/handle_ai_remediation_errors.py,sha256=mA70upSYXK3rL_fmanzKYeUzLENhpXdkW8k3aIHrKzU,785
@@ -70,7 +70,7 @@ cycode/cli/exceptions/handle_errors.py,sha256=9ZiDbHswXLe0TscUqZL9Or5Jq2AlYtzGb6
70
70
  cycode/cli/exceptions/handle_report_sbom_errors.py,sha256=bi0EizHtQLL-ovhHRH98CZ7qXdDPLTYnI59Jn1Y5c0E,926
71
71
  cycode/cli/exceptions/handle_scan_errors.py,sha256=-QIYvbBXmZVOvAdNwGYwAdmBma6Z_pPpS0a77aDICp8,1916
72
72
  cycode/cli/files_collector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
- cycode/cli/files_collector/commit_range_documents.py,sha256=bMp6SmeIC2sQKIoGCE6bWN8yabGVq8KpeDCvNRA_3Ng,10780
73
+ cycode/cli/files_collector/commit_range_documents.py,sha256=rEdvXzO_wue3Tpt0-E-o_GqN12yRGxZvJ0tRmEmQX7U,12444
74
74
  cycode/cli/files_collector/file_excluder.py,sha256=FhBnYF889BOwx3fRjNyBaFix6-65jCejglf8MmiVxSk,7300
75
75
  cycode/cli/files_collector/iac/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  cycode/cli/files_collector/iac/tf_content_generator.py,sha256=a65zA0Ejv_LSA5jac2omHck4IKoNS5MX6v6ltF2wo4E,2873
@@ -157,8 +157,8 @@ cycode/cyclient/report_client.py,sha256=h12pz3vWCwDF73BhqFX7iDSxBgQDFwkiGh3hmul2
157
157
  cycode/cyclient/scan_client.py,sha256=nQJyt34Bne8UAQNj9OHSgvoCfI1EJFKNaEeeGPnrKcg,12471
158
158
  cycode/cyclient/scan_config_base.py,sha256=mXsPZGYCtp85rv5GIige40yQZXuRcEKUW-VQJ0vgFzk,1201
159
159
  cycode/logger.py,sha256=xAzpkWLZhixO4egRcYn4HXM9lIfx5wHdpkHxNc5jrX8,2225
160
- cycode-3.4.1.dev5.dist-info/LICENCE,sha256=2Wx4N6mD_4xB7-E3hPkZ3MPhpJy__k_I8MaCSO-PDRo,1068
161
- cycode-3.4.1.dev5.dist-info/METADATA,sha256=w4U5F4VDSUUka1Q71j3i1ZlrSMf_w_-11ETdT3-DDMc,71912
162
- cycode-3.4.1.dev5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
163
- cycode-3.4.1.dev5.dist-info/entry_points.txt,sha256=iDcVJM8ByLElVgvBgtYxDjw1kT7O8Mo0LcWZIT5L3Ig,45
164
- cycode-3.4.1.dev5.dist-info/RECORD,,
160
+ cycode-3.4.2.dev1.dist-info/LICENCE,sha256=2Wx4N6mD_4xB7-E3hPkZ3MPhpJy__k_I8MaCSO-PDRo,1068
161
+ cycode-3.4.2.dev1.dist-info/METADATA,sha256=ebfwDPm_9tpFqZEBq3-HebH9uJLqo_l4A_MUYNW13K4,71912
162
+ cycode-3.4.2.dev1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
163
+ cycode-3.4.2.dev1.dist-info/entry_points.txt,sha256=iDcVJM8ByLElVgvBgtYxDjw1kT7O8Mo0LcWZIT5L3Ig,45
164
+ cycode-3.4.2.dev1.dist-info/RECORD,,