diff --git a/deploy.sh b/deploy.sh index adfa5b7..c05dbf9 100644 --- a/deploy.sh +++ b/deploy.sh @@ -144,21 +144,24 @@ fi # Vérifier si Git est initialisé sur le serveur echo "" echo "5. Vérification du dépôt Git sur le serveur..." -GIT_STATUS_OUTPUT=$(ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1 && echo 'OK' || echo 'NOT_INIT'") -if echo "$GIT_STATUS_OUTPUT" | grep -q "OK"; then +if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1" >/dev/null 2>&1; then echo " ✓ Dépôt Git détecté" -elif echo "$GIT_STATUS_OUTPUT" | grep -q "NOT_INIT"; then - echo " ⚠ Dépôt Git non initialisé, initialisation..." - ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}" - ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true" else - echo " ✗ Erreur de connexion SSH lors de la vérification du dépôt Git" - echo " Tentative de nettoyage et nouvelle connexion..." - cleanup_dead_ssh - sleep 2 - # Réessayer une fois après nettoyage - if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1"; then - echo " ✓ Dépôt Git détecté après réessai" + SSH_EXIT_CODE=$? + # Vérifier si c'est une erreur de connexion SSH ou si Git n'est pas initialisé + if [ $SSH_EXIT_CODE -ne 0 ]; then + echo " ⚠ Erreur de connexion SSH ou dépôt Git non initialisé" + echo " Tentative de nettoyage et nouvelle connexion..." + cleanup_dead_ssh + sleep 2 + # Réessayer une fois après nettoyage + if ssh_exec "cd ${APP_DIR} && git status >/dev/null 2>&1" >/dev/null 2>&1; then + echo " ✓ Dépôt Git détecté après réessai" + else + echo " ⚠ Dépôt Git non initialisé, initialisation..." + ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}" + ssh_exec "cd ${APP_DIR} && git checkout -b ${BRANCH} 2>/dev/null || true" + fi else echo " ⚠ Dépôt Git non initialisé, initialisation..." ssh_exec "cd ${APP_DIR} && git init && git remote add origin ${GIT_REPO} 2>/dev/null || git remote set-url origin ${GIT_REPO}"