#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CORE_IDE_DIR="${ROOT}/core_ide" PATCH_DIR="${ROOT}/patches/lapce" SERIES_FILE="${PATCH_DIR}/series" if [[ ! -d "${CORE_IDE_DIR}/.git" ]]; then echo "Missing core_ide git checkout: ${CORE_IDE_DIR}" >&2 echo "Run: ./scripts/ensure-core-ide.sh" >&2 exit 1 fi if [[ ! -f "${SERIES_FILE}" ]]; then echo "Missing patch series file: ${SERIES_FILE}" >&2 exit 1 fi if [[ -d "${CORE_IDE_DIR}/.git/rebase-apply" ]] || [[ -d "${CORE_IDE_DIR}/.git/rebase-merge" ]]; then echo "core_ide has an in-progress rebase/am. Resolve it first." >&2 exit 1 fi if [[ -n "$(git -C "${CORE_IDE_DIR}" status --porcelain)" ]]; then echo "core_ide working tree is not clean. Commit/stash changes before applying patches." >&2 exit 1 fi mapfile -t PATCHES < <( sed -e 's/[[:space:]]\+$//' "${SERIES_FILE}" \ | awk 'NF && $1 !~ /^#/' \ | cat ) if [[ ${#PATCHES[@]} -eq 0 ]]; then echo "No patches listed in ${SERIES_FILE}. Nothing to apply." exit 0 fi for rel in "${PATCHES[@]}"; do patch_path="${PATCH_DIR}/${rel}" if [[ ! -f "${patch_path}" ]]; then echo "Patch file not found: ${patch_path}" >&2 exit 1 fi echo "Applying: ${rel}" if ! git -C "${CORE_IDE_DIR}" am --3way "${patch_path}"; then echo "Patch failed: ${rel}" >&2 echo "To abort: (cd core_ide && git am --abort)" >&2 exit 1 fi done echo "OK: applied ${#PATCHES[@]} patch(es) to core_ide."