---
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

### 1. BRANCHES - Vue complete

#### Toutes les branches (locales et remote)
```bash
# Fetch pour avoir les infos a jour
git fetch --all --quiet 2>/dev/null

# Branches locales avec dernier commit
echo "=== BRANCHES LOCALES ==="
git for-each-ref --sort=-committerdate --format='%(refname:short)|%(objectname:short)|%(committerdate:short)|%(subject)' refs/heads

# Branches remote avec dernier commit
echo "=== BRANCHES REMOTE ==="
git for-each-ref --sort=-committerdate --format='%(refname:short)|%(objectname:short)|%(committerdate:short)|%(subject)' refs/remotes/origin

# Worktrees actifs
echo "=== WORKTREES ==="
git worktree list

# Tracking relationships
echo "=== TRACKING ==="
git branch -vv
```

### 2. TAGS - Tous les tags avec details
```bash
# Tous les tags tries par version (newest first)
echo "=== TAGS ==="
git for-each-ref --sort=-v:refname --format='%(refname:short)|%(creatordate:short)|%(subject)' refs/tags

# Dernier tag sur chaque branche principale
echo "=== LATEST TAG PER BRANCH ==="
for branch in main develop; do
  if git rev-parse --verify $branch >/dev/null 2>&1; then
    TAG=$(git describe --tags --abbrev=0 $branch 2>/dev/null || echo "none")
    AHEAD=$(git rev-list --count $TAG..$branch 2>/dev/null || echo "0")
    echo "$branch: $TAG (+$AHEAD commits)"
  fi
done

# Quelles branches contiennent quels tags (3 derniers tags)
echo "=== TAG CONTAINMENT ==="
for tag in $(git tag -l --sort=-v:refname | head -3); do
  BRANCHES=$(git branch -a --contains $tag 2>/dev/null | tr '\n' ',' | sed 's/,$//')
  echo "$tag: $BRANCHES"
done
```

### 3. Git Status courant
- 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)

### 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
```

### 4. COMPARAISONS - develop vs main vs releases (CRITIQUE)

```bash
# === DEVELOP vs MAIN ===
echo "=== DEVELOP vs MAIN ==="

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

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

echo "develop → main: +$DEVELOP_AHEAD commits"
echo "main → develop: +$MAIN_AHEAD commits"

# Determiner l'etat de synchronisation
if [ "$DEVELOP_AHEAD" -eq 0 ] && [ "$MAIN_AHEAD" -eq 0 ]; then
  echo "STATUS: SYNCHRONIZED ✓"
elif [ "$MAIN_AHEAD" -gt 0 ]; then
  echo "STATUS: DIVERGED ⚠️ (main a des commits non merges dans develop)"
elif [ "$DEVELOP_AHEAD" -gt 0 ]; then
  echo "STATUS: RELEASE_NEEDED (normal)"
fi

# === RELEASES EN COURS ===
echo ""
echo "=== RELEASES EN COURS ==="

# Pour chaque branche release (locale et remote)
for RELEASE in $(git branch -a | grep -E 'release/' | sed 's/.*release\//release\//' | sort -u); do
  BRANCH_NAME=$(echo $RELEASE | sed 's/remotes\/origin\///')

  # Verifier si la branche existe
  if git rev-parse --verify $BRANCH_NAME >/dev/null 2>&1; then
    REL_VS_DEV_AHEAD=$(git rev-list --count develop..$BRANCH_NAME 2>/dev/null || echo "0")
    REL_VS_DEV_BEHIND=$(git rev-list --count $BRANCH_NAME..develop 2>/dev/null || echo "0")
    REL_VS_MAIN_AHEAD=$(git rev-list --count main..$BRANCH_NAME 2>/dev/null || echo "0")
    REL_VS_MAIN_BEHIND=$(git rev-list --count $BRANCH_NAME..main 2>/dev/null || echo "0")
    LAST_COMMIT=$(git log -1 --format='%h %s' $BRANCH_NAME 2>/dev/null)

    echo ""
    echo "$BRANCH_NAME:"
    echo "  vs develop: +$REL_VS_DEV_AHEAD/-$REL_VS_DEV_BEHIND"
    echo "  vs main:    +$REL_VS_MAIN_AHEAD/-$REL_VS_MAIN_BEHIND"
    echo "  last:       $LAST_COMMIT"

    # Status
    if [ "$REL_VS_DEV_AHEAD" -eq 0 ] && [ "$REL_VS_MAIN_AHEAD" -eq 0 ]; then
      echo "  status:     MERGED ✓ (peut etre supprimee)"
    elif [ "$REL_VS_DEV_AHEAD" -gt 0 ] || [ "$REL_VS_MAIN_AHEAD" -gt 0 ]; then
      echo "  status:     ACTIVE (commits non merges)"
    fi
  fi
done

# === FEATURES EN COURS ===
echo ""
echo "=== FEATURES EN COURS ==="

for FEATURE in $(git branch -a | grep -E 'feature/' | sed 's/.*feature\//feature\//' | sort -u | head -10); do
  BRANCH_NAME=$(echo $FEATURE | sed 's/remotes\/origin\///')

  if git rev-parse --verify $BRANCH_NAME >/dev/null 2>&1; then
    FEAT_VS_DEV_AHEAD=$(git rev-list --count develop..$BRANCH_NAME 2>/dev/null || echo "0")
    FEAT_VS_DEV_BEHIND=$(git rev-list --count $BRANCH_NAME..develop 2>/dev/null || echo "0")
    LAST_COMMIT=$(git log -1 --format='%h %s' $BRANCH_NAME 2>/dev/null)

    echo "$BRANCH_NAME: +$FEAT_VS_DEV_AHEAD/-$FEAT_VS_DEV_BEHIND | $LAST_COMMIT"
  fi
done
```

**Si MAIN_AHEAD > 0 (main a des commits absents de develop):**
```bash
echo "=== COMMITS MANQUANTS DANS DEVELOP ==="
git log develop..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:  {UP-TO-DATE|AHEAD N|BEHIND N|DIVERGED|NO REMOTE}

