#!/usr/bin/env bash # Builds the two Git-vs-Muse comparison demos for Episode 01's MERGE and # WHERE THEY ACTUALLY DIVERGE sections. Unlike hello-muse/ (the hand-driven # walkthrough repo), these two throwaway repo pairs are regenerated fresh # every run -- disposable scratch content, not hand-maintained. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # --------------------------------------------------------------------------- # Part 1 -- MERGE section: non-overlapping edits (greet's return string vs. # a new farewell() function). Both Git and Muse merge this cleanly. # --------------------------------------------------------------------------- GIT_REPO="$HERE/git-comparison-episode01" rm -rf "$GIT_REPO" mkdir -p "$GIT_REPO" cd "$GIT_REPO" git init -q git config user.name "Demo" git config user.email "demo@example.com" cat > hello.py <<'PY' def greet(name): return f"Hello, {name}!" if __name__ == "__main__": print(greet("world")) PY git add . && git commit -q -m "Add greet function" git checkout -q -b feature/friendlier sed -i '' 's/Hello,/Hey there,/' hello.py git commit -qam "Warmer greeting" git checkout -q main git checkout -q -b feature/farewell cat >> hello.py <<'PY' def farewell(name): return f"See you, {name}!" PY git commit -qam "Add farewell function" git checkout -q main echo "=== Part 1: git merge feature/friendlier ===" git merge --no-edit feature/friendlier echo echo "=== git merge feature/farewell ===" git merge --no-edit feature/farewell # --------------------------------------------------------------------------- # Part 2 -- WHERE THEY ACTUALLY DIVERGE: two branches each add a different # import. Git conflicts (real, same insertion point). Muse doesn't (imports # is an unordered, independently-mergeable dimension). # --------------------------------------------------------------------------- echo echo "=== Part 2: imports -- Git side ===" IMPORTS_GIT="$HERE/imports-git-episode01" rm -rf "$IMPORTS_GIT" mkdir -p "$IMPORTS_GIT" cd "$IMPORTS_GIT" git init -q git config user.name "Demo" git config user.email "demo@example.com" cat > app.py <<'PY' import os import re def greet(name): return f"Hello, {name}!" PY git add . && git commit -q -m "Initial imports" git checkout -q -b feature/add-sys cat > app.py <<'PY' import os import re import sys def greet(name): return f"Hello, {name}!" PY git commit -qam "Add sys import" git checkout -q main git checkout -q -b feature/add-json cat > app.py <<'PY' import os import re import json def greet(name): return f"Hello, {name}!" PY git commit -qam "Add json import" git checkout -q main git merge --no-edit feature/add-sys echo "--- git merge feature/add-json (the conflict) ---" git merge --no-edit feature/add-json || true echo echo "--- app.py with real conflict markers ---" cat app.py git merge --abort 2>/dev/null || true echo echo "=== Part 2: imports -- Muse side ===" IMPORTS_MUSE="$HERE/imports-muse-episode01" rm -rf "$IMPORTS_MUSE" mkdir -p "$IMPORTS_MUSE" cd "$IMPORTS_MUSE" muse init > /dev/null echo "--- imports dimension, straight from the domain ---" muse domain-info --json | python3 -c " import json, sys d = json.load(sys.stdin) for dim in d['domain_schema']['dimensions']: if dim['name'] == 'imports': print(json.dumps(dim, indent=2)) " echo cat > app.py <<'PY' import os import re def greet(name): return f"Hello, {name}!" PY muse code add . > /dev/null && muse commit -m "Initial imports" > /dev/null muse switch -c feature/add-sys > /dev/null cat > app.py <<'PY' import os import re import sys def greet(name): return f"Hello, {name}!" PY muse code add app.py > /dev/null && muse commit -m "Add sys import" > /dev/null muse switch main > /dev/null muse switch -c feature/add-json > /dev/null cat > app.py <<'PY' import os import re import json def greet(name): return f"Hello, {name}!" PY muse code add app.py > /dev/null && muse commit -m "Add json import" > /dev/null muse switch main > /dev/null echo "muse merge feature/add-sys" muse merge feature/add-sys echo echo "muse merge feature/add-json" muse merge feature/add-json echo echo "--- app.py, clean union of both imports ---" cat app.py echo echo "Demo complete. Repos left at:" echo " $GIT_REPO" echo " $IMPORTS_GIT" echo " $IMPORTS_MUSE"