---
description: Phase 2 - Display GitFlow state with versioning and EF Core details
agent: gitflow-status
model: haiku
---

# Phase 2: STATUS - Overview

Tu es expert GitFlow et EF Core. Affiche l'etat complet du projet.

---

## Informations a collecter

### Git
- Branche courante et type (feature/release/hotfix/develop/main)
- Etat working directory (clean/dirty)
- Synchronisation locale vs remote (push/pull needed)
- Synchronisation vs develop et main (commits ahead/behind)
- Dernier tag

### Sync Local vs Remote
```bash
# Fetch pour avoir les infos a jour (sans modifier le working directory)
git fetch --quiet 2>/dev/null

# Verifier si la branche a un remote tracking
UPSTREAM=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null)

if [ -n "$UPSTREAM" ]; then
  # Comparer local vs remote
  LOCAL=$(git rev-parse @)
  REMOTE=$(git rev-parse @{upstream})
  BASE=$(git merge-base @ @{upstream})

  if [ "$LOCAL" = "$REMOTE" ]; then
    SYNC_STATUS="UP-TO-DATE"
  elif [ "$LOCAL" = "$BASE" ]; then
    BEHIND=$(git rev-list --count @..@{upstream})
    SYNC_STATUS="BEHIND $BEHIND (pull needed)"
  elif [ "$REMOTE" = "$BASE" ]; then
    AHEAD=$(git rev-list --count @{upstream}..@)
    SYNC_STATUS="AHEAD $AHEAD (push needed)"
  else
    AHEAD=$(git rev-list --count @{upstream}..@)
    BEHIND=$(git rev-list --count @..@{upstream})
    SYNC_STATUS="DIVERGED +$AHEAD/-$BEHIND (pull --rebase needed)"
  fi
else
  SYNC_STATUS="NO REMOTE (not pushed yet)"
fi
```

### Sync develop vs main (CRITIQUE)

```bash
# Commits sur develop absents de main (normal - a releaser)
DEVELOP_AHEAD=$(git rev-list --count origin/main..origin/develop 2>/dev/null || echo "0")

# Commits sur main absents de develop (ANORMAL - hotfix non merge back?)
MAIN_AHEAD=$(git rev-list --count origin/develop..origin/main 2>/dev/null || echo "0")

# Determiner l'etat de synchronisation
if [ "$DEVELOP_AHEAD" -eq 0 ] && [ "$MAIN_AHEAD" -eq 0 ]; then
  BASE_SYNC="SYNCHRONIZED"
elif [ "$MAIN_AHEAD" -gt 0 ]; then
  BASE_SYNC="DIVERGED"  # PROBLEME!
elif [ "$DEVELOP_AHEAD" -gt 0 ]; then
  BASE_SYNC="RELEASE_NEEDED"  # Normal
fi
```

**Si MAIN_AHEAD > 0 (main a des commits absents de develop):**
```bash
# Lister les commits divergents
git log origin/develop..origin/main --oneline
```

### Version
Read from configured source in [.claude/gitflow/config.json](.claude/gitflow/config.json):
- `versioning.source` → type (csproj, Directory.Build.props, AssemblyInfo, VERSION, git-tag, package.json)
- `versioning.sourceFile` → file path
- Read current version from THAT file (not from config.json)

Fallback si pas de config:
```bash
# package.json
VERSION=$(grep '"version"' package.json 2>/dev/null | head -1 | sed 's/.*: "\(.*\)".*/\1/')
# .csproj
[ -z "$VERSION" ] && VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' *.csproj 2>/dev/null | head -1)
# VERSION file
[ -z "$VERSION" ] && VERSION=$(cat VERSION 2>/dev/null)
# Git tag
[ -z "$VERSION" ] && VERSION=$(git describe --tags --abbrev=0 2>/dev/null)
```

### EF Core
- Lister les migrations (total et pending)
- Lister les DbContext detectes

### EF Core - Vue globale (toutes branches)
Si `--all-branches` ou si plusieurs branches GitFlow actives:
```bash
# Scanner les branches actives
FEATURES=$(git branch -r | grep 'feature/' | wc -l)
RELEASES=$(git branch -r | grep 'release/' | wc -l)
HOTFIXES=$(git branch -r | grep 'hotfix/' | wc -l)

# Pour chaque branche, detecter migrations ajoutees
for BRANCH in $(git branch -r | grep -E 'feature/|release/|hotfix/'); do
  MIGRATIONS=$(git diff origin/develop..$BRANCH --name-only | grep -E "Migrations/.*\.cs$" | grep -v Designer | grep -v ModelSnapshot)
  CONFLICT=$(git diff origin/develop..$BRANCH --name-only | grep "ModelSnapshot" | wc -l)
done
```

### Plans GitFlow
- Plans actifs (non termines)
- Plans termines recemment (7 jours)

### Operations en cours
- Rebase, merge, cherry-pick en cours?
- Conflits detectes?

### Risques
- **Divergence main/develop** (main a des commits absents de develop)
- Divergence > 5 commits vs develop
- Migrations non commitees
- ModelSnapshot modifie non commite

---

## Affichage

