---
description: Rescue modifications from develop to a feature branch
agent: gitflow-commit
model: sonnet
---

# GITFLOW RESCUE - Sauvetage des modifications develop vers feature

Tu es un **Expert Git** et **Expert GitFlow**. Cette commande sauve les modifications faites par erreur sur `develop` vers une branche feature propre.

> **CLAUDE INSTRUCTION:** Les blocs `AskUserQuestion({...})` ci-dessous sont des instructions pour utiliser le tool `AskUserQuestion` de maniere **interactive**. Tu DOIS executer le tool avec ces parametres pour obtenir la reponse de l'utilisateur AVANT de continuer. NE PAS afficher ce code - ATTENDRE la reponse.

---

## ETAPE 1: ANALYSE COMPLETE DE L'ETAT

### 1.1 Fetch et detection

```bash
# Fetch pour avoir les infos a jour
git fetch origin --quiet 2>/dev/null

# Etat du working directory
STAGED=$(git diff --cached --name-only | wc -l)
MODIFIED=$(git diff --name-only | wc -l)
UNTRACKED=$(git ls-files --others --exclude-standard | wc -l)

# Determiner si dirty
if [ "$STAGED" -gt 0 ] || [ "$MODIFIED" -gt 0 ] || [ "$UNTRACKED" -gt 0 ]; then
  HAS_CHANGES="true"
else
  HAS_CHANGES="false"
fi

# Commits locaux non pushes
LOCAL_COMMITS=$(git rev-list --count origin/develop..HEAD 2>/dev/null || echo "0")

# Commits distants non recuperes
REMOTE_COMMITS=$(git rev-list --count HEAD..origin/develop 2>/dev/null || echo "0")

# Determiner l'etat de synchronisation
if [ "$LOCAL_COMMITS" -eq 0 ] && [ "$REMOTE_COMMITS" -eq 0 ]; then
  SYNC_STATE="SYNCED"
elif [ "$LOCAL_COMMITS" -gt 0 ] && [ "$REMOTE_COMMITS" -eq 0 ]; then
  SYNC_STATE="AHEAD"
elif [ "$LOCAL_COMMITS" -eq 0 ] && [ "$REMOTE_COMMITS" -gt 0 ]; then
  SYNC_STATE="BEHIND"
else
  SYNC_STATE="DIVERGED"
fi

echo "=== ANALYSE DEVELOP ==="
echo "Working directory: HAS_CHANGES=$HAS_CHANGES (staged=$STAGED, modified=$MODIFIED, untracked=$UNTRACKED)"
echo "Commits: LOCAL=$LOCAL_COMMITS, REMOTE=$REMOTE_COMMITS"
echo "Sync state: $SYNC_STATE"
```

### 1.2 Classification du cas

| # | HAS_CHANGES | LOCAL_COMMITS | SYNC_STATE | CAS |
|---|-------------|---------------|------------|-----|
| 1 | false | 0 | SYNCED | CLEAN - Rien a faire |
| 2 | true | 0 | SYNCED | DIRTY_ONLY - Modifications non committees |
| 3 | false | >0 | AHEAD/SYNCED | COMMITS_ONLY - Commits locaux |
| 4 | true | >0 | AHEAD/SYNCED | COMMITS_AND_DIRTY - Commits + modifications |
| 5 | false | 0 | BEHIND | BEHIND_CLEAN - Develop en retard |
| 6 | true | 0 | BEHIND | BEHIND_DIRTY - Retard + modifications |
| 7 | false | >0 | BEHIND | REBASE_NEEDED - Commits + retard |
| 8 | true | >0 | BEHIND | REBASE_COMPLEX - Tout combine |
| 9 | * | * | DIVERGED | DIVERGED - Analyse manuelle |

---

## ETAPE 2: TRAITEMENT PAR CAS

### CAS 1: CLEAN - Rien a sauver

**Condition:** `HAS_CHANGES=false && LOCAL_COMMITS=0 && SYNC_STATE=SYNCED`

