Files
SuperSunday/push_patch.sh
karim hassan e601f445cf 🚀 Patch auto
2025-08-24 15:13:31 +00:00

47 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
MSG="${1:-🚀 Patch auto}"
SCRIPT_NAME="$(basename "$0")"
# 0) pré-checks
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
echo "❌ Lance ce script depuis la racine d'un dépôt git."; exit 1; }
# 1) se placer/Créer la branche main
if git show-ref --verify --quiet refs/heads/main; then
git checkout main
else
git checkout -b main
fi
# 2) s'assurer que 'origin' existe
git remote get-url origin >/dev/null 2>&1 || {
echo "❌ Pas de remote 'origin'. Fais: git remote add origin <URL>"; exit 1; }
# 3) s'assurer que le script est committé même s'il est ignoré
# - check s'il est ignoré
if git check-ignore -q "$SCRIPT_NAME"; then
echo " $SCRIPT_NAME est ignoré par .gitignore → ajout forcé (-f)"
git add -f "$SCRIPT_NAME"
fi
# 4) stage global (ajoute le reste)
git add -A
# 5) commit si nécessaire
if git diff --cached --quiet; then
echo " Rien à commit."
else
git commit -m "$MSG"
echo "✅ Commit créé: $MSG"
fi
# 6) push sur main (crée lupstream si besoin)
if git rev-parse --abbrev-ref main@{u} >/dev/null 2>&1; then
git push origin main
else
git push -u origin main
fi
echo "✅ Push terminé sur 'origin/main'."