make-git-vs-muse-episode01-demo.sh bash
173 lines 4.2 KB
Raw
sha256:07c10b6184a651841b238710523048c817c5c062f2435c64628f6e407e9d55e3 Fix stale 'under seven minutes' claim in THE POINT section Sonnet 5 minor ⚠ breaking 23 hours ago
1 #!/usr/bin/env bash
2 # Builds the two Git-vs-Muse comparison demos for Episode 01's MERGE and
3 # WHERE THEY ACTUALLY DIVERGE sections. Unlike hello-muse/ (the hand-driven
4 # walkthrough repo), these two throwaway repo pairs are regenerated fresh
5 # every run -- disposable scratch content, not hand-maintained.
6 set -euo pipefail
7
8 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
10 # ---------------------------------------------------------------------------
11 # Part 1 -- MERGE section: non-overlapping edits (greet's return string vs.
12 # a new farewell() function). Both Git and Muse merge this cleanly.
13 # ---------------------------------------------------------------------------
14 GIT_REPO="$HERE/git-comparison-episode01"
15 rm -rf "$GIT_REPO"
16 mkdir -p "$GIT_REPO"
17 cd "$GIT_REPO"
18
19 git init -q
20 git config user.name "Demo"
21 git config user.email "[email protected]"
22
23 cat > hello.py <<'PY'
24 def greet(name):
25 return f"Hello, {name}!"
26
27 if __name__ == "__main__":
28 print(greet("world"))
29 PY
30 git add . && git commit -q -m "Add greet function"
31
32 git checkout -q -b feature/friendlier
33 sed -i '' 's/Hello,/Hey there,/' hello.py
34 git commit -qam "Warmer greeting"
35
36 git checkout -q main
37 git checkout -q -b feature/farewell
38 cat >> hello.py <<'PY'
39 def farewell(name):
40 return f"See you, {name}!"
41 PY
42 git commit -qam "Add farewell function"
43
44 git checkout -q main
45 echo "=== Part 1: git merge feature/friendlier ==="
46 git merge --no-edit feature/friendlier
47 echo
48 echo "=== git merge feature/farewell ==="
49 git merge --no-edit feature/farewell
50
51 # ---------------------------------------------------------------------------
52 # Part 2 -- WHERE THEY ACTUALLY DIVERGE: two branches each add a different
53 # import. Git conflicts (real, same insertion point). Muse doesn't (imports
54 # is an unordered, independently-mergeable dimension).
55 # ---------------------------------------------------------------------------
56 echo
57 echo "=== Part 2: imports -- Git side ==="
58 IMPORTS_GIT="$HERE/imports-git-episode01"
59 rm -rf "$IMPORTS_GIT"
60 mkdir -p "$IMPORTS_GIT"
61 cd "$IMPORTS_GIT"
62
63 git init -q
64 git config user.name "Demo"
65 git config user.email "[email protected]"
66
67 cat > app.py <<'PY'
68 import os
69 import re
70
71 def greet(name):
72 return f"Hello, {name}!"
73 PY
74 git add . && git commit -q -m "Initial imports"
75
76 git checkout -q -b feature/add-sys
77 cat > app.py <<'PY'
78 import os
79 import re
80 import sys
81
82 def greet(name):
83 return f"Hello, {name}!"
84 PY
85 git commit -qam "Add sys import"
86
87 git checkout -q main
88 git checkout -q -b feature/add-json
89 cat > app.py <<'PY'
90 import os
91 import re
92 import json
93
94 def greet(name):
95 return f"Hello, {name}!"
96 PY
97 git commit -qam "Add json import"
98
99 git checkout -q main
100 git merge --no-edit feature/add-sys
101 echo "--- git merge feature/add-json (the conflict) ---"
102 git merge --no-edit feature/add-json || true
103 echo
104 echo "--- app.py with real conflict markers ---"
105 cat app.py
106 git merge --abort 2>/dev/null || true
107
108 echo
109 echo "=== Part 2: imports -- Muse side ==="
110 IMPORTS_MUSE="$HERE/imports-muse-episode01"
111 rm -rf "$IMPORTS_MUSE"
112 mkdir -p "$IMPORTS_MUSE"
113 cd "$IMPORTS_MUSE"
114
115 muse init > /dev/null
116
117 echo "--- imports dimension, straight from the domain ---"
118 muse domain-info --json | python3 -c "
119 import json, sys
120 d = json.load(sys.stdin)
121 for dim in d['domain_schema']['dimensions']:
122 if dim['name'] == 'imports':
123 print(json.dumps(dim, indent=2))
124 "
125 echo
126
127 cat > app.py <<'PY'
128 import os
129 import re
130
131 def greet(name):
132 return f"Hello, {name}!"
133 PY
134 muse code add . > /dev/null && muse commit -m "Initial imports" > /dev/null
135
136 muse switch -c feature/add-sys > /dev/null
137 cat > app.py <<'PY'
138 import os
139 import re
140 import sys
141
142 def greet(name):
143 return f"Hello, {name}!"
144 PY
145 muse code add app.py > /dev/null && muse commit -m "Add sys import" > /dev/null
146
147 muse switch main > /dev/null
148 muse switch -c feature/add-json > /dev/null
149 cat > app.py <<'PY'
150 import os
151 import re
152 import json
153
154 def greet(name):
155 return f"Hello, {name}!"
156 PY
157 muse code add app.py > /dev/null && muse commit -m "Add json import" > /dev/null
158
159 muse switch main > /dev/null
160 echo "muse merge feature/add-sys"
161 muse merge feature/add-sys
162 echo
163 echo "muse merge feature/add-json"
164 muse merge feature/add-json
165 echo
166 echo "--- app.py, clean union of both imports ---"
167 cat app.py
168
169 echo
170 echo "Demo complete. Repos left at:"
171 echo " $GIT_REPO"
172 echo " $IMPORTS_GIT"
173 echo " $IMPORTS_MUSE"
File History 1 commit
sha256:07c10b6184a651841b238710523048c817c5c062f2435c64628f6e407e9d55e3 Fix stale 'under seven minutes' claim in THE POINT section Sonnet 5 minor 23 hours ago