```
==============================================================================
                    DEVELOP EST PROPRE
==============================================================================

Aucune modification detectee sur develop.
Vous pouvez creer une feature directement.

PROCHAINE ETAPE:
  /gitflow:10-start feature <nom>

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

**Action:** Terminer avec message informatif. Pas de rescue necessaire.

---

### CAS 2: DIRTY_ONLY - Modifications non committees uniquement

**Condition:** `HAS_CHANGES=true && LOCAL_COMMITS=0 && (SYNC_STATE=SYNCED || SYNC_STATE=BEHIND)`

**Affichage:**

```
==============================================================================
                    MODIFICATIONS NON COMMITTEES DETECTEES
==============================================================================

Working directory:
  * {STAGED} fichiers stages
  * {MODIFIED} fichiers modifies
  * {UNTRACKED} fichiers non suivis

PLAN D'ACTION:
  1. Sauvegarder les modifications (stash)
  2. Creer la branche feature depuis develop
  3. Restaurer les modifications sur la feature

Develop restera INTACT et synchronise avec origin.

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

**Question:**

```javascript
AskUserQuestion({
  questions: [{
    question: "Quel nom pour la feature branch ?",
    header: "Feature",
    options: [
      { label: "add-", description: "Ajouter une nouvelle fonctionnalite" },
      { label: "update-", description: "Ameliorer une fonctionnalite existante" },
      { label: "fix-", description: "Correction de bug" }
    ],
    multiSelect: false
  }]
})
// L'utilisateur doit pouvoir saisir le nom complet via "Other"
```

**Execution:**

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/5] Point de restauration cree: ${RESCUE_TAG}"

# 1. Stash avec message descriptif
git stash push -m "gitflow-rescue: modifications pour ${FEATURE_BRANCH}" --include-untracked
echo "[2/5] Modifications sauvegardees (stash)"

# 2. Si BEHIND, pull d'abord
if [ "$SYNC_STATE" = "BEHIND" ]; then
  git pull origin develop --ff-only
  echo "[3/5] Develop synchronise avec origin"
else
  echo "[3/5] Develop deja synchronise"
fi

# 3. Creer la feature depuis develop (qui est synced)
git checkout -b "${FEATURE_BRANCH}" origin/develop
echo "[4/5] Branche ${FEATURE_BRANCH} creee"

# 4. Restaurer les modifications
git stash pop
echo "[5/5] Modifications restaurees"

echo ""
echo "=============================================================================="
echo "                    RESCUE REUSSI"
echo "=============================================================================="
echo ""
echo "Feature creee: ${FEATURE_BRANCH}"
echo "Fichiers restaures: $(git status --short | wc -l)"
echo ""
echo "develop: Propre et synchronise avec origin"
echo "feature: Contient vos modifications"
echo ""
echo "PROCHAINES ETAPES:"
echo "  /gitflow:3-commit     -> Committer vos modifications"
echo "  /gitflow:7-pull-request -> Creer une PR quand pret"
echo ""
echo "Point de restauration: ${RESCUE_TAG}"
echo "  En cas de probleme: git checkout develop && git reset --hard ${RESCUE_TAG}"
echo ""
echo "=============================================================================="
```

---

### CAS 3: COMMITS_ONLY - Commits locaux non pushes (clean)

**Condition:** `HAS_CHANGES=false && LOCAL_COMMITS>0 && (SYNC_STATE=AHEAD || SYNC_STATE=SYNCED)`

**Affichage:**

```
==============================================================================
                    COMMITS LOCAUX DETECTES SUR DEVELOP
==============================================================================

{LOCAL_COMMITS} commit(s) sur develop NON pushes:
------------------------------------------------------------------------------
{git log origin/develop..HEAD --oneline}
------------------------------------------------------------------------------

PLAN D'ACTION:
  1. Creer la branche feature avec ces commits
  2. Remettre develop a l'etat de origin/develop

ATTENTION: Ces commits seront DEPLACES (pas copies) vers la feature.
           Develop local sera RESET a origin/develop.

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

