rajout script de push
This commit is contained in:
52
push_patch.sh
Executable file
52
push_patch.sh
Executable file
@@ -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 <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é."
|
||||
Reference in New Issue
Block a user