#!/usr/bin/env bash # # Apply our patches + overlay onto the pristine upstream submodules. # # Fails loudly if a patch no longer applies (i.e. upstream moved after a # submodule bump), so you know exactly which patch to refresh. Idempotent: # it resets each submodule's tracked files to the pinned commit first. # set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" echo "==> Ensuring submodules are initialised & at pinned commits" git submodule update --init --recursive apply_patches() { local name="$1" dir="$2" if [ ! -d "patches/$name" ]; then return; fi echo "==> [$name] resetting to pinned commit" git -C "$dir" checkout -- . 2>/dev/null || true git -C "$dir" clean -fd -e node_modules 2>/dev/null || true echo "==> [$name] applying patches" local applied=0 for patch in patches/"$name"/*.patch; do [ -e "$patch" ] || continue echo " - $(basename "$patch")" # --3way lets git fall back to a merge if context shifted slightly. git -C "$dir" apply --3way "$ROOT/$patch" applied=$((applied + 1)) done echo "==> [$name] $applied patch(es) applied" } apply_patches ui httptoolkit-ui apply_patches server httptoolkit-server echo "==> Copying overlay files into httptoolkit-server" cp -v overlay/server/htk-entry.ts httptoolkit-server/htk-entry.ts cp -v overlay/server/src/htk-app.ts httptoolkit-server/src/htk-app.ts cp -v overlay/server/src/commands/app.ts httptoolkit-server/src/commands/app.ts echo "==> apply.sh complete."