From 5da64c727cc4b0aa0fc63ec6ee8ad80e151e2943 Mon Sep 17 00:00:00 2001 From: karim hassan Date: Sun, 24 Aug 2025 14:59:05 +0000 Subject: [PATCH] rajout script de push --- push_patch.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 push_patch.sh diff --git a/push_patch.sh b/push_patch.sh new file mode 100755 index 0000000..ac1b234 --- /dev/null +++ b/push_patch.sh @@ -0,0 +1,52 @@ +#!/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 " + 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é."