Skip to content

Commit 9030718

Browse files
committed
fix: resolve merge commit detection and add production safety features
🔧 Fixed Git Show Bug: - Removed --format=%n from all git show calls (was producing ['', ''] empty arrays) - Added merge-aware fallback: git diff --name-only <parent^1> <commit> for merge commits 🚀 Customer Guidance: - Buildkite users: Keep CI_PIPELINE_SOURCE=merge_request_event override for GitLab-triggered pipelines - Squash merge opt-out: SOCKET_GIT_DISABLE_SQUASH_HEURISTIC=1 available if heuristic detection causes false positives (default: heuristic enabled) ⚠️ Enhanced Warnings: - Octopus merges log a first-parent warning when 3+ parents detected - Clear messaging about limitations: 'Using first-parent diff only - may not show all changes from all branches' 📊 Detection Transparency: - Frozen DETECTION SUMMARY log schema for monitoring integration - Method tracking: mr-diff | merge-diff | single-commit-show - Git command logging for debugging support escalations 🛡️ Production Safety: - Parent commit validation prevents accidental huge diffs - Graceful error handling with clear failure messages - Lazy loading for improved performance ✅ What This Fixes: - Empty file detection on merge commits (['', ''] → actual changed files) - Incorrect API mode fallbacks on merge commits - Missing transparency in file detection logic - No guardrails against dangerous Git operations Real Detection Examples: - Single Commit: DETECTION SUMMARY: method=single-commit-show files=11 sha=095b0ccc cmd="git show --name-only 095b0cc..." - Merge Commit: DETECTION SUMMARY: method=merge-diff files=1 sha=b459b2e3 cmd="git diff --name-only 89ca8e3a..b459b2e3"
1 parent 7af45bc commit 9030718

File tree

3 files changed

+1312
-89
lines changed

3 files changed

+1312
-89
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,84 @@ The CLI determines which files to scan based on the following logic:
285285
- **Using `--enable-diff`**: Forces diff mode without SCM integration - useful when you want differential scanning but are using `--integration api`. For example: `socketcli --integration api --enable-diff --target-path /path/to/repo`
286286
- **Auto-detection**: Most CI/CD scenarios now work with just `socketcli --target-path /path/to/repo --scm github --pr-number $PR_NUM`
287287
288+
## CI/CD Platform Notes
289+
290+
### Buildkite Integration
291+
292+
Buildkite triggers may require special environment variable setup when integrated with GitLab or other source control systems.
293+
294+
#### Event Type Override
295+
296+
If you encounter "Unknown event type trigger" in Buildkite-triggered jobs, you can override the event type:
297+
298+
```bash
299+
# Override Buildkite pipeline event type to merge_request_event
300+
export CI_PIPELINE_SOURCE=merge_request_event
301+
socketcli --target-path $BUILDKITE_BUILD_CHECKOUT_PATH --scm gitlab
302+
```
303+
304+
#### Troubleshooting Missing MR Variables
305+
306+
To verify if GitLab MR environment variables are available in your Buildkite pipeline:
307+
308+
```bash
309+
# Add this debugging snippet to your Buildkite pipeline
310+
echo "=== GitLab MR Environment Variables ==="
311+
echo "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-'NOT SET'}"
312+
echo "CI_MERGE_REQUEST_TARGET_BRANCH_NAME: ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-'NOT SET'}"
313+
echo "CI_MERGE_REQUEST_IID: ${CI_MERGE_REQUEST_IID:-'NOT SET'}"
314+
echo "CI_PIPELINE_SOURCE: ${CI_PIPELINE_SOURCE:-'NOT SET'}"
315+
echo "========================================"
316+
```
317+
318+
If these variables are missing, the CLI will fall back to merge-aware Git diff detection, which may produce partial results for complex merge scenarios.
319+
320+
#### Buildkite-Specific Configuration
321+
322+
For optimal detection in Buildkite environments triggered by GitLab:
323+
324+
```bash
325+
# Example Buildkite pipeline step
326+
steps:
327+
- label: "Socket Security Scan"
328+
command: |
329+
# Override event type if needed
330+
export CI_PIPELINE_SOURCE=merge_request_event
331+
332+
# Run Socket scan with GitLab SCM detection
333+
socketcli \
334+
--target-path $BUILDKITE_BUILD_CHECKOUT_PATH \
335+
--scm gitlab \
336+
--pr-number ${CI_MERGE_REQUEST_IID:-0} \
337+
--enable-debug
338+
```
339+
340+
### Advanced Configuration Options
341+
342+
#### Squash Merge Detection Control
343+
344+
The CLI uses heuristic-based detection for squash merges. To disable this behavior:
345+
346+
```bash
347+
export SOCKET_GIT_DISABLE_SQUASH_HEURISTIC=1
348+
socketcli --target-path ./my-project
349+
```
350+
351+
**When to use this:**
352+
- False positives: Regular commits with merge-like messages are misclassified
353+
- Consistent behavior: You want deterministic single-commit detection only
354+
- Performance: Avoiding heuristic analysis for large repositories
355+
356+
#### Default Branch Detection Matrix
357+
358+
| Scenario | `--default-branch` | `--ignore-commit-files` | Behavior |
359+
|----------|-------------------|------------------------|----------|
360+
| **PR/MR Context** | Not set | Not set | Auto-detects as `false` (PR scans) |
361+
| **Main Branch Push** | Not set | Not set | Auto-detects as `true` (main branch) |
362+
| **Force Default** | `--default-branch` | Not set | Forces `true` regardless of context |
363+
| **Force API Mode** | Not set | `--ignore-commit-files` | Full scan, default branch auto-detected |
364+
| **Override Both** | `--default-branch` | `--ignore-commit-files` | Forces default branch + full scan |
365+
288366
## Debugging and Troubleshooting
289367
290368
### Saving Submitted Files List

0 commit comments

Comments
 (0)