**Generation nom suggere:**

```bash
# Extraire le scope ou type du premier commit
FIRST_COMMIT_MSG=$(git log -1 --format='%s' origin/develop..HEAD)
# Exemple: "fix(auth): correct login flow" -> "fix-auth"
# Ou: "add user authentication" -> "add-user-authentication"
SUGGESTED_NAME=$(echo "$FIRST_COMMIT_MSG" | \
  sed 's/[(:].*//g' | \
  tr '[:upper:]' '[:lower:]' | \
  sed 's/[^a-z0-9 ]//g' | \
  tr ' ' '-' | \
  sed 's/--*/-/g' | \
  sed 's/^-//;s/-$//' | \
  cut -c1-40)
```

**Question:**

```javascript
AskUserQuestion({
  questions: [{
    question: "Confirmer le deplacement des commits vers une feature ?",
    header: "Confirm",
    options: [
      { label: "Oui, deplacer (Recommande)", description: `${LOCAL_COMMITS} commits -> feature branch` },
      { label: "Non, annuler", description: "Garder les commits sur develop" }
    ],
    multiSelect: false
  }]
})

// Si "Oui", demander le nom
if (response === "Oui, deplacer (Recommande)") {
  AskUserQuestion({
    questions: [{
      question: `Nom de la feature (suggestion: ${SUGGESTED_NAME}) ?`,
      header: "Feature",
      options: [
        { label: SUGGESTED_NAME, description: "Genere depuis le premier commit (Recommande)" },
        { label: "Autre nom", description: "Saisir un nom personnalise" }
      ],
      multiSelect: false
    }]
  })
}
```

**Execution:**

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/4] Point de restauration cree: ${RESCUE_TAG}"

# 1. Creer la feature branch a partir de HEAD actuel (avec les commits)
git branch "${FEATURE_BRANCH}"
echo "[2/4] Branche ${FEATURE_BRANCH} creee avec les commits"

# 2. Reset develop a origin/develop
git reset --hard origin/develop
echo "[3/4] develop reset a origin/develop"

# 3. Checkout la feature
git checkout "${FEATURE_BRANCH}"
echo "[4/4] Bascule sur ${FEATURE_BRANCH}"

echo ""
echo "=============================================================================="
echo "                    RESCUE REUSSI"
echo "=============================================================================="
echo ""
echo "Feature creee: ${FEATURE_BRANCH}"
echo "Commits deplaces: ${LOCAL_COMMITS}"
echo ""
echo "develop: RESET a origin/develop (propre)"
echo "feature: Contient vos ${LOCAL_COMMITS} commits"
echo ""
echo "PROCHAINES ETAPES:"
echo "  /gitflow:3-commit     -> Continuer a developper"
echo "  /gitflow:7-pull-request -> Creer une PR quand pret"
echo ""
echo "Point de restauration: ${RESCUE_TAG}"
echo "  En cas de probleme: git checkout develop && git reset --hard ${RESCUE_TAG}"
echo ""
echo "=============================================================================="
```

---

### CAS 4: COMMITS_AND_DIRTY - Commits locaux + Modifications non committees

**Condition:** `HAS_CHANGES=true && LOCAL_COMMITS>0 && (SYNC_STATE=AHEAD || SYNC_STATE=SYNCED)`

**Affichage:**

```
==============================================================================
                    COMMITS + MODIFICATIONS DETECTES
==============================================================================

COMMITS ({LOCAL_COMMITS} non pushes):
------------------------------------------------------------------------------
{git log origin/develop..HEAD --oneline}
------------------------------------------------------------------------------

MODIFICATIONS EN COURS:
  * {STAGED} fichiers stages
  * {MODIFIED} fichiers modifies
  * {UNTRACKED} fichiers non suivis

PLAN D'ACTION:
  1. Sauvegarder les modifications (stash)
  2. Creer feature avec les commits existants
  3. Reset develop a origin/develop
  4. Restaurer les modifications sur la feature

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

**Execution:**

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/6] Point de restauration cree: ${RESCUE_TAG}"

# 1. Stash les modifications en cours
git stash push -m "gitflow-rescue: WIP pour ${FEATURE_BRANCH}" --include-untracked
echo "[2/6] Modifications sauvegardees (stash)"

# 2. Creer la feature branch a partir de HEAD (avec les commits)
git branch "${FEATURE_BRANCH}"
echo "[3/6] Branche ${FEATURE_BRANCH} creee avec les commits"

# 3. Reset develop
git reset --hard origin/develop
echo "[4/6] develop reset a origin/develop"

# 4. Checkout feature
git checkout "${FEATURE_BRANCH}"
echo "[5/6] Bascule sur ${FEATURE_BRANCH}"

# 5. Restaurer le stash
git stash pop
echo "[6/6] Modifications restaurees"

echo ""
echo "=============================================================================="
echo "                    RESCUE REUSSI"
echo "=============================================================================="
echo ""
echo "Feature creee: ${FEATURE_BRANCH}"
echo "Commits deplaces: ${LOCAL_COMMITS}"
echo "Modifications restaurees: $(git status --short | wc -l) fichiers"
echo ""
echo "develop: RESET a origin/develop (propre)"
echo "feature: Contient vos commits ET vos modifications"
echo ""
echo "PROCHAINES ETAPES:"
echo "  /gitflow:3-commit     -> Committer vos modifications"
echo "  /gitflow:7-pull-request -> Creer une PR quand pret"
echo ""
echo "Point de restauration: ${RESCUE_TAG}"
echo ""
echo "=============================================================================="
```

---

### CAS 5: BEHIND_CLEAN - Develop en retard (clean)

**Condition:** `HAS_CHANGES=false && LOCAL_COMMITS=0 && SYNC_STATE=BEHIND`

**Affichage:**

```
==============================================================================
                    DEVELOP EN RETARD
==============================================================================

Votre develop local est {REMOTE_COMMITS} commits EN RETARD.

Commits a recuperer depuis origin/develop:
------------------------------------------------------------------------------
{git log HEAD..origin/develop --oneline}
------------------------------------------------------------------------------

PLAN D'ACTION:
  1. Mettre a jour develop (pull)
  2. Creer la feature depuis develop a jour

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

**Execution:**

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS ==="
echo ""

# 1. Pull develop
git pull origin develop --ff-only
echo "[1/2] develop synchronise avec origin"

# 2. Creer la feature
git checkout -b "${FEATURE_BRANCH}"
echo "[2/2] Branche ${FEATURE_BRANCH} creee"

echo ""
echo "=============================================================================="
echo "                    FEATURE CREEE
echo "=============================================================================="
echo ""
echo "Feature creee: ${FEATURE_BRANCH}"
echo "Base: develop a jour (${REMOTE_COMMITS} commits recuperes)"
echo ""
echo "PROCHAINES ETAPES:"
echo "  /gitflow:3-commit     -> Committer vos modifications"
echo "  /gitflow:7-pull-request -> Creer une PR quand pret"
echo ""
echo "=============================================================================="
```

---

### CAS 6: BEHIND_DIRTY - Develop en retard + modifications

**Condition:** `HAS_CHANGES=true && LOCAL_COMMITS=0 && SYNC_STATE=BEHIND`

**Execution:** Meme logique que CAS 2, mais avec pull avant le checkout de la feature.

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/5] Point de restauration cree: ${RESCUE_TAG}"

# 1. Stash
git stash push -m "gitflow-rescue: WIP pour ${FEATURE_BRANCH}" --include-untracked
echo "[2/5] Modifications sauvegardees (stash)"

# 2. Pull develop
git pull origin develop --ff-only
echo "[3/5] develop synchronise avec origin"

# 3. Creer la feature
git checkout -b "${FEATURE_BRANCH}"
echo "[4/5] Branche ${FEATURE_BRANCH} creee"

# 4. Restaurer stash
git stash pop
echo "[5/5] Modifications restaurees"

echo ""
echo "=============================================================================="
echo "                    RESCUE REUSSI"
echo "=============================================================================="
echo ""
echo "Feature creee: ${FEATURE_BRANCH}"
echo "develop: Synchronise avec origin"
echo "feature: Contient vos modifications"
echo ""
echo "PROCHAINES ETAPES:"
echo "  /gitflow:3-commit     -> Committer vos modifications"
echo ""
echo "=============================================================================="
```

---

### CAS 7: REBASE_NEEDED - Commits locaux + Remote en avance

**Condition:** `HAS_CHANGES=false && LOCAL_COMMITS>0 && REMOTE_COMMITS>0`

**Affichage:**

```
==============================================================================
                    SITUATION COMPLEXE - COMMITS LOCAUX + REMOTE EN AVANCE
==============================================================================

VOS COMMITS LOCAUX ({LOCAL_COMMITS}):
------------------------------------------------------------------------------
{git log origin/develop..HEAD --oneline}
------------------------------------------------------------------------------

COMMITS SUR ORIGIN ({REMOTE_COMMITS}):
------------------------------------------------------------------------------
{git log HEAD..origin/develop --oneline}
------------------------------------------------------------------------------

PLAN D'ACTION (rebase):
  1. Creer la feature avec vos commits
  2. Reset develop a origin/develop
  3. Rebaser la feature sur develop a jour

INFO: Vos commits seront rejoues SUR les commits distants.

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

**Question:**

```javascript
AskUserQuestion({
  questions: [{
    question: "Comment proceder avec vos commits locaux ?",
    header: "Strategy",
    options: [
      { label: "Rebase (Recommande)", description: "Rejouer vos commits sur origin/develop a jour" },
      { label: "Merge", description: "Creer un commit de merge (historique moins propre)" },
      { label: "Annuler", description: "Ne rien faire, je gere manuellement" }
    ],
    multiSelect: false
  }]
})
```

**Execution (Rebase):**

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS (REBASE) ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/5] Point de restauration cree: ${RESCUE_TAG}"

# 1. Creer la feature a partir de HEAD actuel
git branch "${FEATURE_BRANCH}"
echo "[2/5] Branche ${FEATURE_BRANCH} creee"

# 2. Reset develop a origin
git reset --hard origin/develop
echo "[3/5] develop reset a origin/develop"

# 3. Checkout feature
git checkout "${FEATURE_BRANCH}"
echo "[4/5] Bascule sur ${FEATURE_BRANCH}"

# 4. Rebase sur develop a jour
echo "[5/5] Rebase en cours..."
if git rebase develop; then
  echo ""
  echo "=============================================================================="
  echo "                    RESCUE REUSSI"
  echo "=============================================================================="
  echo ""
  echo "Feature creee: ${FEATURE_BRANCH}"
  echo "Commits deplaces et rebases: ${LOCAL_COMMITS}"
  echo ""
  echo "develop: RESET a origin/develop (propre)"
  echo "feature: Contient vos commits rebases sur develop a jour"
  echo ""
  echo "PROCHAINES ETAPES:"
  echo "  /gitflow:3-commit     -> Continuer a developper"
  echo "  /gitflow:7-pull-request -> Creer une PR quand pret"
  echo ""
  echo "Point de restauration: ${RESCUE_TAG}"
  echo ""
  echo "=============================================================================="
else
  echo ""
  echo "=============================================================================="
  echo "                    CONFLITS DE REBASE DETECTES"
  echo "=============================================================================="
  echo ""
  echo "Des conflits ont ete detectes lors du rebase."
  echo ""
  echo "RESOLUTION:"
  echo "  1. Resolvez les conflits dans les fichiers marques"
  echo "  2. git add <fichiers resolus>"
  echo "  3. git rebase --continue"
  echo ""
  echo "OU pour annuler:"
  echo "  git rebase --abort"
  echo "  git checkout develop && git reset --hard ${RESCUE_TAG}"
  echo ""
  echo "=============================================================================="
fi
```

