fix: auto-stash local changes before git pull in deployment
- Check for uncommitted changes (both staged and unstaged) - Auto-stash with timestamp before pulling - Prevents "Your local changes would be overwritten" errors - Commented-out option to reapply stash after pull if needed Server changes are preserved in git stash for recovery if needed. Fixes: "error: Your local changes to the following files would be overwritten by merge"
This commit is contained in:
@@ -34,8 +34,20 @@ jobs:
|
||||
echo "🔧 Fixing repository permissions..."
|
||||
sudo chown -R $USER:$USER .
|
||||
|
||||
# Stash any local changes before pulling
|
||||
if ! git diff-files --quiet || ! git diff-index --quiet --cached HEAD; then
|
||||
echo "💾 Stashing local changes..."
|
||||
git stash push -m "Auto-stash before deployment $(date +%Y%m%d-%H%M%S)"
|
||||
fi
|
||||
|
||||
git pull origin main
|
||||
|
||||
# Reapply stashed changes if any (optional - comment out if not needed)
|
||||
# if git stash list | grep -q "Auto-stash"; then
|
||||
# echo "♻️ Reapplying stashed changes..."
|
||||
# git stash pop || echo "⚠️ Could not reapply stash (conflicts?)"
|
||||
# fi
|
||||
|
||||
echo "🔄 Restarting service..."
|
||||
sudo systemctl restart $SERVICE_NAME
|
||||
|
||||
|
||||
Reference in New Issue
Block a user