Files
SuperSunday/push_patch.sh
2025-08-24 14:59:05 +00:00

53 lines
1.4 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
# --- options ---
MSG="${1:-}" # message passé en argument
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')"
# --- 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
}
# 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
else
echo " Aucun changement détecté (workspace propre)."
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"
else
echo "⇡ Première publication de la branche '$BRANCH' (upstream)…"
git push -u origin "$BRANCH"
fi
echo "✅ Terminé."