Skip to content

[kyo-sql-dolt] stageMerge: a merge left staged for the caller to commit once - #2007

Merged
fwbrasil merged 1 commit into
mainfrom
kyo-dolt-stage-merge
Sep 27, 2026
Merged

fwbrasil merged 1 commit into
mainfrom
kyo-dolt-stage-merge

Conversation

@fwbrasil

Copy link
Copy Markdown
Collaborator

Problem

Dolt.merge either fast-forwards or commits the merge itself, so a caller cannot add its own rows to the merge commit. A caller that must write an anchor row into every commit on a branch has no way to do it for merges: a fast-forward puts the other branch's commits on it untouched, and a merge commit is already recorded before the caller can write.

Two DoltLite defects surfaced while testing it:

  • A conflicting merge or pull raised the engine's error instead of answering Dolt.Merge.Conflicted. The engine rolls a conflicting merge back under autocommit before anything can read the conflicts.
  • log(ref) read the bare dolt_log, which lists only the current branch, so a commit that exists only on another branch was missing from that branch's log, and commitAt could not find it.

Solution

Dolt.stageMerge(from) is git merge --no-ff --no-commit on both engines. A clean merge answers Dolt.Merge.Staged and leaves the merged changes in the working set; the caller writes more and its next commit records one commit with both parents, holding the merged changes and the caller's writes. It never fast-forwards.

Dolt.Merge becomes a sealed trait, and a new sealed Dolt.StagedMerge is what stageMerge answers: UpToDate, Conflicted or Staged. Each operation's answer type holds exactly the outcomes it can produce, so merge never answers Staged and stageMerge never answers FastForward or Merged. Both engines answer a staged merge like an up-to-date one, so dolt_merge_status.is_merging tells them apart.

On DoltLite, a conflicting merge, stageMerge or pull now runs under autocommit and, when it fails, replays the call inside a transaction on one pinned session, reads the conflicts, and rolls back. It answers Conflicted and leaves the branch as it was. log(ref) and commitAt read dolt_log(revision).

Notes

  • Conflicts diverge between the engines, and the divergence is declared on Dolt.merge and Dolt.Merge.Conflicted: the server keeps a conflicted merge in the working set to resolve, while DoltLite never keeps conflicts past a transaction, so it reports them and rolls back. Tests assert both sides.
  • Why a separate method rather than a flag or a new merge case is recorded in kyo-sql/CONTRIBUTING.md.
  • Tests: DoltLiteClientTest 18 passed, 1 cancelled (the engine-absent leaf) on JVM, JS, Wasm and Native. SqlDoltOnlyTest against a Dolt 2.3.4 server in podman: 22 passed on JVM, JS, Wasm and Native. Both cover the fast-forward-possible case (two parents, the caller's rows in the same commit, the branch unmoved until commit), diverged branches, up to date, and conflicts.

…it once

## Problem

`Dolt.merge` either fast-forwards or commits the merge itself, so a caller
cannot add its own rows to the merge commit. A caller that must write an
anchor row into every commit on a branch has no way to do it for merges:
a fast-forward puts the other branch's commits on it untouched, and a merge
commit is already recorded before the caller can write.

Two DoltLite defects surfaced while testing it:

- A conflicting `merge` or `pull` raised the engine's error instead of
  answering `Dolt.Merge.Conflicted`. The engine rolls a conflicting merge
  back under autocommit before anything can read the conflicts.
- `log(ref)` read the bare `dolt_log`, which lists only the current branch,
  so a commit that exists only on another branch was missing from that
  branch's log, and `commitAt` could not find it.

## Solution

`Dolt.stageMerge(from)` is `git merge --no-ff --no-commit` on both engines.
A clean merge answers `Dolt.Merge.Staged` and leaves the merged changes in
the working set; the caller writes more and its next `commit` records one
commit with both parents, holding the merged changes and the caller's
writes. It never fast-forwards.

`Dolt.Merge` becomes a sealed trait, and a new sealed `Dolt.StagedMerge` is
what `stageMerge` answers: `UpToDate`, `Conflicted` or `Staged`. Each
operation's answer type holds exactly the outcomes it can produce, so
`merge` never answers `Staged` and `stageMerge` never answers
`FastForward` or `Merged`. Both engines answer a staged merge like an
up-to-date one, so `dolt_merge_status.is_merging` tells them apart.

On DoltLite, a conflicting `merge`, `stageMerge` or `pull` now runs under
autocommit and, when it fails, replays the call inside a transaction on one
pinned session, reads the conflicts, and rolls back. It answers
`Conflicted` and leaves the branch as it was. `log(ref)` and `commitAt`
read `dolt_log(revision)`.

## Notes

- Conflicts diverge between the engines, and the divergence is declared on
  `Dolt.merge` and `Dolt.Merge.Conflicted`: the server keeps a conflicted
  merge in the working set to resolve, while DoltLite never keeps
  conflicts past a transaction, so it reports them and rolls back. Tests
  assert both sides.
- Why a separate method rather than a flag or a new `merge` case is
  recorded in `kyo-sql/CONTRIBUTING.md`.
- Tests: `DoltLiteClientTest` 18 passed, 1 cancelled (the engine-absent
  leaf) on JVM, JS, Wasm and Native. `SqlDoltOnlyTest` against a Dolt
  2.3.4 server in podman: 22 passed on JVM, JS, Wasm and Native. Both
  cover the fast-forward-possible case (two parents, the caller's rows in
  the same commit, the branch unmoved until commit), diverged branches,
  up to date, and conflicts.
@fwbrasil
fwbrasil merged commit d85c852 into main Sep 27, 2026
14 checks passed
@fwbrasil
fwbrasil deleted the kyo-dolt-stage-merge branch September 27, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant