60 lines
1.2 KiB
Bash
60 lines
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
current_branch=$(git branch --show-current)
|
|
|
|
if [ -z "$current_branch" ]; then
|
|
echo "Erreur : impossible de détecter la branche courante."
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$current_branch" = "main" ]; then
|
|
echo "Erreur : ce script ne peut pas être exécuté depuis la branche main."
|
|
exit 1
|
|
fi
|
|
|
|
start_branch="$current_branch"
|
|
|
|
cleanup() {
|
|
if [ "$(git branch --show-current)" != "$start_branch" ]; then
|
|
git checkout "$start_branch" >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
|
|
merge_or_fail() {
|
|
source_branch="$1"
|
|
target_branch="$2"
|
|
|
|
if ! git merge "$source_branch"; then
|
|
echo "Erreur : conflit lors du merge de $source_branch vers $target_branch."
|
|
echo "Résolvez les conflits manuellement, puis relancez le script."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
echo "Branche courante détectée : $current_branch"
|
|
read -r -p "Confirmer l'exécution sur cette branche ? [y/N] " confirm
|
|
case "$confirm" in
|
|
y|Y|yes|YES)
|
|
;;
|
|
*)
|
|
echo "Annulé."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
if [ "$current_branch" != "dev" ]; then
|
|
git checkout dev
|
|
merge_or_fail "$current_branch" "dev"
|
|
git push
|
|
current_branch="dev"
|
|
fi
|
|
|
|
git checkout main
|
|
merge_or_fail dev main
|
|
git push
|
|
git checkout dev
|