#!/usr/bin/env bash # Apply BoosAPI overlay patches on top of the vanilla ComfyUI submodule. # # Run after `git submodule update --init` or after bumping the submodule # pointer. Idempotent — files are overwritten with the overlay copy. # # Refuses to clobber a dirty submodule working tree so you don't lose # upstream work-in-progress. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OVERLAY="$ROOT/comfy_patches/overlay" TARGET="$ROOT/comfy_source" if [ ! -d "$TARGET" ]; then echo "comfy_source/ does not exist — did you forget --recurse-submodules?" >&2 exit 1 fi # Refuse to apply over a dirty submodule (anything other than our overlay diff). # The overlay files _will_ show as modified after we apply, so we only check # for OTHER changes by comparing against the upstream tree. if [ -d "$TARGET/.git" ] || [ -f "$TARGET/.git" ]; then cd "$TARGET" # Stash any pre-existing local changes that aren't part of the overlay. # We list overlay paths and exclude them from the dirty check. overlay_paths=$(cd "$OVERLAY" && find . -type f -printf '%P\n') unexpected=$(git status --porcelain | awk '{print $2}' | grep -vxF -f <(printf '%s\n' "$overlay_paths") || true) if [ -n "$unexpected" ]; then echo "comfy_source/ has unexpected local changes — aborting:" >&2 echo "$unexpected" >&2 echo "" >&2 echo "Commit/stash inside the submodule, or rm -rf and re-init it." >&2 exit 1 fi cd "$ROOT" fi count=0 while IFS= read -r -d '' src; do rel="${src#"$OVERLAY/"}" dst="$TARGET/$rel" mkdir -p "$(dirname "$dst")" cp "$src" "$dst" count=$((count + 1)) done < <(find "$OVERLAY" -type f -print0) echo "Applied $count overlay file(s) to comfy_source/."