---

### CAS 8: REBASE_COMPLEX - Commits + modifications + retard

**Condition:** `HAS_CHANGES=true && LOCAL_COMMITS>0 && REMOTE_COMMITS>0`

**Execution:** Combinaison de CAS 7 avec stash/unstash.

```bash
FEATURE_NAME="$USER_INPUT"
FEATURE_BRANCH="feature/${FEATURE_NAME}"

echo ""
echo "=== RESCUE EN COURS (COMPLEXE) ==="
echo ""

# Point de restauration
RESCUE_TAG="rescue/develop-$(date +%Y%m%d-%H%M%S)"
git tag "${RESCUE_TAG}" HEAD
echo "[1/7] Point de restauration cree: ${RESCUE_TAG}"

# 1. Stash les modifications
git stash push -m "gitflow-rescue: WIP pour ${FEATURE_BRANCH}" --include-untracked
STASHED="true"
echo "[2/7] Modifications sauvegardees (stash)"

# 2. Creer la feature a partir de HEAD actuel
git branch "${FEATURE_BRANCH}"
echo "[3/7] Branche ${FEATURE_BRANCH} creee"

# 3. Reset develop a origin
git reset --hard origin/develop
echo "[4/7] develop reset a origin/develop"

# 4. Checkout feature
git checkout "${FEATURE_BRANCH}"
echo "[5/7] Bascule sur ${FEATURE_BRANCH}"

# 5. Rebase sur develop a jour
echo "[6/7] Rebase en cours..."
if git rebase develop; then
  # 6. Restaurer stash
  git stash pop
  echo "[7/7] Modifications restaurees"

  echo ""
  echo "=============================================================================="
  echo "                    RESCUE REUSSI"
  echo "=============================================================================="
  echo ""
  echo "Feature creee: ${FEATURE_BRANCH}"
  echo "Commits deplaces et rebases: ${LOCAL_COMMITS}"
  echo "Modifications restaurees: $(git status --short | wc -l) fichiers"
  echo ""
  echo "PROCHAINES ETAPES:"
  echo "  /gitflow:3-commit     -> Committer vos modifications"
  echo ""
  echo "=============================================================================="
else
  echo ""
  echo "=============================================================================="
  echo "                    CONFLITS DE REBASE DETECTES"
  echo "=============================================================================="
  echo ""
  echo "Des conflits ont ete detectes lors du rebase."
  echo "Vos modifications non committees sont toujours dans le stash."
  echo ""
  echo "RESOLUTION:"
  echo "  1. Resolvez les conflits"
  echo "  2. git rebase --continue"
  echo "  3. git stash pop (pour recuperer vos modifications)"
  echo ""
  echo "Point de restauration: ${RESCUE_TAG}"
  echo ""
  echo "=============================================================================="
fi
```

---

### CAS 9: DIVERGED - Divergence critique

**Condition:** `SYNC_STATE=DIVERGED`

**Affichage:**