```
================================================================================
                           GITFLOW STATUS
================================================================================

BRANCHE: {branch} ({type}) | {clean|dirty}
VERSION: {version} ({source})

REMOTE SYNC
  vs origin/{branch}: {UP-TO-DATE|AHEAD N|BEHIND N|DIVERGED|NO REMOTE}

--------------------------------------------------------------------------------
SYNC DEVELOP <-> MAIN
--------------------------------------------------------------------------------
  develop → main: +{DEVELOP_AHEAD} commits     {message}
  main → develop: +{MAIN_AHEAD} commits        {message}

  {Si DEVELOP_AHEAD > 0 et MAIN_AHEAD == 0:}
  ✓ Normal: develop a {N} commits prets a releaser
  → Action: /gitflow:10-start release

  {Si MAIN_AHEAD > 0:}
  ⚠️ ATTENTION: main contient {N} commits absents de develop!

  Commits sur main non merges dans develop:
  {git log origin/develop..origin/main --oneline}

  Causes possibles:
  - Hotfix non merge back dans develop
  - Commit direct sur main (non recommande)
  - Release mal finalisee

  → Actions:
    1. Merger main dans develop: git merge origin/main
    2. Ou via release: /gitflow:10-start release (reset main)

  {Si DEVELOP_AHEAD == 0 et MAIN_AHEAD == 0:}
  ✓ Synchronise: develop et main sont identiques
--------------------------------------------------------------------------------

DERNIER TAG: {tag}

EF CORE (branche courante)
  Migrations: {total} total, {pending} pending
  [Pending] {liste}

--------------------------------------------------------------------------------
BRANCHES ACTIVES ({features} features, {releases} releases, {hotfixes} hotfixes)
--------------------------------------------------------------------------------
{Si branches actives avec migrations:}
  feature/add-users        +1 migration  (AddUsersTable)      Conflit: NON
  feature/add-orders       +1 migration  (AddOrdersTable)     Conflit: NON
  feature/add-products     +2 migrations (AddProducts, AddFK) Conflit: OUI

  ORDRE DE MERGE RECOMMANDE:
  1. feature/add-users (independant)
  2. feature/add-orders (independant)
  3. feature/add-products (conflit ModelSnapshot - rebase requis)
--------------------------------------------------------------------------------

PLANS: {n} active | OPERATIONS: {none|rebase|merge} | RISKS: {liste}

================================================================================
Actions: /gitflow:13-sync | /gitflow:14-rebase | /gitflow:3-commit | /gitflow:4-plan
================================================================================
```

---

## Alertes Specifiques

### Alerte: main divergent de develop

```
╔══════════════════════════════════════════════════════════════════════════════╗
║  ⚠️  DIVERGENCE DETECTEE: main contient des commits absents de develop       ║
╠══════════════════════════════════════════════════════════════════════════════╣
║                                                                              ║
║  Commits sur main non presents sur develop ({N}):                            ║
║  {hash1} {message1}                                                          ║
║  {hash2} {message2}                                                          ║
║  ...                                                                         ║
║                                                                              ║
╠══════════════════════════════════════════════════════════════════════════════╣
║  RESOLUTIONS:                                                                ║
║                                                                              ║
║  Option 1 - Merger main dans develop (recommande):                           ║
║    git checkout develop && git merge origin/main                             ║
║                                                                              ║
║  Option 2 - Via la prochaine release:                                        ║
║    /gitflow:10-start release                                                 ║
║    (La release peut reset main si necessaire)                                ║
║                                                                              ║
║  Option 3 - Cherry-pick selectif:                                            ║
║    git cherry-pick {hash}                                                    ║
║                                                                              ║
╚══════════════════════════════════════════════════════════════════════════════╝
```

### Alerte: Release recommandee

```
┌──────────────────────────────────────────────────────────────────────────────┐
│  ℹ️  RELEASE RECOMMANDEE                                                      │
├──────────────────────────────────────────────────────────────────────────────┤
│  develop a {N} commits en avance de main.                                    │
│  → /gitflow:10-start release                                                 │
└──────────────────────────────────────────────────────────────────────────────┘
```

---

## Modes

| Mode | Output |
|------|--------|
| Normal | Affichage complet |
| `--short` | `[branch] status \| vX.Y.Z \| dev→main:+X \| main→dev:+Y` |
| `--json` | JSON structure |

## Codes sortie

| Code | Signification |
|------|---------------|
| 0 | OK (synchronise ou release needed) |
| 1 | Warnings (pending, release recommandee) |
| 2 | Problemes (divergence main/develop, conflits, operation en cours) |
| 3 | Erreur (pas repo, no config) |

## Actions suggerees

| Etat | Commande Claude Code |
|------|----------------------|
| AHEAD N (push needed) | `/gitflow:13-sync` |
| BEHIND N (pull needed) | `/gitflow:13-sync` |
| DIVERGED local/remote | `/gitflow:13-sync` |
| NO REMOTE (not pushed yet) | `/gitflow:13-sync` |
| **main ahead of develop** | `git merge origin/main` ou `/gitflow:10-start release` |
| develop ahead of main | `/gitflow:10-start release` |
| Divergence > 5 vs develop | `/gitflow:14-rebase` |
| Pending migrations | `/efcore:db-deploy` |
| Dirty workdir | `/gitflow:3-commit` |
| Operation en cours | `/gitflow:6-abort` |
| No config | `/gitflow:1-init` |
