🚀 Patch auto
This commit is contained in:
@@ -1,52 +1,47 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# --- options ---
|
MSG="${1:-🚀 Patch auto}"
|
||||||
MSG="${1:-}" # message passé en argument
|
SCRIPT_NAME="$(basename "$0")"
|
||||||
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')"
|
|
||||||
|
|
||||||
# --- préchecks ---
|
# 0) pré-checks
|
||||||
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
|
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
|
||||||
echo "❌ Lance ce script depuis un dépôt git (racine du projet)."
|
echo "❌ Lance ce script depuis la racine d'un dépôt git."; exit 1; }
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Branche courante
|
# 1) se placer/Créer la branche main
|
||||||
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
if git show-ref --verify --quiet refs/heads/main; then
|
||||||
|
git checkout main
|
||||||
# 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
|
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"
|
echo "✅ Commit créé: $MSG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 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
|
else
|
||||||
echo "ℹ️ Aucun changement détecté (workspace propre)."
|
git push -u origin main
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- push ---
|
echo "✅ Push terminé sur 'origin/main'."
|
||||||
# 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"
|
|
||||||
else
|
|
||||||
echo "⇡ Première publication de la branche '$BRANCH' (upstream)…"
|
|
||||||
git push -u origin "$BRANCH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "✅ Terminé."
|
|
||||||
Reference in New Issue
Block a user