#!/bin/bash

VERSION=$1

if [ -z "$VERSION" ]; then
  echo "Usage: ./hotfix.sh 1.0.1"
  exit 1
fi

echo "🔄 Checkout master"
git checkout master
git pull

echo "🔀 Merge hotfix/$VERSION"
git merge hotfix/$VERSION

echo "🏷️ Tag version"
git tag -a v$VERSION -m "Hotfix $VERSION"

echo "⬆️ Push master + tag"
git push origin master
git push origin v$VERSION

echo "🔁 Merge back into develop"
git checkout develop
git merge hotfix/$VERSION
git push

echo "🧹 Delete hotfix branch"
git branch -d hotfix/$VERSION
git push origin --delete hotfix/$VERSION

echo "✅ Hotfix $VERSION deployed"