---
description: Analyze conflicts before merge (BLOCKING if conflict detected)
agent: efcore-conflicts
model: sonnet
---

# EF Core Conflicts - Cross-Branch Conflict Analysis

Analyzes potential conflicts between current branch and target branch using **SmartStack MCP**.

**USAGE:** Before a merge or commit to ensure there are no migration conflicts.

**BEHAVIOR:** Returns exit code 1 if conflict detected (blocks merge/commit).

**INTEGRATION:** Uses `mcp__smartstack__check_migrations` for structured analysis.

---

## STEP 1: Invoke MCP check_migrations

> **MCP INTEGRATION:** This command delegates conflict analysis to the SmartStack MCP server
> which provides structured, consistent analysis across all SmartStack projects.

```
CALL mcp__smartstack__check_migrations WITH:
  - branch: {current branch}
  - compareBranch: "develop" (or specified target)
```

**Claude instruction:** Use the MCP tool `mcp__smartstack__check_migrations` with parameters:

```json
{
  "branch": "<current_branch>",
  "compareBranch": "develop"
}
```

---

## STEP 2: Parse MCP Response

The MCP returns a structured `MigrationCheckResult`:

```typescript
interface MigrationCheckResult {
  hasConflicts: boolean;
  migrations: MigrationInfo[];
  conflicts: MigrationConflict[];
  suggestions: string[];
}

interface MigrationConflict {
  type: 'order' | 'snapshot' | 'dependency' | 'naming';
  description: string;
  files: string[];
  resolution: string;
}
```

---

## STEP 3: Evaluate Conflict Level

Based on MCP response:

| Conflict Type | Level | Action |
|---------------|-------|--------|
| `naming` | LOW | Warning only |
| `order` | MEDIUM | Warning, suggest reorder |
| `dependency` | HIGH | Block merge |
| `snapshot` | CRITICAL | Block merge, require rebase |

---

## STEP 4: Display Results

**If `hasConflicts: false`:**

```
================================================================================
                    EF CORE CONFLICT ANALYSIS (via MCP)
================================================================================

BRANCH: {current_branch}
TARGET: develop

STATUS: OK - No conflicts detected

Migrations: {count}
ModelSnapshot: Synchronized

================================================================================
```

**If `hasConflicts: true`:**

```
================================================================================
                    EF CORE CONFLICT ANALYSIS (via MCP)
================================================================================

BRANCH: {current_branch}
TARGET: develop

STATUS: CONFLICT DETECTED

CONFLICTS FOUND:
{for each conflict in conflicts}
  [{conflict.type}] {conflict.description}
    Files: {conflict.files.join(', ')}
    Resolution: {conflict.resolution}
{end for}

SUGGESTIONS:
{for each suggestion in suggestions}
  - {suggestion}
{end for}

================================================================================
BLOCKING: Merge not allowed until conflicts are resolved.
================================================================================

RESOLUTION OPTIONS:
  /efcore:rebase-snapshot    Rebase ModelSnapshot on develop (recommended)
  /efcore:conflicts --force  Ignore and proceed (not recommended)

================================================================================
```

---

## STEP 5: Exit Code

```bash
if [ "$HAS_CONFLICTS" = "true" ]; then
  exit 1  # BLOCKING
else
  exit 0  # OK
fi
```

---

## Options

| Option | Description |
|--------|-------------|
| `--force` | Ignore conflict (not recommended) |
| `--target <branch>` | Compare with branch other than develop |
| `--json` | Output raw MCP JSON response |

---

## Exit Codes

| Code | Meaning |
|------|---------|
| 0 | No conflict or minor conflict |
| 1 | Conflict detected - merge blocked |
| 2 | MCP connection error |

---

## MCP Tool Reference

**Tool:** `mcp__smartstack__check_migrations`

**Description:** Analyze EF Core migrations for conflicts, ordering issues, and ModelSnapshot discrepancies between branches

**Parameters:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `projectPath` | string | EF Core project path (default: auto-detect) |
| `branch` | string | Git branch to check (default: current) |
| `compareBranch` | string | Branch to compare against |

---

## Why MCP Integration?

1. **Consistency:** Same analysis logic across CLI, CI/CD, and IDE
2. **Maintainability:** Single source of truth in MCP server
3. **Structured Output:** Typed responses instead of bash text parsing
4. **Extensibility:** Easy to add new conflict types in one place
