Merge changes

Undo a merge

Take one merged change back out of main with a new checked change, and keep main's history as it is.

bay undo reverses the effect of one merged change. It opens a new change that takes that merge's edits back out of current main. The new change runs the same checks and merges like any other change. Use it when a merge breaks something and a fix would take longer.

An undo never rewrites main. Every commit before it stays as it was. The undo merges as a new commit with a Reverts: trailer that names the undone change.

When to use undo

  • A red after merging: a post check fails. An undo of the merge that owns the red is never refused.
  • A wrong merge: a change reached main that should not have.
  • Bring a change back: undo the undo, and the original edits return.
  • Main is held: an undo merges during a hold, as a fix does.

Undo a change

Name the merged change. bay returns at once with queued, and a runner finishes the merge. When no pre-merge check covers the undo, bay merges it at once.

sh
bay undo c7k2m4qa

Wait for the outcome

--wait runs the undo and returns its outcome, as bay merge --wait does. It runs here when this checkout serves each check's environment. Else a runner runs it. --wait=<seconds> watches that long while the undo waits for a runner. It returns the outcome if one comes in time. Else it returns queued with state running, and the run goes on.

sh
bay undo c7k2m4qa --wait

Repair a conflict

Later changes may have edited the same lines. Then the undo does not merge, and bay returns MERGE_CONFLICT. bay leaves the undo change open. detail.view names its view, with conflict markers in the files. Resolve the paths in detail.conflicts, then merge the undo from that view.

sh
cd <detail.view>
# resolve each path in detail.conflicts
bay merge --wait

Let a runner undo a red

A runner can undo the change that turned main red when no fix comes in time. Set [red] undo_after_s in .bay/config.toml on main to turn it on. The wait starts when bay tells the culprit's session that its change broke the check. Without the key, bay never undoes a change on its own.

toml
# .bay/config.toml on main
[red]
undo_after_s = 1800                # 0 to 2592000 seconds (30 days)

A runner undoes the culprit only when all of these are true.

  • The evidence names the culprit, and its own runs of the check failed on the product, never flaky or unknown.
  • No fix of the red merged, and no fix, undo or change that supersedes the culprit waits in line.
  • The culprit is not an undo, so bay never undoes an undo on its own.
  • Main did not move since the runner read it.
  • The undo merges onto main without a conflict, and it still changes main.
  • When the newest failure changed the check, a run of the new check on that merge failed too.

The undo is an ordinary change under the runner's name, with the same required checks. Like every undo of a red, it goes ahead of the changes the red holds. bay decides once for each culprit, and tells its session once: the undo, or why there is none. bay status names it on the red's row: the undo change, why there is none, or when it is due. A repository whose key registry signs every request gets no automatic undo.

text
bay: change c7k2m4qa: main is red on smoke; your change broke it and no fix came in time, so bay opened its undo, change m3x7qdk2, which goes first in line. Merge your work again with the fix in a new change: bay start <intent>

How an undo works

  1. 01

    Find the merge

    bay asks the remote for the merged marker refs/bay/landed/<change>. It then finds that merge commit on main. If the remote lost that marker, bay finds the merge from the change's record instead. It reads the undone change's record from the remote, and never moves this clone's copy of it back.

  2. 02

    Build the reverse

    bay merges the reverse of that commit onto current main with git merge-tree. When the result equals main's own tree, the effect is already gone. bay opens no change.

  3. 03

    Open the undo change

    bay opens a new change on the intent undo of <change>. Its paths are the paths that the merge touched. bay writes the reverse into the view of that change.

  4. 04

    Merge

    The undo change takes the normal path to main, with the same required checks. Its merge commit carries Reverts: <change>.

Undo the same change twice

  • Each undo of one change claims the next generation of the intent undo of <change>.
  • While the first undo is open, bay refuses a second with CHANGE_SUPERSEDED.
  • Once the first undo merges or ends, the next opens.
  • The second undo also carries a Supersedes: trailer that names the first undo.
  • An undo never claims a generation of the undone change's own intent.

Fix a merged change instead

bay start --fixes <change> opens a new change that names the merged change it fixes. Its merge carries a Fixes: <change> trailer. bay start <change> --fixes <change> makes a change still open the fix in place, keeping its id. When the named change is not on main, bay refuses with CHANGE_NOT_MERGED and opens no change.

To fix a red post check, --fixes <check> names a post check of main's policy instead. With no culprit, the red's owner moves to each newer failure. The check's name never moves.

sh
bay start CARD-130 --fixes c7k2m4qa --paths src/api
bay start CARD-131 --fixes smoke

Read the lineage

bay status --lineage lists the Reverts:, Supersedes: and Fixes: pairs on main. Give a range, such as <from>..<to>, to read part of main. It reads local refs only and never fetches, so run bay status first. publication says whether bay merged the naming commit. Without a key registry, publication is always true. A trailer typed on a commit outside bay is only a claim.

sh
bay status --lineage

Results

ok, merged and queued exit 0. blocked exits 10, and failed exits 20.

ResultWhen`detail`
queuedWithout --wait: the undo change is open and waits for a runner. After --wait=<seconds> runs out, state is running and the run goes on.As for bay merge.
mergedWith --wait, or when no pre-merge check covers the undo: the undo merged.As for bay merge --wait.
okThe effect is already gone from main. bay opens no change, so the result has no change.undo: "nothing to undo", reverts, main
blocked, CHANGE_NOT_MERGEDThe change is not on main.main
blocked, MERGE_CONFLICTThe reverse does not merge onto main. The view stays open for repair.conflicts, view, reverts, main
failedbay cannot read the remote, so it cannot tell whether the change merged. A merge Git cannot read also fails. An argument that is not a change id fails too.A string that says why.

What an undo cannot do

  • It cannot remove a commit from main. Main stays append-only.
  • It cannot skip the checks. The undo is an ordinary change.
  • It cannot undo a change that is not on main. Abandon that change instead.
  • It undoes one change per call. Run it once for each change.

Refusals

Each refusal is blocked and exits 10. The Results page lists what to do next for each one.

CodeMeaning
CHANGE_NOT_MERGEDThe named change is not on main.
MERGE_CONFLICTThe reverse does not merge onto current main. detail.view holds it for repair.
CHANGE_SUPERSEDEDAn earlier undo of the same change is still open. Wait for it to merge, or give it up with bay abandon <change>.