┌──────────────────────────────────────────────────────────────────────────────┐
│ BRANCHES                                                                     │
├──────────────────────────────────────────────────────────────────────────────┤
│ LOCALES ({n})                                                                │
│ ──────────────────────────────────────────────────────────────────────────── │
│ Branch              │ Commit  │ Date       │ Message                         │
│ ─────────────────────────────────────────────────────────────────────────────│
│ * develop           │ 8e8069d │ 2026-01-17 │ fix(ci): use NPM_TOKEN...      │
│   main              │ dd0cb2a │ 2026-01-17 │ chore(ci): update pipeline...  │
│   release/v1.5.1    │ 10d2c58 │ 2026-01-17 │ chore: bump version to 1.5.1   │
│                                                                              │
│ REMOTE origin ({n})                                                          │
│ ──────────────────────────────────────────────────────────────────────────── │
│   origin/develop    │ 8e8069d │ 2026-01-17 │ fix(ci): use NPM_TOKEN...      │
│   origin/main       │ 91d0986 │ 2026-01-16 │ feat(license): add license...  │
│                                                                              │
│ WORKTREES ({n})                                                              │
│ ──────────────────────────────────────────────────────────────────────────── │
│   01-Main           │ main           │ dd0cb2a                               │
│   02-Develop        │ develop        │ 8e8069d (current)                     │
│   releases/v1.4.2   │ release/v1.4.2 │ a45f239                               │
└──────────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────────┐
│ TAGS ({n} total)                                                             │
├──────────────────────────────────────────────────────────────────────────────┤
│ Tag     │ Date       │ Message                          │ Branches           │
│ ─────────────────────────────────────────────────────────────────────────────│
│ v1.5.2  │ 2026-01-17 │ Release v1.5.2 - Azure DevOps... │ main               │
│ v1.5.1  │ 2026-01-17 │ Release v1.5.1 - Fix init...     │ main               │
│ v1.5.0  │ 2026-01-17 │ Release v1.5.0 - Project scaf... │ develop, main      │
│ v1.4.1  │ 2026-01-17 │ Release v1.4.1 - Patch release   │ develop, main      │
│ v1.4.0  │ 2026-01-16 │ Release v1.4.0                   │ develop, main      │
│                                                                              │
│ DERNIERE VERSION PAR BRANCHE                                                 │
│   main:    v1.5.2 (+2 commits depuis ce tag)                                 │
│   develop: v1.5.0 (+10 commits depuis ce tag)                                │
│                                                                              │
│   Legende: "+N commits" = nombre de changements faits apres ce tag           │
└──────────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────────┐
│ COMPARAISONS ENTRE BRANCHES                                                  │
├──────────────────────────────────────────────────────────────────────────────┤
│ DEVELOP vs MAIN (Production)                                                 │
│ ──────────────────────────────────────────────────────────────────────────── │
│                                                                              │
│   develop: {N} commits prets a publier en production                         │
│            (changements sur develop non encore sur main)                     │
│                                                                              │
│   main:    {N} commits a recuperer dans develop                              │
│            (changements sur main non encore sur develop)                     │
│                                                                              │
│   ETAT: {message selon situation}                                            │
│   ✓ SYNCHRONISE   = develop et main sont identiques                          │
│   ℹ️ A PUBLIER     = develop a des changements prets pour une release        │
│   ⚠️ DESYNCHRONISE = main a des commits non recuperes (action requise)       │
│                                                                              │
│ {Si main a des commits non recuperes:}                                       │
│   ⚠️ ATTENTION: {N} changements sur main non recuperes dans develop!         │
│   ─────────────────────────────────────────────────────────────────────────  │
│   Ces commits sont sur main mais absents de develop:                         │
│   dd0cb2a chore(ci): update pipeline to use NPM_TOKEN variable               │
│   3db14b6 Merge pull request 31 from release/v1.5.2 into main                │
│                                                                              │
│   → ACTION: Recuperer ces changements avec: git merge main                   │
│                                                                              │
│ RELEASES EN COURS                                                            │
│ ──────────────────────────────────────────────────────────────────────────── │
│ Branch          │ vs develop          │ vs main             │ Status         │
│ ─────────────────────────────────────────────────────────────────────────────│
│ release/v1.5.1  │ 0 a publier/25 a    │ 0 a publier/28 a    │ TERMINEE ✓     │
│                 │ recuperer           │ recuperer           │ (supprimable)  │
│ release/v1.4.2  │ 0 a publier/26 a    │ 0 a publier/29 a    │ TERMINEE ✓     │
│                 │ recuperer           │ recuperer           │ (supprimable)  │
│                                                                              │
│ FEATURES (branches de fonctionnalites)                                       │
│ ──────────────────────────────────────────────────────────────────────────── │
│ feature/xxx: {N} commits a publier / {N} a recuperer de develop              │
│              Dernier: {message du dernier commit}                            │
└──────────────────────────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────────────────────────┐
│ EF CORE                                                                      │
├──────────────────────────────────────────────────────────────────────────────┤
│ Migrations: {total} total, {pending} pending                                 │
│ [Pending] {liste}                                                            │
│                                                                              │
│ BRANCHES AVEC MIGRATIONS                                                     │
│ ──────────────────────────────────────────────────────────────────────────── │
│   feature/add-users    +1 migration (AddUsersTable)      Conflit: NON        │
│   feature/add-orders   +1 migration (AddOrdersTable)     Conflit: NON        │
│   feature/add-products +2 migrations                     Conflit: OUI ⚠️     │
│                                                                              │
│ ORDRE DE MERGE RECOMMANDE:                                                   │
│   1. feature/add-users (independant)                                         │
│   2. feature/add-orders (independant)                                        │
│   3. feature/add-products (rebase requis apres #1 et #2)                     │
└──────────────────────────────────────────────────────────────────────────────┘

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

══════════════════════════════════════════════════════════════════════════════
 ACTIONS A FAIRE
══════════════════════════════════════════════════════════════════════════════

{Generer cette section dynamiquement selon l'etat detecte}
{Chaque action = 1 ligne description + 1 bloc code copiable}

EXEMPLES DE FORMAT:

⚠️ Recuperer 3 commits de main dans develop
git merge main

ℹ️ Creer une release (10 commits prets pour production)
/gitflow:start release v1.6.0

✓ Merger feature/add-users dans develop (prete, 0 conflit)
/gitflow:finish feature/add-users

↻ Mettre a jour feature/add-orders (15 commits a recuperer de develop)
/gitflow:rebase feature/add-orders

🗑️ Nettoyer release/v1.5.1 (terminee, supprimable)
/gitflow:cleanup release/v1.5.1

🗑️ Nettoyer release/v1.4.2 (terminee, supprimable)
/gitflow:cleanup release/v1.4.2

💾 Sauvegarder les modifications en cours (3 fichiers modifies)
/gitflow:commit "description des changements"

↑ Envoyer develop vers le serveur (5 commits non publies)
/gitflow:sync develop

══════════════════════════════════════════════════════════════════════════════
```

---

## 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` |
