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

A test pins `revertCommit`: undoing a shipped commit keeps later changes, reports a real conflict, and refuses a merge commit with two parents #6703

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

`revertCommit` and `commitParents` now have tests in `test/git-revert.test.ts`. All 6 pass, and the push went through. `bun x tsc --noEmit` couldn't run here: it reported a missing `bun` type definition (TS2688) even after `bun install` ran, so the type check is unconfirmed until the forge's check runs. `src/git/revert.ts` is unchanged.

shipped production is serving it deploy c1f25a9

opened this

revertCommit and commitParents now have tests in test/git-revert.test.ts. All 6 pass, and the push went through. bun x tsc --noEmit couldn't run here: it reported a missing bun type definition (TS2688) even after bun install ran, so the type check is unconfirmed until the forge's check runs. src/git/revert.ts is unchanged.

Each test builds a throwaway repository in $TMPDIR:

  • Later work stays: reverting B with C on top removes only B's line, and C's edit survives.
  • Conflict: when C rewrote B's lines, the result is {kind: "conflict", files: ["f.txt"]}, and the refs are identical before and after.
  • New commit: its only parent is ontoOid, and it carries the given message and author (name and email, for both author and committer).
  • Parents: commitParents returns [] for a root, one oid for a squash, and two for a merge. It returns undefined for a malformed oid.
  • What revertCommit does with each:

- A root commit is refused with a git error. - A merge commit with two parents is reverted against its first parent, so the side branch's file goes and main's edit stays. - Anything over two parents returns {kind: "octopus", parents: n}. - An unsafe oid returns unsafe.

The issue title says a merge commit with two parents should be refused, but the code reverts it against the first parent, as git revert -m 1 does. I pinned the code's behaviour, not the title's, and only octopus merges are refused. If you want two-parent merges refused too, that is a code change in src/git/revert.ts.

To try it, run bun test test/git-revert.test.ts.

Closes #6702

commented

revertCommit and commitParents now have tests in test/git-revert.test.ts. All 6 pass, and the push went through. bun x tsc --noEmit couldn't run here: it reported a missing bun type definition (TS2688) even after bun install ran, so the type check is unconfirmed until the forge's check runs. src/git/revert.ts is unchanged.

Each test builds a throwaway repository in $TMPDIR:

  • Later work stays: reverting B with C on top removes only B's line, and C's edit survives.
  • Conflict: when C rewrote B's lines, the result is {kind: "conflict", files: ["f.txt"]}, and the refs are identical before and after.
  • New commit: its only parent is ontoOid, and it carries the given message and author (name and email, for both author and committer).
  • Parents: commitParents returns [] for a root, one oid for a squash, and two for a merge. It returns undefined for a malformed oid.
  • What revertCommit does with each:

- A root commit is refused with a git error. - A merge commit with two parents is reverted against its first parent, so the side branch's file goes and main's edit stays. - Anything over two parents returns {kind: "octopus", parents: n}. - An unsafe oid returns unsafe.

The issue title says a merge commit with two parents should be refused, but the code reverts it against the first parent, as git revert -m 1 does. I pinned the code's behaviour, not the title's, and only octopus merges are refused. If you want two-parent merges refused too, that is a code change in src/git/revert.ts.

To try it, run bun test test/git-revert.test.ts.

Approved

Tests-only change; src/git/revert.ts untouched. Covers keep-later-work, real conflict (files named, refs unchanged), single parent/message/author, commitParents for root/squash/merge/bad oid, root refusal, merge reverted on first parent, octopus and unsafe oid. Each assertion matches revert.ts as read. Caveat: this checkout did not contain the test file so I could not run it myself; reading it against the source, the expectations hold. Next: (1) the issue title says a two-parent merge is refused but the code reverts it with -m 1; the pull pins the code, so decide in the issue whether the title or the code is right. (2) The tsc TS2688 was unconfirmed locally; make sure the forge check shows it clean. Optional: the root-commit case asserts kind git, which is a weak message-less pin; fine for now.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs