diff --git a/update-gitops-status.sh b/update-gitops-status.sh index b51b447..65bbbb1 100644 --- a/update-gitops-status.sh +++ b/update-gitops-status.sh @@ -248,10 +248,22 @@ if [ "$MODE" = "post-deploy" ]; then fi DEPLOYED_FILES_JSON+="]" else - # Drift-check mode: populate drifted_files, keep deployed_files empty - DEPLOYED_FILES_JSON="[]" - DRIFTED_FILES_JSON="[" + # Drift-check mode: Keep existing deployed_files, only update drifted_files + # First fetch current status to preserve deployed_files + echo " Fetching current deployed_files from API..." + CURRENT_JSON=$(curl -s "$GITOPS_STATUS_SERVER_URL/api/status" 2>/dev/null || echo "{}") + # Extract deployed_files from current JSON (use jq if available) + if command -v jq >/dev/null 2>&1; then + DEPLOYED_FILES_JSON=$(echo "$CURRENT_JSON" | jq -c '.deployed_files // []' 2>/dev/null || echo "[]") + echo " Preserving deployed_files: $DEPLOYED_FILES_JSON" + else + DEPLOYED_FILES_JSON="[]" + echo " WARNING: jq not available, cannot preserve deployed_files" + fi + + # Build drifted_files from detected drift + DRIFTED_FILES_JSON="[" if [ ${#CHANGED_FILES[@]} -gt 0 ]; then for i in "${!CHANGED_FILES[@]}"; do if [ "$i" -gt 0 ]; then