You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Step-by-step example: updating a mathlib downstream
136
136
137
-
Suppose you maintain `MyProject`, a Lean 4 project that depends on mathlib. mathlib has released a batch of new commits and you want to know which ones your project still builds against — and find the exact commit where it breaks.
137
+
Suppose you maintain `MyProject`, a Lean 4 project that depends on mathlib. mathlib has released a batch of new commits and you want to find the exact commit where your project breaks. Because mathlib moves fast — dozens of commits a day — you almost always want bisect: it identifies the first bad commit with roughly log₂(N) probes instead of N.
### 2. Run linear mode to walk forward through mathlib commits
151
+
### 2. Run bisect to find the breaking commit
152
+
153
+
Bisect is the default — no `--scan-mode` flag needed:
152
154
153
155
```bash
154
156
hopscotch dep mathlib \
155
157
--project-dir ./MyProject \
156
158
--from a1b2c3d4 \
157
-
--to origin/master \
158
-
--scan-mode linear
159
+
--to origin/master
159
160
```
160
161
161
-
`hopscotch` fetches the commit range from GitHub (set `GITHUB_TOKEN` to avoid rate limits), then starts probing each commit. Note that `--from` is exclusive — `a1b2c3d4` itself is not tested; probing begins at the next commit after it.
162
+
`hopscotch` fetches the commit range from GitHub (set `GITHUB_TOKEN` to avoid rate limits), validates that the last commit in the range actually fails, then binary-searches. Note that `--from` is exclusive — `a1b2c3d4` itself is not tested.
Edit `MyProject/Foo.lean` to use the updated API. After fixing:
211
+
Edit `MyProject/Foo.lean` to use the updated API. With the lakefile still pinned to `4f5a6b7c` from the last probe, verify the fix locally:
189
212
190
213
```bash
191
-
cd MyProject && lake build# verify the fix works at the failing commit
214
+
cd MyProject && lake build
192
215
```
193
216
194
-
### 5. Resume from where you left off
217
+
### 5. Commit and start a fresh session
195
218
196
-
Because `hopscotch` serializes state after each step, you can resume without re-testing commits that already passed:
219
+
Bisect's goal is identification, not incremental repair — once it finds the boundary the session is complete. Commit your fix, clear the state, and run again to check whether the rest of the range is clean:
197
220
198
221
```bash
222
+
cd MyProject && git add -p && git commit -m "fix: update to renamed Mathlib.SomeRenamedLemma"
223
+
rm -rf MyProject/.lake/hopscotch
224
+
199
225
hopscotch dep mathlib \
200
226
--project-dir ./MyProject \
201
227
--from a1b2c3d4 \
202
-
--to origin/master \
203
-
--allow-dirty-workspace # skip git-cleanliness check since you made edits
228
+
--to origin/master
204
229
```
205
230
206
-
`hopscotch` picks up at commit `c3d4e5f6` with your fix applied and continues:
[2026-03-31T14:00:01Z] Running lake update mathlib
211
-
…
212
-
[2026-03-31T14:05:00Z] Finished lake build (log file: …) ← now passes
213
-
…
214
-
```
231
+
If there is only one regression in the range this second run will complete with all commits passing. If there are multiple regressions, bisect will find the next boundary and you repeat.
215
232
216
-
Repeat steps 3–5 for each failure until the full range passes.
233
+
### Aside: Linear mode for incremental iteration
217
234
218
-
### 6. Pinpoint a breaking commit with bisect
235
+
`--scan-mode linear` steps through commits oldest-to-newest and stops at the first failure. It is useful when:
219
236
220
-
If the commit range is large and you just want to identify the culprit quickly without fixing things incrementally, omit `--scan-mode` (bisect is the default) or pass it explicitly:
237
+
- you are testing a single commit (`--from <last-good> --to <candidate>`)
238
+
- you prefer to fix each regression before moving to the next, letting you accumulate fixes across a long walk
221
239
222
240
```bash
223
241
hopscotch dep mathlib \
224
242
--project-dir ./MyProject \
225
243
--from a1b2c3d4 \
226
-
--to origin/master
244
+
--to origin/master \
245
+
--scan-mode linear
227
246
```
228
247
229
-
`hopscotch` binary-searches the range, probing roughly log₂(N) commits instead of all N. The output format is the same per-step timestamped log as linear mode; the summary at `.lake/hopscotch/summary.md` records the last known-good commit and the first known-bad commit.
248
+
Because linear mode serializes state after each step, rerunning the same command after a failure resumes from exactly where it stopped. Once the previously-failing commit passes, `hopscotch` checks that the working tree is clean before advancing — ensuring every fix is committed before the session moves on. Pass `--allow-dirty-workspace` to skip this check when you are iterating on a fix across several commits before committing.
0 commit comments