|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Sync engine/ with a newer upstream CodeGraph release. |
| 3 | +# |
| 4 | +# Usage: scripts/sync-upstream.sh <upstream-tag> |
| 5 | +# |
| 6 | +# Workflow: |
| 7 | +# 1. Clone upstream at the target tag into a tmp dir. |
| 8 | +# 2. rsync into engine/ (preserving our patches isn't fully automatic — |
| 9 | +# conflicts on files we patched must be resolved by hand in the resulting |
| 10 | +# diff). |
| 11 | +# 3. Update engine/UPSTREAM.md with the new tag/SHA. |
| 12 | +# 4. Leaves the working tree dirty so the user can review + commit. |
| 13 | + |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +if [[ $# -ne 1 ]]; then |
| 17 | + echo "usage: $0 <upstream-tag>" |
| 18 | + exit 64 |
| 19 | +fi |
| 20 | + |
| 21 | +TAG="$1" |
| 22 | +cd "$(dirname "$0")/.." |
| 23 | +REPO_ROOT="$(pwd)" |
| 24 | + |
| 25 | +TMP="$(mktemp -d -t cga-sync-XXXXXX)" |
| 26 | +trap "rm -rf '$TMP'" EXIT |
| 27 | + |
| 28 | +echo "[1/4] Cloning upstream at $TAG..." |
| 29 | +gh repo clone colbymchenry/codegraph "$TMP/upstream" -- --depth 1 --branch "$TAG" |
| 30 | + |
| 31 | +SHA="$(cd "$TMP/upstream" && git rev-parse HEAD)" |
| 32 | + |
| 33 | +echo "[2/4] Syncing into engine/..." |
| 34 | +rsync -a --delete \ |
| 35 | + --exclude='.git' \ |
| 36 | + --exclude='.github' \ |
| 37 | + --exclude='node_modules' \ |
| 38 | + --exclude='release' \ |
| 39 | + --exclude='UPSTREAM.md' \ |
| 40 | + --exclude='PATCHES.md' \ |
| 41 | + "$TMP/upstream/" engine/ |
| 42 | + |
| 43 | +echo "[3/4] Updating engine/UPSTREAM.md..." |
| 44 | +DATE="$(date +%Y-%m-%d)" |
| 45 | +cat > engine/UPSTREAM.md <<EOF |
| 46 | +# Upstream Provenance |
| 47 | +
|
| 48 | +This directory is a flat copy of [CodeGraph](https://github.com/colbymchenry/codegraph) |
| 49 | +at a pinned commit. We do not preserve upstream's git history here. |
| 50 | +
|
| 51 | +| Field | Value | |
| 52 | +| --- | --- | |
| 53 | +| Upstream repo | https://github.com/colbymchenry/codegraph | |
| 54 | +| Vendored tag | $TAG | |
| 55 | +| Vendored commit SHA | $SHA | |
| 56 | +| Vendored on | $DATE | |
| 57 | +
|
| 58 | +## Updating |
| 59 | +
|
| 60 | +Run \`scripts/sync-upstream.sh <new-tag>\`. It fetches upstream at the target |
| 61 | +tag, syncs into \`engine/\`, and updates this file. Re-apply our patches as |
| 62 | +needed (see \`engine/PATCHES.md\`). |
| 63 | +
|
| 64 | +## What we change |
| 65 | +
|
| 66 | +See \`engine/PATCHES.md\` for the list of modifications layered on top of this |
| 67 | +upstream snapshot. |
| 68 | +EOF |
| 69 | + |
| 70 | +echo "[4/4] Done. Review with:" |
| 71 | +echo " git status engine/" |
| 72 | +echo " git diff engine/PATCHES.md" |
| 73 | +echo |
| 74 | +echo "Then re-apply patches per engine/PATCHES.md, run tests, and commit." |
0 commit comments