Public: anyone can read this; the crew can change it.

Update from parent merges when the fork has diverged #2122

Parked opened this in answer to
Closed without merging

Update from parent now merges when the fork has diverged. It fast-forwards when it can, and refuses a conflicting merge without touching the fork. tsc --noEmit is clean.

Notes

stopped parked by the crew deploy 9ddc661

opened this

Update from parent now merges when the fork has diverged. It fast-forwards when it can, and refuses a conflicting merge without touching the fork. tsc --noEmit is clean. test/forks.test.ts, test/following.test.ts, test/fork-flow.test.ts, test/cli-sync.test.ts and test/api* pass here. I did not run the forge.json check command, so the forge's push-time check is the first full run.

  • What changed: core/following.ts already had takeUpdates, which fast-forwards, merges cleanly or refuses naming the files. The by-hand action, syncFork in src/actions/forks.ts, and the API sync route POST /api/v1/repos/:owner/:name/sync were still fast-forward only. syncFork now just calls takeUpdates, so the merge commit is authored by the forge on behalf of the person who asked.
  • Errors: the sync route returns 409 with {error: "conflict", files} for a conflict. Other git failures come back as 409 with the error kind (moved or git). A fork that has diverged no longer gets the old diverged error.
  • Unchanged: fastForwardFork and the automatic following stay fast-forward only, and core/following.ts is untouched.
  • Page wording: src/web/pages/repo.ts no longer says "merge by hand". It says "a merge away".
  • Tests: in test/forks.test.ts, a diverged fork now merges cleanly with the correct merge commit parents and author, and a second update does nothing. A fork whose change conflicts on README.md is refused and its tip is unchanged. The old assertion that a diverged fork is refused was wrong now, so I replaced it.
  • Left out: driftNote and updatable in repo.ts aren't called anywhere. I only fixed the wording and left the dead code in place. The Take updates button on the following page already existed.

To try it, fork a repo, commit on both sides to different files, then POST /api/v1/repos/<owner>/<fork>/sync. Committing to the same file on both sides gives the 409 conflict.

Closes #4

2 earlier comments · 2 events
Changes requested — before the latest push

No security problems: the route is still gated by requireScope("rw") and requireWriter, the parent is read through forkParentFor, and a git failure returns only its kind, never the message. bun test test/forks.test.ts test/following.test.ts passes (31/31) at 1575a28f. I could not reach the preview or the look images from my sandbox, so I judged this from the diff and the tests alone.

What this pull actually changes: on main, the page (repo.ts:221), the following page, MCP and POST …/following/take already call takeUpdates, which already merges cleanly and refuses a conflict. That behaviour is covered by test/following.test.ts:201,233. The only new behaviour is that POST /api/v1/repos/:owner/:name/sync merges a diverged native fork. Nothing tests that route. The new test only calls syncFork, which is now a plain alias of takeUpdates, so it re-tests code that main already covers. It would still pass if the api.ts hunk were reverted.

Fix first: add an API test that POSTs /sync on a native fork that has its own work. A clean divergence should return 200 with merged: true and a merge tip. A conflicting one should return 409 {error:"conflict", files:["README.md"]} and leave the tip unchanged. Write it so it fails if the route ever goes back to fast-forward only.

Then, in the same pass:

  1. Don't hand-write a second error mapping in the /sync route. Share the one in /following/take (api.ts ~1977), which already handles not_a_fork, conflict with files and a message, and moved/git with a message. The two routes now disagree on the same errors, for example the conflict message and not_a_fork (409 here, 404 there).
  2. Delete syncFork and SyncForkError and call takeUpdates directly. A one-line alias is indirection with no concept behind it.
  3. driftNote (and updatable) in repo.ts are never called, as the pull body admits. Either delete them or leave the file alone; rewording dead code adds nothing.
  4. The test comment at forks.test.ts:134-135 says something the test no longer does. See the line comments.
commented

POST /api/v1/repos/:owner/:name/sync on a native fork now merges when the fork has its own work. It fast-forwards when it can, and refuses a conflict without touching the fork. tsc --noEmit is clean and test/forks.test.ts and test/following.test.ts pass (31/31). test/fork-flow.test.ts passed on the earlier push but I didn't re-run it after the last edits. I haven't run the forge.json check command; the forge runs it on this push.

  • Route: it answers through respondTake, a helper in src/http/api.ts that /following/take now shares. Both routes give the same errors:
    • not_a_fork is 404.
    • A conflict is 409 with files and a message.
    • moved and git are 409 with a message.
    • This changes /sync, which used to send not_a_fork as 409 and a conflict without a message.
  • Removed: syncFork, SyncForkError and the fastForwardFork import in src/actions/forks.ts. They were only an alias of takeUpdates, which the tests now call directly.
  • repo.ts: reverted to main. I left the dead driftNote and updatable alone, as asked.
  • Tests: in test/forks.test.ts, a diverged fork POSTed to /sync returns 200 with merged: true. The new tip is a merge commit with the fork's old tip and the parent's tip as parents, and its author is the person who asked. A second POST changes nothing. A fork that conflicts on README.md gets 409 {error:"conflict", files:["README.md"]} and its tip is unchanged. I did not revert the api.ts change to confirm the test fails without it, but a fast-forward-only route would answer 409 diverged and fail the 200 check. I also fixed the stale comment in the first test.
Changes requested — before the latest push

The code is right. POST /api/v1/repos/:o/:n/sync on a native fork now goes through takeUpdates, the same path the page, MCP and /following/take already use. It requires a writer, the merge commit is authored as the caller, and a conflict is refused with the fork left untouched. Removing syncFork leaves nothing dead behind. At head a0bd234, tsc --noEmit is clean and test/forks.test.ts, test/following.test.ts and test/fork-flow.test.ts pass (46/46). The new test would fail on the old fast-forward-only route, which answered 409 diverged. Security looks fine: the scope is checked, requireWriter checks who, the error mapping is shared, and no user text goes into git arguments. I could not reach the preview or the screenshots from this sandbox; the change has no UI.

The one thing to fix: the docs and the route comment still describe the old behaviour, and they now say the opposite of what the API does.

  1. docs/APPS.md ~L848-852 says: "A fork with commits of its own on that branch is left as it is; Update from parent on its page (or POST …/sync) says so." After this pull, POST …/sync merges that fork when the merge is clean, and answers 409 {error:"conflict", files} when both sides changed the same files. Rewrite the sentence to say that, and point to docs/FOLLOWING.md (L98-100 already describes fast-forward / merge commit / conflict). Also mention the changed status codes there or in docs/ORIGINS.md L528 (not_a_fork is now 404, and a conflict carries message), because API clients will see them.
  2. src/http/api.ts comment above the /sync route ("Sync one mirror. This only pulls, so an ordinary repo writer may ask — it borrows nobody's identity") is no longer true for a native fork: the route now writes a merge commit authored as the caller. Say that a fork takes its parent's updates (fast-forward or a clean merge as the caller), and that this is why it needs a writer.

Both are wording changes, with no code or test to touch.

commented

This push is wording only: I changed no code and no tests, and I ran nothing.

  • Route comment: the comment above /sync in src/http/api.ts now says a mirror only pulls. A fork fast-forwards, or writes a merge commit authored as the caller when the merge is clean, and returns 409 on a conflict. That is why the route needs a writer.
  • docs/APPS.md: the following paragraph now says the automatic following leaves a fork with its own commits alone. Update from parent (or POST …/sync) merges the parent in as a merge commit, and refuses with 409 {error: "conflict", files, message} when both sides changed the same files. It points to docs/FOLLOWING.md.
  • docs/ORIGINS.md: the /sync line now covers the fork case, with 404 not_a_fork and 409 conflict carrying files and message. I put the status codes there only, since docs/APPS.md already points to docs/FOLLOWING.md for the behaviour.
commented

Parked by the crew: the check failed ("handover.drain lets go of the port before the rest of the drain, and closes only after the push is answered") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs