Skip to content

Commit 8a07994

Browse files
committed
Fixing --ignore-commit-files to properly work again
1 parent cfdd0e6 commit 8a07994

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.52"
9+
version = "2.2.53"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.52'
2+
__version__ = '2.2.53'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/socketcli.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def main_code():
356356
# Determine files to check based on the new logic
357357
files_to_check = []
358358
force_api_mode = False
359+
force_diff_mode = False
359360

360361
if files_explicitly_specified:
361362
# Case 2: Files are specified - use them and don't check commit details
@@ -365,10 +366,20 @@ def main_code():
365366
# Case 1: Files not specified and --ignore-commit-files not set - try to find changed files from commit
366367
files_to_check = git_repo.changed_files
367368
log.debug(f"Using changed files from commit: {files_to_check}")
369+
elif config.ignore_commit_files and is_repo:
370+
# Case 3: Git repo with --ignore-commit-files - force diff mode
371+
files_to_check = []
372+
force_diff_mode = True
373+
log.debug("Git repo with --ignore-commit-files: forcing diff mode")
368374
else:
369-
# ignore_commit_files is set or not a repo - scan everything but force API mode if no supported files
375+
# Case 4: Not a git repo (ignore_commit_files was auto-set to True)
370376
files_to_check = []
371-
log.debug("No files to check from commit (ignore_commit_files=True or not a repo)")
377+
# If --enable-diff is set, force diff mode for non-git repos
378+
if config.enable_diff:
379+
force_diff_mode = True
380+
log.debug("Non-git repo with --enable-diff: forcing diff mode")
381+
else:
382+
log.debug("Non-git repo without --enable-diff: will use full scan mode")
372383

373384
# Check if we have supported manifest files
374385
has_supported_files = files_to_check and core.has_manifest_files(files_to_check)
@@ -389,22 +400,19 @@ def main_code():
389400
has_supported_files = False
390401

391402
# Case 3: If no supported files or files are empty, force API mode (no PR comments)
392-
if not has_supported_files:
403+
# BUT: Don't force API mode if we're in force_diff_mode
404+
if not has_supported_files and not force_diff_mode:
393405
force_api_mode = True
394406
log.debug("No supported manifest files found, forcing API mode")
395407

396408
# Determine scan behavior
397409
should_skip_scan = False # Always perform scan, but behavior changes based on supported files
398-
if config.ignore_commit_files and not files_explicitly_specified:
399-
# Force full scan when ignoring commit files and no explicit files
400-
should_skip_scan = False
401-
log.debug("Forcing full scan due to ignore_commit_files")
402-
elif not has_supported_files:
403-
# No supported files - still scan but in API mode
410+
if not has_supported_files and not force_diff_mode:
411+
# No supported files and not forcing diff - still scan but in API mode
404412
should_skip_scan = False
405413
log.debug("No supported files but will scan in API mode")
406414
else:
407-
log.debug("Found supported manifest files, proceeding with normal scan")
415+
log.debug("Found supported manifest files or forcing diff mode, proceeding with normal scan")
408416

409417
org_slug = core.config.org_slug
410418
if config.repo_is_public:
@@ -531,14 +539,15 @@ def main_code():
531539

532540
output_handler.handle_output(diff)
533541

534-
elif config.enable_diff and not force_api_mode:
535-
# New logic: --enable-diff forces diff mode even with --integration api (no SCM)
542+
elif (config.enable_diff or force_diff_mode) and not force_api_mode:
543+
# New logic: --enable-diff or force_diff_mode (from --ignore-commit-files in git repos) forces diff mode
536544
log.info("Diff mode enabled without SCM integration")
537545
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths, explicit_files=sbom_files_to_submit)
538546
output_handler.handle_output(diff)
539547

540-
elif config.enable_diff and force_api_mode:
541-
# User requested diff mode but no manifest files were detected
548+
elif (config.enable_diff or force_diff_mode) and force_api_mode:
549+
# User requested diff mode but no manifest files were detected - this should not happen with new logic
550+
# but keeping as a safety net
542551
log.warning("--enable-diff was specified but no supported manifest files were detected in the changed files. Falling back to full scan mode.")
543552
log.info("Creating Socket Report (full scan)")
544553
serializable_params = {

0 commit comments

Comments
 (0)