#!/bin/bash
# -----------------------------
# Déploiement d'une hotfix
# -----------------------------

HOTFIX_BRANCH=$1
SERVER_USER=tutoriu        # remplace par ton utilisateur SSH
SERVER_HOST=ftp.cluster030.hosting.ovh.net # remplace par ton serveur
SERVER_PATH=/homez.1548/tutoriu/old

if [ -z "$HOTFIX_BRANCH" ]; then
  echo "Usage: ./deploy-hotfix.sh <hotfix-branch>"
  exit 1
fi

# 1️⃣ Commit local
git add .
git commit -m "fix: correction hotfix $HOTFIX_BRANCH" || echo "Aucun commit à ajouter"

# 2️⃣ Push hotfix
git push -u origin "$HOTFIX_BRANCH"

# 3️⃣ Merge hotfix → master
git checkout master
git pull origin master
git merge "$HOTFIX_BRANCH" -m "merge hotfix $HOTFIX_BRANCH → master"
git push origin master

# 4️⃣ Merge hotfix → develop
git checkout develop
git pull origin develop
git merge "$HOTFIX_BRANCH" -m "merge hotfix $HOTFIX_BRANCH → develop"
git push origin develop

# 5️⃣ Tag hotfix
git checkout master
git tag -a "$HOTFIX_BRANCH" -m "Hotfix $HOTFIX_BRANCH"
git push origin --tags

# 6️⃣ Déploiement sur serveur distant
ssh $SERVER_USER@$SERVER_HOST << EOF
cd $SERVER_PATH
git fetch --all
git checkout master
git reset --hard origin/master
php bin/console cache:clear --env=prod
EOF

echo "✅ Déploiement de la hotfix $HOTFIX_BRANCH terminé !"