🚀 Patch auto
This commit is contained in:
@@ -1,52 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# --- options ---
|
||||
MSG="${1:-}" # message passé en argument
|
||||
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')"
|
||||
MSG="${1:-🚀 Patch auto}"
|
||||
SCRIPT_NAME="$(basename "$0")"
|
||||
|
||||
# --- préchecks ---
|
||||
# 0) pré-checks
|
||||
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
|
||||
echo "❌ Lance ce script depuis un dépôt git (racine du projet)."
|
||||
exit 1
|
||||
}
|
||||
echo "❌ Lance ce script depuis la racine d'un dépôt git."; exit 1; }
|
||||
|
||||
# Branche courante
|
||||
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||
|
||||
# Remote
|
||||
if ! git remote get-url origin >/dev/null 2>&1; then
|
||||
echo "❌ Aucun remote 'origin' configuré. Ajoute-le puis relance."
|
||||
echo " Exemple: git remote add origin <URL_SSH_OU_HTTPS>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- add + commit si nécessaire ---
|
||||
# Vérifie si des changements existent (tracked ou non)
|
||||
if git status --porcelain | grep -q .; then
|
||||
git add .
|
||||
# message de commit
|
||||
if [ -z "$MSG" ]; then
|
||||
MSG="🚀 Patch auto — ${TIMESTAMP}"
|
||||
fi
|
||||
# commit (si rien de nouveau, git renverra un code !=0)
|
||||
if ! git commit -m "$MSG" >/dev/null 2>&1; then
|
||||
echo "ℹ️ Rien de nouveau à committer après 'git add .'"
|
||||
else
|
||||
echo "✅ Commit créé: $MSG"
|
||||
fi
|
||||
# 1) se placer/Créer la branche main
|
||||
if git show-ref --verify --quiet refs/heads/main; then
|
||||
git checkout main
|
||||
else
|
||||
echo "ℹ️ Aucun changement détecté (workspace propre)."
|
||||
git checkout -b main
|
||||
fi
|
||||
|
||||
# --- push ---
|
||||
# Si upstream pas configuré, push avec -u
|
||||
if git rev-parse --abbrev-ref "@{u}" >/dev/null 2>&1; then
|
||||
echo "⇡ Pushing vers origin/$BRANCH…"
|
||||
git push origin "$BRANCH"
|
||||
# 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
|
||||
echo "⇡ Première publication de la branche '$BRANCH' (upstream)…"
|
||||
git push -u origin "$BRANCH"
|
||||
git commit -m "$MSG"
|
||||
echo "✅ Commit créé: $MSG"
|
||||
fi
|
||||
|
||||
echo "✅ Terminé."
|
||||
# 6) push sur main (crée l’upstream 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'."
|
||||
Reference in New Issue
Block a user