From a8423f9c3960bf382376d1d53bdcebbdb857b56c Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 7 Jan 2026 18:08:07 +0100 Subject: [PATCH] Enhance deployment script to conditionally symlink data directories based on git tracking status, improving error handling for uncommitted changes. Implement cleanup of untracked files while preserving essential directories, ensuring a smoother deployment process. --- deploy-production.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/deploy-production.sh b/deploy-production.sh index bea563f..5f53dd7 100755 --- a/deploy-production.sh +++ b/deploy-production.sh @@ -55,7 +55,13 @@ has_tracked_files_under() { } echo "0. Ensuring persistent data directories (recommended)..." -ensure_symlink_dir "server/data" "$DATA_ROOT/server-data" +# IMPORTANT: Only symlink server/data if it's not tracked by git. +if has_tracked_files_under "server/data"; then + echo " Skipping symlink for server/data (tracked files detected in git)." + echo " Recommendation: remove server/data/** from git history and keep them only as production data." +else + ensure_symlink_dir "server/data" "$DATA_ROOT/server-data" +fi # IMPORTANT: Only symlink public/data if it's not tracked by git. # Otherwise git will error with "path is beyond a symbolic link". @@ -104,13 +110,18 @@ if [ -n "$(git status --porcelain | grep '^UU\|^AA\|^DD')" ]; then git reset --hard HEAD fi -# Ensure a clean working tree (we avoid git stash because it breaks with symlinked data paths) -if [ -n "$(git status --porcelain)" ]; then - echo "ERROR: Working tree is not clean. Please commit/revert changes before deployment." - echo "Hint: If this is caused by tracked production data files, remove them from git tracking." - git status --porcelain - exit 1 -fi +# Ensure git operations can run even if we have untracked local artifacts (e.g. backups/) +# We avoid `git stash` (breaks with symlinked tracked paths). Instead, hard-reset and clean safely. +echo " Resetting working tree to HEAD (production data will be restored from backup)..." +git reset --hard HEAD + +echo " Cleaning untracked files (excluding data dirs/backups/.env)..." +git clean -fd \ + -e server/data \ + -e public/data \ + -e public/uploads \ + -e backups \ + -e .env || true # Pull latest changes echo " Pulling latest changes..."