```
==============================================================================
                    DIVERGENCE CRITIQUE DETECTEE
==============================================================================

Votre develop local a DIVERGE de origin/develop.

COMMITS LOCAUX UNIQUEMENT ({LOCAL_COMMITS}):
------------------------------------------------------------------------------
{git log origin/develop..HEAD --oneline}
------------------------------------------------------------------------------

COMMITS DISTANTS UNIQUEMENT ({REMOTE_COMMITS}):
------------------------------------------------------------------------------
{git log HEAD..origin/develop --oneline}
------------------------------------------------------------------------------

BASE COMMUNE:
{git merge-base HEAD origin/develop}

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

**Question:**

```javascript
AskUserQuestion({
  questions: [{
    question: "Situation de divergence. Comment resoudre ?",
    header: "Diverge",
    options: [
      { label: "Sauvegarder mes commits -> feature (Recommande)", description: "Creer une feature avec vos commits, reset develop" },
      { label: "Forcer rebase", description: "Rebase agressif - peut causer des conflits" },
      { label: "Annuler", description: "Je vais analyser manuellement" }
    ],
    multiSelect: false
  }]
})
```

**Execution (Sauvegarder -> feature):**

Meme logique que CAS 7 ou CAS 8 selon HAS_CHANGES.

---

## RESUME DU FLUX

```
+-----------------------------------------------------------------------------+
|                         GITFLOW RESCUE FLOW                                 |
+-----------------------------------------------------------------------------+
|                                                                             |
|  DETECTION                                                                  |
|  ---------                                                                  |
|     +-------------+                                                         |
|     | git status  |---> HAS_CHANGES (dirty/clean)                           |
|     | git rev-list|---> LOCAL_COMMITS (ahead count)                         |
|     | git fetch   |---> REMOTE_COMMITS (behind count)                       |
|     +-------------+---> SYNC_STATE (synced/ahead/behind/diverged)           |
|                                                                             |
|  DECISION                                                                   |
|  --------                                                                   |
|     SYNC_STATE = ?                                                          |
|         |                                                                   |
|         +-- SYNCED ---> Cas simple (1-4)                                    |
|         |                  +-- HAS_CHANGES + LOCAL_COMMITS -> Stash/Branch  |
|         |                                                                   |
|         +-- BEHIND ---> Pull d'abord, puis cas simple (5-6)                 |
|         |                                                                   |
|         +-- AHEAD + BEHIND ---> Rebase necessaire (7-8)                     |
|         |                                                                   |
|         +-- DIVERGED ---> Analyse manuelle requise (9)                      |
|                                                                             |
|  EXECUTION                                                                  |
|  ---------                                                                  |
|     1. [Optionnel] git stash (si dirty)                                     |
|     2. [Optionnel] git pull (si behind)                                     |
|     3. git branch feature/xxx (preserver commits)                           |
|     4. git reset --hard origin/develop (nettoyer develop)                   |
|     5. git checkout feature/xxx                                             |
|     6. [Optionnel] git rebase develop (si etait behind)                     |
|     7. [Optionnel] git stash pop (restaurer WIP)                            |
|                                                                             |
|  RESULTAT                                                                   |
|  --------                                                                   |
|     OK develop = origin/develop (propre)                                    |
|     OK feature/xxx = vos commits + modifications                            |
|     OK Point de restauration cree                                           |
|                                                                             |
+-----------------------------------------------------------------------------+
```

---

## INTEGRATION WORKTREE (OPTIONNEL)

Si la configuration GitFlow utilise les worktrees (mode "organized" ou "adjacent"), la feature peut etre creee dans un worktree separe au lieu d'un simple checkout.

**Detection du mode worktree:**

```bash
# Detecter la structure existante
if [ -d "../features" ] && [ -d "../releases" ]; then
  WORKTREE_MODE="organized"
  WORKTREE_PATH="../features/${FEATURE_NAME}"
elif [ -d "../worktrees" ]; then
  WORKTREE_MODE="adjacent"
  WORKTREE_PATH="../worktrees/features/${FEATURE_NAME}"
else
  WORKTREE_MODE="none"
fi
```

**Si worktree disponible, proposer:**

```javascript
AskUserQuestion({
  questions: [{
    question: "Creer la feature dans un worktree separe ?",
    header: "Worktree",
    options: [
      { label: "Oui (Recommande)", description: `Creer dans ${WORKTREE_PATH}` },
      { label: "Non", description: "Simple checkout sur la branche" }
    ],
    multiSelect: false
  }]
})
```

**Execution avec worktree:**

```bash
# Au lieu de git checkout -b, utiliser:
mkdir -p "$(dirname ${WORKTREE_PATH})"
git worktree add "${WORKTREE_PATH}" "${FEATURE_BRANCH}"

echo ""
echo "Worktree cree: ${WORKTREE_PATH}"
echo "Pour y acceder: cd ${WORKTREE_PATH}"
```
