From 4d3ba589719796b53b53af86efe2aa3998b9e8fa Mon Sep 17 00:00:00 2001 From: elpatron Date: Fri, 29 May 2026 21:17:42 +0200 Subject: [PATCH] refactor: Improve Git synchronization process in update-prod.sh Enhanced the update-prod.sh script to better handle Git operations. The script now checks for local changes before syncing, fetches tags from the origin, and performs a hard reset to the current branch, providing clearer error messages for potential failures. --- scripts/update-prod.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/update-prod.sh b/scripts/update-prod.sh index 79c6508..98a2957 100755 --- a/scripts/update-prod.sh +++ b/scripts/update-prod.sh @@ -143,10 +143,26 @@ APP_VERSION="$6" cd "$REMOTE_DIR" || { echo "Error: Remote directory '$REMOTE_DIR' not found."; exit 1; } -echo "Pulling latest changes from Git..." -git pull --tags +echo "Syncing repository from origin..." +CURRENT_BRANCH="$(git branch --show-current)" +if [ -z "$CURRENT_BRANCH" ]; then + echo "Error: Could not determine current Git branch." + exit 1 +fi + +if ! git diff-index --quiet HEAD -- || [ -n "$(git status --porcelain)" ]; then + echo "Warning: Local changes on deployment host will be discarded." +fi + +git fetch --tags origin if [ $? -ne 0 ]; then - echo "Error: Git pull failed." + echo "Error: Git fetch failed." + exit 1 +fi + +git reset --hard "origin/${CURRENT_BRANCH}" +if [ $? -ne 0 ]; then + echo "Error: Git reset to origin/${CURRENT_BRANCH} failed." exit 1 fi