From 931847e0a21b836c639b1d3a89f1fe3c002a340a Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 16:57:36 -0600 Subject: [PATCH 01/15] Skip a release cherry-pick whose change is already on the release branch A merged PR whose change had already landed on its release branch was re-picked one commit at a time. Each intermediate commit conflicted against its own landed content, the workflow committed the markers, and opened a conflict PR that could only be closed (harper#3067: the second run of a demilestoned/milestoned pair re-picking harper#3038 onto v5.3). The cherry-pick job now asks .github/scripts/change-landed.sh, after checking out the release branch, whether one pick of the PR's whole net change would come out empty: a clean git merge-tree that leaves the release tree unchanged. Only that answer skips, through the existing no-op path. Partial presence, a revert, a conflict, or a check that cannot run all pick as before. The lone-merge-commit fallback is not provably the whole change and is never checked. unitTests/github/cherryPickPatch.test.mjs runs the shipped job steps against a fixture origin with gh stubbed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 8 +- .github/scripts/change-landed.sh | 24 + .github/workflows/cherry-pick-patch.yml | 32 +- DESIGN.md | 1 + unitTests/github/cherryPickPatch.test.mjs | 518 ++++++++++++++++++++++ 5 files changed, 577 insertions(+), 6 deletions(-) create mode 100755 .github/scripts/change-landed.sh create mode 100644 unitTests/github/cherryPickPatch.test.mjs diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 65c066f4c9..efee22073c 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -2,7 +2,7 @@ CI workflows. -**Read this when:** a workflow that installs dependencies fails on one Node line but not another, when changing which npm writes `package-lock.json`, when changing how the Docker image is built, smoke-tested or published, or when `Unit tests: lmdb` hits its cap or a new unit suite seeds or clears rows. +**Read this when:** a workflow that installs dependencies fails on one Node line but not another, when changing which npm writes `package-lock.json`, when changing how the Docker image is built, smoke-tested or published, when `Unit tests: lmdb` hits its cap or a new unit suite seeds or clears rows, or when changing what the release cherry-pick decides to pick. Index of every design note: [DESIGN.md](../DESIGN.md). @@ -27,3 +27,9 @@ Pushes to `main` and release branches run the same staging path, copying into a `test:unit:lmdb` re-runs `unitTests/resources`, `unitTests/apiTests` and `unitTests/bin` on LMDB, where every awaited commit waits on a disk sync. A fixture that seeds or clears one row per transaction costs seconds on the default engine and minutes on LMDB, and a runner with slow fsync multiplies exactly that part. `subscriptionPreviousCountScanBound.test.js` (harper#2826), `subscriptionSuperseded.test.js` (harper#2887) and `calibrationStore.test.js` each pushed the step past its cap this way. Nothing enforces this; the step's `timeout-minutes` is the only detector. Write a fixture's rows in one transaction and await a write only before the step that reads it. Empty a table with `Table.clear()`, or with every delete in one transaction where the table has a full-text index (`clear()` refuses it) or the suite reads the deletes from the audit log (`clear()` writes none). Where a test checks write order (calibration discovery scans decisions by time), keep those writes serial and let the independent ones commit alongside them. Before raising the cap, compare each suite's time in the `lmdb` step with the same suite in `resources (core)`/`resources (indexes)` of the same job, and fix the suite whose LMDB time grew. + +## A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`) + +Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether one pick of the PR's whole net change onto the release branch would come out empty: `git merge-tree` of that change, with its own base as the merge base, is clean and leaves the release tree unchanged. Only that answer skips the PR, with no branch and no PR. A change that is partly present, reverted, or conflicting picks as before, and so does a check that cannot run. This is the empty-pick test `scripts/apply-picks.sh` already applies to each commit, lifted to the net change. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. + +The net change is `MERGE_BASE..HEAD_SHA` when the job replays the PR's commits, which includes any merge-commit resolutions; a contained change therefore also clears that hold. It is `MERGE_SHA^1..MERGE_SHA` for a PR merged with a merge commit. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh new file mode 100755 index 0000000000..19dfa63da9 --- /dev/null +++ b/.github/scripts/change-landed.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Report whether a branch already contains a change. +# +# Usage: change-landed.sh +# Exits 0 when merging .. into (three-way, as the +# merge base) is clean and leaves 's tree unchanged: every hunk of the +# change is already there verbatim. Exits 1 otherwise — a change that is only +# partly present, was reverted, or conflicts — and 2, with a warning, when the +# check cannot run. Only 0 means "skip"; the caller picks on anything else. +set -u + +TARGET="$1" +BASE="$2" +HEAD="$3" + +MERGED=$(git merge-tree --write-tree --merge-base="$BASE" "$TARGET" "$HEAD") +case $? in + 0) [ "$MERGED" = "$(git rev-parse "$TARGET^{tree}")" ] ;; + 1) exit 1 ;; + *) + echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD, so it will be picked" + exit 2 + ;; +esac diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index c31f3295dc..d98047ee15 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -243,6 +243,7 @@ jobs: run: | cp .github/scripts/upsert-sticky-comment.js "$RUNNER_TEMP/upsert-sticky-comment.js" cp .github/scripts/apply-picks.sh "$RUNNER_TEMP/apply-picks.sh" + cp .github/scripts/change-landed.sh "$RUNNER_TEMP/change-landed.sh" - name: Configure git run: | @@ -311,9 +312,13 @@ jobs: # The PR was merged with a merge commit: it IS the change. PICK_FLAGS="-m 1" PICK_SHAS="$MERGE_SHA" + CHANGE_BASE="${MERGE_SHA}^1" + CHANGE_HEAD="$MERGE_SHA" else PICK_FLAGS="" PICK_SHAS=$(git rev-list --reverse --no-merges "${MERGE_BASE}..${HEAD_SHA}" | tr '\n' ' ') + CHANGE_BASE="$MERGE_BASE" + CHANGE_HEAD="$HEAD_SHA" # Only merges a human DECIDED something in need holding, so a # routine "merge main in, no conflicts" PR still lands # automatically. The test is whether the recorded merge matches what @@ -335,6 +340,9 @@ jobs: # something to review, but it is not provably the whole change. PICK_SHAS="$MERGE_SHA" HOLD="the PR has no replayable non-merge commits, so this branch was built from the merge commit alone" + # Not provably the whole change, so it cannot prove the whole + # change landed either. + CHANGE_HEAD="" elif [ -n "$EXCLUDED_MERGES" ]; then echo "pushed=false" >> "$GITHUB_OUTPUT" # Nothing replayable and a merge that resolved something: the @@ -350,6 +358,23 @@ jobs: fi fi fi + + # ── Create / reset cherry-pick branch off release branch ──────── + git checkout -B "$BRANCH" "origin/$RELEASE_BRANCH" + + # ── Skip a change the release branch already has ──────────────── + # + # Replaying it re-applies each intermediate commit against its own + # final content, which conflicts. Skip only when one pick of the whole + # net change would come out empty — the test apply-picks.sh applies to + # each commit — and pick on anything else, including a check that + # could not run. + if [ -n "$CHANGE_HEAD" ] && "$RUNNER_TEMP/change-landed.sh" "origin/$RELEASE_BRANCH" "$CHANGE_BASE" "$CHANGE_HEAD"; then + echo "The change from PR #$PR_NUMBER is already on $RELEASE_BRANCH — nothing to pick" + echo "no_op=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + echo "pick_flags=$PICK_FLAGS" >> "$GITHUB_OUTPUT" echo "pick_shas=$PICK_SHAS" >> "$GITHUB_OUTPUT" if [ -n "$EXCLUDED_MERGES" ]; then @@ -358,9 +383,6 @@ jobs: echo "excluded_merges=$EXCLUDED_MERGES" >> "$GITHUB_OUTPUT" echo "hold=$HOLD" >> "$GITHUB_OUTPUT" - # ── Create / reset cherry-pick branch off release branch ──────── - git checkout -B "$BRANCH" "origin/$RELEASE_BRANCH" - # ── Apply commits, tracking which conflicted ──────────────────── CONFLICTS=$("$RUNNER_TEMP/apply-picks.sh" "$PICK_FLAGS" "$PICK_SHAS") echo "conflicts=$CONFLICTS" >> "$GITHUB_OUTPUT" @@ -392,10 +414,10 @@ jobs: --base "$RELEASE_BRANCH" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || true) if [ -n "$STALE_PR" ] && [ "$STALE_PR" != "null" ]; then gh pr close "$STALE_PR" --repo "$GITHUB_REPOSITORY" \ - --comment "Superseded: PR #${PR_NUMBER} no longer produces any commits to cherry-pick onto \`${RELEASE_BRANCH}\`." >/dev/null || true + --comment "Superseded: PR #${PR_NUMBER} has nothing left to cherry-pick onto \`${RELEASE_BRANCH}\`." >/dev/null || true fi git push origin --delete "$BRANCH" 2>/dev/null || true - BODY=$(printf '%s\n## Release cherry-pick `%s`: already present\n\nEvery commit from this PR is already on `%s` — nothing to cherry-pick.\n' \ + BODY=$(printf '%s\n## Release cherry-pick `%s`: already present\n\nThe change from this PR is already on `%s` — nothing to cherry-pick.\n' \ "$STICKY_MARKER" "$RELEASE_BRANCH" "$RELEASE_BRANCH") node "$RUNNER_TEMP/upsert-sticky-comment.js" "$PR_NUMBER" "$STICKY_MARKER" "$BODY" diff --git a/DESIGN.md b/DESIGN.md index bee0ab75ce..f5cf0aa14e 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -15,6 +15,7 @@ Index of the design notes for the harper core: one line per note, grouped by the - [The lock file must pass `npm ci` under npm 10 and npm 11 (`workflows/lockfile-npm-compat.yml`)](.github/DESIGN.md#the-lock-file-must-pass-npm-ci-under-npm-10-and-npm-11-workflowslockfile-npm-compatyml) — npm 11 writes the lock but accepts some that npm 10's `npm ci` rejects; fix the conflict at its source, never by regenerating with npm 10. - [A release copies to Docker Hub only the image it booted (`workflows/docker-smoke.yml`, `workflows/publish-docker.yaml`)](.github/DESIGN.md#a-release-copies-to-docker-hub-only-the-image-it-booted-workflowsdocker-smokeyml-workflowspublish-dockeryaml) — The release builds once into a runner-local registry, smoke-tests that digest and copies the same index to Docker Hub; never a rebuild. - [Unit-test fixtures don't spend `Unit tests: lmdb` on one durable commit per row (`workflows/unit-test.yml`)](.github/DESIGN.md#unit-test-fixtures-dont-spend-unit-tests-lmdb-on-one-durable-commit-per-row-workflowsunit-testyml) — Every resources suite re-runs on LMDB, where each awaited commit syncs; fixtures batch their writes, and the step cap is the only detector. +- [A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`)](.github/DESIGN.md#a-release-cherry-pick-skips-a-change-its-branch-already-has-workflowscherry-pick-patchyml-scriptschange-landedsh) — skip only when one pick of the PR's whole net change would be empty; replaying a landed PR commit by commit conflicts instead. ## resources/ — records, transactions, tables, blobs, audit diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs new file mode 100644 index 0000000000..d11a1c8356 --- /dev/null +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -0,0 +1,518 @@ +import assert from 'node:assert'; +import { execFileSync, spawnSync } from 'node:child_process'; +import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { parse } from 'yaml'; + +// Runs the shipped cherry-pick job's `run:` steps against a local origin, with `gh` and the +// sticky-comment helper stubbed, so a test sees exactly the branches and PRs a real run makes. +const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); +const job = parse(readFileSync(join(root, '.github/workflows/cherry-pick-patch.yml'), 'utf8')).jobs['cherry-pick']; +const changeLanded = join(root, '.github/scripts/change-landed.sh'); +const RELEASE = 'v5.3'; +const PR_NUMBER = '7'; +const DEADLINE = 60_000; +// #3038's shape: the second commit rewrites the line the first one changed, so replaying the first +// onto a release that already has both conflicts instead of applying empty. +const FIRST_FIX = { 5: 'first fix' }; +const SECOND_FIX = { 5: 'second fix', 6: 'second fix, continued' }; + +describe('cherry-pick-patch.yml', function () { + let fixture; + + beforeEach(function () { + fixture = createFixture(); + }); + + afterEach(function () { + rmSync(fixture.dir, { recursive: true, force: true }); + }); + + function incidentPr() { + fixture.prCommit(FIRST_FIX, 'First fix'); + fixture.prCommit(SECOND_FIX, 'Second fix'); + return fixture.squashMerge(); + } + + it('lands a squash-merged change the release branch lacks', function () { + incidentPr(); + const run = fixture.runJob(); + assert.ok(run.ran.includes('Merge into release branch'), run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); + assert.deepStrictEqual(run.prCreates, []); + assert.deepStrictEqual(fixture.cherryPickBranches(), []); + }); + + it('makes a second run for a landed change a no-op, and closes the conflict PR an earlier run left', function () { + // #3067: one milestone change fires `demilestoned` and `milestoned`; the first run landed + // the PR's commits and the second re-picked them onto the advanced release tip. + incidentPr(); + fixture.runJob(); + const landedTip = fixture.releaseTip(); + const run = fixture.runJob({ openPr: '3067' }); + assert.strictEqual(run.outputs.no_op, 'true', run.log); + assert.match(run.log, /already on v5\.3 — nothing to pick/); + assert.deepStrictEqual(run.prCreates, [], run.log); + assert.ok(run.gh.some(([command, sub, number]) => command === 'pr' && sub === 'close' && number === '3067')); + assert.deepStrictEqual(fixture.cherryPickBranches(), []); + assert.strictEqual(fixture.releaseTip(), landedTip); + assert.match(run.stickies.at(-1), /already present/); + }); + + it('skips a change that reached the release branch as one squashed commit', function () { + const squash = incidentPr(); + const backport = fixture.onRelease((git) => git('cherry-pick', squash)); + const run = fixture.runJob(); + assert.strictEqual(run.outputs.no_op, 'true', run.log); + assert.deepStrictEqual(run.prCreates, []); + assert.deepStrictEqual(fixture.cherryPickBranches(), []); + assert.strictEqual(fixture.releaseTip(), backport); + }); + + it('picks the rest of a change the release branch has only part of', function () { + incidentPr(); + fixture.onRelease((git) => git('cherry-pick', fixture.prCommits[0])); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.strictEqual(run.outputs.conflicts, '', run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); + }); + + it('picks again a change that landed and was then reverted', function () { + incidentPr(); + fixture.runJob(); + fixture.onRelease((git) => git('revert', '--no-edit', 'HEAD', 'HEAD~1')); + assert.strictEqual(fixture.releaseFile(), fixture.lines()); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); + }); + + it('lands a change merged with a merge commit, whose PR head is already on main', function () { + fixture.prCommit(FIRST_FIX, 'First fix'); + fixture.prCommit(SECOND_FIX, 'Second fix'); + fixture.mergeCommit(); + const run = fixture.runJob(); + assert.strictEqual(run.outputs.pick_flags, '-m 1', run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); + }); + + it('still opens the conflict PR when the release branch changed the same lines differently', function () { + incidentPr(); + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines({ 5: 'release-only edit' })); + git('commit', '-qam', 'Release-only edit'); + }); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.conflicts, '', run.log); + assert.ok(run.ran.includes('Report conflict'), run.log); + assert.strictEqual(run.prCreates.length, 1, run.log); + assert.deepStrictEqual(fixture.cherryPickBranches(), [`cherry-pick/${RELEASE}/pr-${PR_NUMBER}`]); + const branchFile = fixture.git(fixture.origin, 'show', `cherry-pick/${RELEASE}/pr-${PR_NUMBER}:lib.txt`); + assert.match(branchFile, /^<<<<<<< /m); + }); + + it('picks a landed change, as before, when the containment check cannot run', function () { + incidentPr(); + fixture.runJob(); + const run = fixture.runJob({ + afterStash(temp) { + writeFileSync(join(temp, 'change-landed.sh'), '#!/usr/bin/env bash\necho "::warning::check failed"\nexit 2\n'); + }, + }); + assert.match(run.log, /::warning::check failed/); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.notStrictEqual(run.outputs.conflicts, '', run.log); + }); + + it('holds a lone fallback merge commit even when the release branch has that commit', function () { + // The PR head reached main directly, so the API's merge SHA is just its last commit. The + // release has that commit but not the one before it; only a human can tell it is incomplete. + fixture.prCommit({ 10: 'first file fix' }, 'First fix'); + fixture.prCommit({ 20: 'second file fix' }, 'Second fix'); + fixture.fastForward(); + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines({ 20: 'second file fix' })); + git('commit', '-qam', 'Backport the second fix only'); + }); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.ok(run.ran.includes('Report held for review'), run.log); + assert.match(run.stickies.at(-1), /held for review/); + }); + + describe('a PR whose merge of main resolved content of its own', function () { + const RESOLVED = { 5: 'resolved' }; + + beforeEach(function () { + fixture.prCommit(FIRST_FIX, 'First fix'); + fixture.mainCommit({ 5: 'main edit' }, 'Main edit'); + fixture.mergeMainIntoPr(RESOLVED); + fixture.squashMerge(); + }); + + it('is a no-op when its whole net change, resolution included, is on the release branch', function () { + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines(RESOLVED)); + git('commit', '-qam', 'Backport the resolved change'); + }); + const run = fixture.runJob(); + assert.strictEqual(run.outputs.no_op, 'true', run.log); + assert.ok(run.ran.includes('Report no-op'), run.log); + assert.deepStrictEqual(run.prCreates, []); + }); + + it('is held for review when the release branch lacks it', function () { + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.ok(run.ran.includes('Report held for review'), run.log); + assert.strictEqual(run.prCreates.length, 1, run.log); + }); + }); +}); + +describe('change-landed.sh', function () { + let dir; + let env; + const git = (...args) => execFileSync('git', args, { cwd: dir, env, encoding: 'utf8', timeout: DEADLINE }).trim(); + const landed = (target, base, head) => + spawnSync('bash', [changeLanded, target, base, head], { cwd: dir, env, encoding: 'utf8', timeout: DEADLINE }); + + beforeEach(function () { + dir = mkdtempSync(join(tmpdir(), 'change-landed-')); + env = isolatedGitEnv(dir); + git('init', '-q'); + git('config', 'user.name', 'Author'); + git('config', 'user.email', 'author@example.com'); + writeFileSync(join(dir, 'text.txt'), 'text\n'); + writeFileSync(join(dir, 'blob.bin'), Buffer.from([0, 1, 2, 3, 0, 255])); + writeFileSync(join(dir, 'run.sh'), 'echo run\n'); + writeFileSync(join(dir, 'gone.txt'), 'to be deleted\n'); + writeFileSync(join(dir, 'moved.txt'), Array.from({ length: 20 }, (_, index) => `moved ${index}\n`).join('')); + git('add', '.'); + git('commit', '-qm', 'Base'); + }); + + afterEach(function () { + rmSync(dir, { recursive: true, force: true }); + }); + + const changes = { + 'an executable bit': () => { + chmodSync(join(dir, 'run.sh'), 0o755); + git('add', 'run.sh'); + }, + 'binary content': () => { + writeFileSync(join(dir, 'blob.bin'), Buffer.from([0, 9, 9, 9, 0, 255])); + git('add', 'blob.bin'); + }, + 'a deletion': () => git('rm', '-q', 'gone.txt'), + 'a rename': () => git('mv', 'moved.txt', 'renamed.txt'), + 'a new file': () => { + writeFileSync(join(dir, 'new.txt'), 'new\n'); + git('add', 'new.txt'); + }, + }; + + for (const [kind, change] of Object.entries(changes)) { + it(`tells ${kind} the target has from one it lacks`, function () { + const base = git('rev-parse', 'HEAD'); + change(); + git('commit', '-qm', kind); + const head = git('rev-parse', 'HEAD'); + git('checkout', '-qb', 'target', base); + writeFileSync(join(dir, 'text.txt'), 'an unrelated release edit\n'); + git('commit', '-qam', 'Unrelated release edit'); + const without = landed('target', base, head); + assert.strictEqual(without.status, 1, without.stdout + without.stderr); + git('cherry-pick', head); + const withChange = landed('target', base, head); + assert.strictEqual(withChange.status, 0, withChange.stdout + withChange.stderr); + }); + } + + it('reports a check that cannot run with a warning and exit 2', function () { + const result = landed('refs/heads/no-such-branch', 'HEAD', 'HEAD'); + assert.strictEqual(result.status, 2, result.stderr); + assert.match(result.stdout, /^::warning::/m); + }); +}); + +function isolatedGitEnv(dir) { + const gitconfig = join(dir, '.gitconfig-test'); + writeFileSync( + gitconfig, + '[init]\n\tdefaultBranch = main\n[commit]\n\tgpgsign = false\n[advice]\n\tdetachedHead = false\n' + ); + return { + ...Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_'))), + GIT_CONFIG_GLOBAL: gitconfig, + GIT_CONFIG_NOSYSTEM: '1', + }; +} + +function createFixture() { + const dir = mkdtempSync(join(tmpdir(), 'cherry-pick-patch-')); + const bin = join(dir, 'bin'); + mkdirSync(bin); + const env = isolatedGitEnv(dir); + env.PATH = `${bin}:${process.env.PATH}`; + writeStub( + join(bin, 'gh'), + `const { appendFileSync } = require('node:fs'); +const { execFileSync } = require('node:child_process'); +const args = process.argv.slice(2); +appendFileSync(process.env.GH_LOG, JSON.stringify(args) + '\\n'); +const [command, sub] = args; +if (command === 'api' && /^repos\\/[^/]+\\/[^/]+\\/pulls\\/\\d+$/.test(sub) && args[2] === '--jq') { + process.stdout.write(execFileSync('jq', ['-c', args[3], process.env.GH_PR_JSON])); +} else if (command === 'pr' && sub === 'list') { + process.stdout.write(process.env.GH_OPEN_PR ?? ''); +} else if (command === 'pr' && sub === 'create') { + process.stdout.write('https://github.com/test/repo/pull/100\\n'); +} else if (!(command === 'pr' && ['edit', 'close'].includes(sub))) { + process.stderr.write('unexpected gh call: ' + args.join(' ') + '\\n'); + process.exit(1); +} +` + ); + const stickyStub = join(dir, 'upsert-sticky-comment.js'); + writeFileSync( + stickyStub, + `require('node:fs').appendFileSync(process.env.STICKY_LOG, JSON.stringify(process.argv[4]) + '\\n');\n` + ); + + const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', timeout: DEADLINE }).trim(); + const origin = join(dir, 'origin.git'); + const seed = join(dir, 'seed'); + git(dir, 'init', '-q', '--bare', origin); + git(dir, 'init', '-q', seed); + git(seed, 'config', 'user.name', 'Author'); + git(seed, 'config', 'user.email', 'author@example.com'); + git(seed, 'remote', 'add', 'origin', origin); + const seedGit = (...args) => git(seed, ...args); + + const lines = (overrides = {}) => + Array.from({ length: 40 }, (_, index) => overrides[index + 1] ?? `line ${index + 1}`).join('\n') + '\n'; + const writeLib = (content) => writeFileSync(join(seed, 'lib.txt'), content); + const commitLib = (overrides, message) => { + writeLib(lines(overrides)); + seedGit('commit', '-qam', message); + return seedGit('rev-parse', 'HEAD'); + }; + + writeLib(lines()); + seedGit('add', 'lib.txt'); + seedGit('commit', '-qm', 'Base'); + seedGit('branch', RELEASE); + // main moves on after the release cut, away from the lines the PRs touch + let mainState = { 35: 'main-only change' }; + commitLib(mainState, 'Main-only change'); + seedGit('branch', 'feature'); + let featureState = { ...mainState }; + const prCommits = []; + + let prJson; + const publish = (mergeSha) => { + seedGit('push', '-q', '--force', 'origin', 'main', RELEASE, `feature:refs/pull/${PR_NUMBER}/head`); + prJson = join(dir, 'pr.json'); + writeFileSync( + prJson, + JSON.stringify({ + title: 'Fix the thing', + head: { sha: seedGit('rev-parse', 'feature') }, + base: { sha: seedGit('merge-base', 'main', 'feature') }, + merge_commit_sha: mergeSha, + merged: true, + state: 'closed', + }) + ); + return mergeSha; + }; + const onBranch = (branch, change) => { + seedGit('checkout', '-q', branch); + const result = change(); + seedGit('checkout', '-q', 'main'); + return result; + }; + + return { + dir, + origin, + prCommits, + lines, + writeLib, + git, + prCommit(overrides, message) { + featureState = { ...featureState, ...overrides }; + prCommits.push(onBranch('feature', () => commitLib(featureState, message))); + }, + mainCommit(overrides, message) { + mainState = { ...mainState, ...overrides }; + commitLib(mainState, message); + }, + mergeMainIntoPr(resolution) { + featureState = { ...mainState, ...resolution }; + onBranch('feature', () => { + spawnSync('git', ['merge', '-q', 'main'], { cwd: seed, env, timeout: DEADLINE }); + writeLib(lines(featureState)); + seedGit('commit', '-qam', 'Merge main, resolving the conflict by hand'); + }); + }, + squashMerge() { + seedGit('merge', '-q', '--squash', 'feature'); + seedGit('commit', '-qm', `Fix the thing (#${PR_NUMBER})`); + return publish(seedGit('rev-parse', 'HEAD')); + }, + mergeCommit() { + seedGit('merge', '-q', '--no-ff', '-m', `Merge pull request #${PR_NUMBER}`, 'feature'); + return publish(seedGit('rev-parse', 'HEAD')); + }, + fastForward() { + seedGit('merge', '-q', '--ff-only', 'feature'); + return publish(seedGit('rev-parse', 'HEAD')); + }, + onRelease(change) { + seedGit('fetch', '-q', 'origin', `+${RELEASE}:${RELEASE}`); + return onBranch(RELEASE, () => { + change(seedGit); + seedGit('push', '-q', 'origin', RELEASE); + return seedGit('rev-parse', 'HEAD'); + }); + }, + releaseFile: () => git(origin, 'show', `${RELEASE}:lib.txt`) + '\n', + releaseTip: () => git(origin, 'rev-parse', RELEASE), + cherryPickBranches: () => + git(origin, 'for-each-ref', '--format=%(refname:short)', 'refs/heads/cherry-pick/').split('\n').filter(Boolean), + runJob(options = {}) { + return runJob({ dir, env, origin, prJson, stickyStub, git, ...options }); + }, + }; +} + +function runJob({ dir, env, origin, prJson, stickyStub, git, openPr, afterStash }) { + const run = mkdtempSync(join(dir, 'run-')); + const work = join(run, 'work'); + const temp = join(run, 'temp'); + mkdirSync(temp); + git(run, 'clone', '-q', origin, work); + const ghLog = join(run, 'gh.log'); + const stickyLog = join(run, 'sticky.log'); + const outputs = {}; + const ran = []; + let log = ''; + let failed = false; + let first = true; + for (const [index, step] of job.steps.entries()) { + if (step.uses || !stepCondition(step.if, outputs, failed)) continue; + // The real checkout is of main, which tracks .github/scripts; the fixture's main does not. + if (first) cpSync(join(root, '.github/scripts'), join(work, '.github/scripts'), { recursive: true }); + const outputFile = join(run, `output-${index}`); + writeFileSync(outputFile, ''); + const stepEnv = { + ...env, + GITHUB_OUTPUT: outputFile, + GITHUB_REPOSITORY: 'test/repo', + GITHUB_SERVER_URL: 'https://github.com', + GITHUB_RUN_ID: '1', + RUNNER_TEMP: temp, + PR_NUMBER, + GH_LOG: ghLog, + GH_PR_JSON: prJson, + STICKY_LOG: stickyLog, + }; + if (openPr) stepEnv.GH_OPEN_PR = openPr; + for (const [key, value] of Object.entries({ ...job.env, ...step.env })) { + stepEnv[key] = expand(String(value), outputs); + } + const script = join(run, `step-${index}.sh`); + writeFileSync(script, expand(step.run, outputs)); + const result = spawnSync('bash', ['--noprofile', '--norc', '-eo', 'pipefail', script], { + cwd: work, + env: stepEnv, + encoding: 'utf8', + timeout: DEADLINE, + }); + ran.push(step.name); + log += `\n── ${step.name} (exit ${result.status})\n${result.stdout}${result.stderr}`; + if (result.status !== 0) failed = true; + if (step.id) Object.assign(outputs, readOutputs(outputFile)); + if (first) { + rmSync(join(work, '.github'), { recursive: true, force: true }); + cpSync(stickyStub, join(temp, 'upsert-sticky-comment.js')); + afterStash?.(temp); + first = false; + } + } + assert.ok(!failed, log); + const readLog = (file) => + existsSync(file) + ? readFileSync(file, 'utf8') + .split('\n') + .filter(Boolean) + .map((line) => JSON.parse(line)) + : []; + const gh = readLog(ghLog); + return { + ran, + outputs, + log, + gh, + prCreates: gh.filter(([command, sub]) => command === 'pr' && sub === 'create'), + stickies: readLog(stickyLog), + }; +} + +// GitHub's expression syntax, limited to the forms this job uses; anything else fails the test +// rather than being guessed at. +function expand(text, outputs) { + return text.replace(/\$\{\{\s*(.+?)\s*\}\}/g, (_, expression) => { + const output = /^steps\.pick\.outputs\.(\w+)$/.exec(expression); + if (output) return outputs[output[1]] ?? ''; + if (expression === 'matrix.release') return RELEASE; + if (expression === 'secrets.GITHUB_TOKEN') return 'test-token'; + throw new Error(`unsupported expression: ${expression}`); + }); +} + +function stepCondition(condition, outputs, failed) { + if (condition === undefined) return !failed; + let checksStatus = false; + let result = true; + for (const term of condition.split('&&').map((part) => part.trim())) { + if (term === 'failure()') { + checksStatus = true; + result &&= failed; + continue; + } + const comparison = /^steps\.pick\.outputs\.(\w+) (==|!=) '([^']*)'$/.exec(term); + if (!comparison) throw new Error(`unsupported if: ${condition}`); + const value = outputs[comparison[1]] ?? ''; + result &&= comparison[2] === '==' ? value === comparison[3] : value !== comparison[3]; + } + return checksStatus ? result : result && !failed; +} + +function readOutputs(file) { + const outputs = {}; + const lines = readFileSync(file, 'utf8').split('\n'); + for (let index = 0; index < lines.length; index++) { + const heredoc = /^(\w+)<<(.+)$/.exec(lines[index]); + if (heredoc) { + const end = lines.indexOf(heredoc[2], index + 1); + outputs[heredoc[1]] = lines.slice(index + 1, end).join('\n'); + index = end; + continue; + } + const separator = lines[index].indexOf('='); + if (separator > 0) outputs[lines[index].slice(0, separator)] = lines[index].slice(separator + 1); + } + return outputs; +} + +function writeStub(path, source) { + writeFileSync(path, `#!/usr/bin/env node\n${source}`); + chmodSync(path, 0o755); +} From a2b64156aea2154a22002e81339cbf78cffe3c50 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 17:23:20 -0600 Subject: [PATCH 02/15] Narrow the landed-change contract to Git's merge rules, and harden the fixture Say what change-landed.sh decides: one pick of the net change would be empty under the same merge rules the picks run under, not verbatim presence. Pin the merge-commit route's re-run no-op, fail the fixture on an unterminated step output instead of looping, and guard teardown. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 2 +- .github/scripts/change-landed.sh | 11 ++++------- .github/workflows/cherry-pick-patch.yml | 13 +++++-------- unitTests/github/cherryPickPatch.test.mjs | 17 +++++++++++++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index efee22073c..084ac6d0b4 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -30,6 +30,6 @@ Write a fixture's rows in one transaction and await a write only before the step ## A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`) -Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether one pick of the PR's whole net change onto the release branch would come out empty: `git merge-tree` of that change, with its own base as the merge base, is clean and leaves the release tree unchanged. Only that answer skips the PR, with no branch and no PR. A change that is partly present, reverted, or conflicting picks as before, and so does a check that cannot run. This is the empty-pick test `scripts/apply-picks.sh` already applies to each commit, lifted to the net change. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. +Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether one pick of the PR's whole net change onto the release branch would come out empty: `git merge-tree` of that change, with its own base as the merge base, is clean and leaves the release tree unchanged. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, or conflicting picks as before, and so does a check that cannot run. "Empty" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. This is the empty-pick test `scripts/apply-picks.sh` already applies to each commit, lifted to the net change. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. The net change is `MERGE_BASE..HEAD_SHA` when the job replays the PR's commits, which includes any merge-commit resolutions; a contained change therefore also clears that hold. It is `MERGE_SHA^1..MERGE_SHA` for a PR merged with a merge commit. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 19dfa63da9..14c2957d0c 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -1,12 +1,9 @@ #!/usr/bin/env bash -# Report whether a branch already contains a change. -# # Usage: change-landed.sh -# Exits 0 when merging .. into (three-way, as the -# merge base) is clean and leaves 's tree unchanged: every hunk of the -# change is already there verbatim. Exits 1 otherwise — a change that is only -# partly present, was reverted, or conflicts — and 2, with a warning, when the -# check cannot run. Only 0 means "skip"; the caller picks on anything else. +# Exits 0 only when one pick of .. onto would come out +# empty under Git's merge rules: merge-tree with as the merge base is +# clean and leaves 's tree unchanged. 1 means it would change , +# 2 that the check could not run. Callers pick on anything but 0. set -u TARGET="$1" diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index d98047ee15..fdb3ed209f 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -337,11 +337,10 @@ jobs: if [ "$IS_MERGED" = "true" ]; then # Nothing replayable: the PR's own content exists only in # commits that cannot be replayed. The merge SHA gives a human - # something to review, but it is not provably the whole change. + # something to review, but it is not provably the whole change, + # so it cannot prove the whole change landed either. PICK_SHAS="$MERGE_SHA" HOLD="the PR has no replayable non-merge commits, so this branch was built from the merge commit alone" - # Not provably the whole change, so it cannot prove the whole - # change landed either. CHANGE_HEAD="" elif [ -n "$EXCLUDED_MERGES" ]; then echo "pushed=false" >> "$GITHUB_OUTPUT" @@ -364,11 +363,9 @@ jobs: # ── Skip a change the release branch already has ──────────────── # - # Replaying it re-applies each intermediate commit against its own - # final content, which conflicts. Skip only when one pick of the whole - # net change would come out empty — the test apply-picks.sh applies to - # each commit — and pick on anything else, including a check that - # could not run. + # Replaying it commit by commit conflicts: each intermediate commit + # meets its own final content. One pick of the whole net change comes + # out empty instead, the test apply-picks.sh applies to each commit. if [ -n "$CHANGE_HEAD" ] && "$RUNNER_TEMP/change-landed.sh" "origin/$RELEASE_BRANCH" "$CHANGE_BASE" "$CHANGE_HEAD"; then echo "The change from PR #$PR_NUMBER is already on $RELEASE_BRANCH — nothing to pick" echo "no_op=true" >> "$GITHUB_OUTPUT" diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index d11a1c8356..73928e3fb4 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -27,7 +27,8 @@ describe('cherry-pick-patch.yml', function () { }); afterEach(function () { - rmSync(fixture.dir, { recursive: true, force: true }); + if (fixture) rmSync(fixture.dir, { recursive: true, force: true }); + fixture = undefined; }); function incidentPr() { @@ -90,13 +91,17 @@ describe('cherry-pick-patch.yml', function () { assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); }); - it('lands a change merged with a merge commit, whose PR head is already on main', function () { + it('lands a change merged with a merge commit, whose PR head is already on main, then skips it', function () { fixture.prCommit(FIRST_FIX, 'First fix'); fixture.prCommit(SECOND_FIX, 'Second fix'); fixture.mergeCommit(); const run = fixture.runJob(); assert.strictEqual(run.outputs.pick_flags, '-m 1', run.log); assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); + const landedTip = fixture.releaseTip(); + const rerun = fixture.runJob(); + assert.strictEqual(rerun.outputs.no_op, 'true', rerun.log); + assert.strictEqual(fixture.releaseTip(), landedTip); }); it('still opens the conflict PR when the release branch changed the same lines differently', function () { @@ -119,7 +124,9 @@ describe('cherry-pick-patch.yml', function () { fixture.runJob(); const run = fixture.runJob({ afterStash(temp) { - writeFileSync(join(temp, 'change-landed.sh'), '#!/usr/bin/env bash\necho "::warning::check failed"\nexit 2\n'); + const stub = join(temp, 'change-landed.sh'); + writeFileSync(stub, '#!/usr/bin/env bash\necho "::warning::check failed"\nexit 2\n'); + chmodSync(stub, 0o755); }, }); assert.match(run.log, /::warning::check failed/); @@ -196,7 +203,8 @@ describe('change-landed.sh', function () { }); afterEach(function () { - rmSync(dir, { recursive: true, force: true }); + if (dir) rmSync(dir, { recursive: true, force: true }); + dir = undefined; }); const changes = { @@ -502,6 +510,7 @@ function readOutputs(file) { const heredoc = /^(\w+)<<(.+)$/.exec(lines[index]); if (heredoc) { const end = lines.indexOf(heredoc[2], index + 1); + if (end < 0) throw new Error(`output ${heredoc[1]} has no closing ${heredoc[2]}`); outputs[heredoc[1]] = lines.slice(index + 1, end).join('\n'); index = end; continue; From 46594a5efa13b4957c6ca357557a6bf737ba9527 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 17:32:44 -0600 Subject: [PATCH 03/15] Pin the merge-commit re-run skip to the containment check The lone -m 1 pick of an already-landed merge commit also comes out empty, so the re-run asserted no_op even with the check removed. Assert the check's own skip line and that no pick was planned. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- unitTests/github/cherryPickPatch.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 73928e3fb4..543040e231 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -100,7 +100,9 @@ describe('cherry-pick-patch.yml', function () { assert.strictEqual(fixture.releaseFile(), fixture.lines(SECOND_FIX), run.log); const landedTip = fixture.releaseTip(); const rerun = fixture.runJob(); - assert.strictEqual(rerun.outputs.no_op, 'true', rerun.log); + // The lone `-m 1` pick would also come out empty; the skip must come from the containment check. + assert.match(rerun.log, /already on v5\.3 — nothing to pick/); + assert.strictEqual(rerun.outputs.pick_flags, undefined, rerun.log); assert.strictEqual(fixture.releaseTip(), landedTip); }); From 22da9521d51668a9b0cdaf523bc97d46b20b7b0e Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 17:44:49 -0600 Subject: [PATCH 04/15] Exit explicitly from every branch of change-landed.sh The landed branch returned its test's status implicitly, so a command appended after the case would have turned every result into exit 0, the one answer that skips a pick. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/scripts/change-landed.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 14c2957d0c..51224df4b2 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -12,7 +12,10 @@ HEAD="$3" MERGED=$(git merge-tree --write-tree --merge-base="$BASE" "$TARGET" "$HEAD") case $? in - 0) [ "$MERGED" = "$(git rev-parse "$TARGET^{tree}")" ] ;; + 0) + [ "$MERGED" = "$(git rev-parse "$TARGET^{tree}")" ] && exit 0 + exit 1 + ;; 1) exit 1 ;; *) echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD, so it will be picked" From 58471f85d6ec967da9c9072a460dfb093e109f34 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 18:03:20 -0600 Subject: [PATCH 05/15] Require the picked commits, not just the net change, to be on the release The net change since the live merge base drops any of the PR's content that main absorbed from another PR before this one merged main. A release that had the rest of the change then read as landed, and the skip withheld commits the per-commit replay would have landed. change-landed.sh now also replays the picks onto the first one's parent and requires that change to merge into the release without changing it too. The net change still guards merge resolutions no commit carries. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 4 +- .github/scripts/change-landed.sh | 55 +++++++++----- .github/workflows/cherry-pick-patch.yml | 8 +-- DESIGN.md | 2 +- unitTests/github/cherryPickPatch.test.mjs | 87 ++++++++++++++++++----- 5 files changed, 115 insertions(+), 41 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 084ac6d0b4..788b5ac4d1 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -30,6 +30,6 @@ Write a fixture's rows in one transaction and await a write only before the step ## A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`) -Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether one pick of the PR's whole net change onto the release branch would come out empty: `git merge-tree` of that change, with its own base as the merge base, is clean and leaves the release tree unchanged. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, or conflicting picks as before, and so does a check that cannot run. "Empty" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. This is the empty-pick test `scripts/apply-picks.sh` already applies to each commit, lifted to the net change. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. +Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch would change nothing. Two `git merge-tree` merges into the release must each be clean and leave its tree unchanged. One merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), which carries merge resolutions no commit does. The other merges the picked commits, replayed in order onto the first one's parent, which carries content main absorbed from another PR and so dropped out of the net change. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed, or conflicting picks as before, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -The net change is `MERGE_BASE..HEAD_SHA` when the job replays the PR's commits, which includes any merge-commit resolutions; a contained change therefore also clears that hold. It is `MERGE_SHA^1..MERGE_SHA` for a PR merged with a merge commit. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. +When both merges change nothing, the excluded-merge hold is cleared too, since the resolutions are in the net change. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 51224df4b2..be1bfaf081 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -1,24 +1,45 @@ #!/usr/bin/env bash -# Usage: change-landed.sh -# Exits 0 only when one pick of .. onto would come out -# empty under Git's merge rules: merge-tree with as the merge base is -# clean and leaves 's tree unchanged. 1 means it would change , -# 2 that the check could not run. Callers pick on anything but 0. +# Usage: change-landed.sh ... +# Exits 0 only when picking the commits onto would leave it unchanged +# under Git's merge rules. Two merges into must each be clean and +# leave its tree as it was: the net change .., which carries merge +# resolutions no commit does, and the commits replayed in order onto the first +# one's parent, which carries content main absorbed out of ... +# 1 means not landed, 2 that the check could not run; callers pick on either. set -u TARGET="$1" BASE="$2" HEAD="$3" +shift 3 -MERGED=$(git merge-tree --write-tree --merge-base="$BASE" "$TARGET" "$HEAD") -case $? in - 0) - [ "$MERGED" = "$(git rev-parse "$TARGET^{tree}")" ] && exit 0 - exit 1 - ;; - 1) exit 1 ;; - *) - echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD, so it will be picked" - exit 2 - ;; -esac +could_not_run() { + echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD, so it will be picked" + exit 2 +} + +# Exits 1 unless merging .. into TARGET is clean and changes nothing. +require_landed() { + local merged status + merged=$(git merge-tree --write-tree --merge-base="$1" "$TARGET" "$2") + status=$? + [ "$status" -gt 1 ] && could_not_run + [ "$status" -eq 0 ] && [ "${merged%%$'\n'*}" = "$(git rev-parse "$TARGET^{tree}")" ] || exit 1 +} + +[ "$#" -gt 0 ] || could_not_run +require_landed "$BASE" "$HEAD" + +FROM="$1^1" +PICKED="$1" +shift +for COMMIT in "$@"; do + PICKED=$(git merge-tree --write-tree --merge-base="$COMMIT^1" "$PICKED" "$COMMIT") + case $? in + 0) ;; + 1) exit 1 ;; + *) could_not_run ;; + esac +done +require_landed "$FROM" "$PICKED" +exit 0 diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index fdb3ed209f..6f5aa5993b 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -363,10 +363,10 @@ jobs: # ── Skip a change the release branch already has ──────────────── # - # Replaying it commit by commit conflicts: each intermediate commit - # meets its own final content. One pick of the whole net change comes - # out empty instead, the test apply-picks.sh applies to each commit. - if [ -n "$CHANGE_HEAD" ] && "$RUNNER_TEMP/change-landed.sh" "origin/$RELEASE_BRANCH" "$CHANGE_BASE" "$CHANGE_HEAD"; then + # Replaying a landed change commit by commit conflicts: each + # intermediate commit meets its own final content. + # shellcheck disable=SC2086 + if [ -n "$CHANGE_HEAD" ] && "$RUNNER_TEMP/change-landed.sh" "origin/$RELEASE_BRANCH" "$CHANGE_BASE" "$CHANGE_HEAD" $PICK_SHAS; then echo "The change from PR #$PR_NUMBER is already on $RELEASE_BRANCH — nothing to pick" echo "no_op=true" >> "$GITHUB_OUTPUT" exit 0 diff --git a/DESIGN.md b/DESIGN.md index f5cf0aa14e..d8908234e4 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -15,7 +15,7 @@ Index of the design notes for the harper core: one line per note, grouped by the - [The lock file must pass `npm ci` under npm 10 and npm 11 (`workflows/lockfile-npm-compat.yml`)](.github/DESIGN.md#the-lock-file-must-pass-npm-ci-under-npm-10-and-npm-11-workflowslockfile-npm-compatyml) — npm 11 writes the lock but accepts some that npm 10's `npm ci` rejects; fix the conflict at its source, never by regenerating with npm 10. - [A release copies to Docker Hub only the image it booted (`workflows/docker-smoke.yml`, `workflows/publish-docker.yaml`)](.github/DESIGN.md#a-release-copies-to-docker-hub-only-the-image-it-booted-workflowsdocker-smokeyml-workflowspublish-dockeryaml) — The release builds once into a runner-local registry, smoke-tests that digest and copies the same index to Docker Hub; never a rebuild. - [Unit-test fixtures don't spend `Unit tests: lmdb` on one durable commit per row (`workflows/unit-test.yml`)](.github/DESIGN.md#unit-test-fixtures-dont-spend-unit-tests-lmdb-on-one-durable-commit-per-row-workflowsunit-testyml) — Every resources suite re-runs on LMDB, where each awaited commit syncs; fixtures batch their writes, and the step cap is the only detector. -- [A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`)](.github/DESIGN.md#a-release-cherry-pick-skips-a-change-its-branch-already-has-workflowscherry-pick-patchyml-scriptschange-landedsh) — skip only when one pick of the PR's whole net change would be empty; replaying a landed PR commit by commit conflicts instead. +- [A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`)](.github/DESIGN.md#a-release-cherry-pick-skips-a-change-its-branch-already-has-workflowscherry-pick-patchyml-scriptschange-landedsh) — skip only when the PR's net change and its replayed commits both merge into the release without changing it; replaying a landed PR commit by commit conflicts instead. ## resources/ — records, transactions, tables, blobs, audit diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 543040e231..43d369f7cb 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -14,14 +14,26 @@ const changeLanded = join(root, '.github/scripts/change-landed.sh'); const RELEASE = 'v5.3'; const PR_NUMBER = '7'; const DEADLINE = 60_000; -// #3038's shape: the second commit rewrites the line the first one changed, so replaying the first -// onto a release that already has both conflicts instead of applying empty. +// change-landed.sh merges trees with an explicit merge base, which git supports from 2.45. +const GIT_HAS_TREE_MERGE = (() => { + const [major, minor] = /(\d+)\.(\d+)/ + .exec(execFileSync('git', ['--version'], { encoding: 'utf8' })) + .slice(1) + .map(Number); + return major > 2 || (major === 2 && minor >= 45); +})(); +// The second commit rewrites the line the first one changed, so replaying the first onto a release +// that already has both conflicts instead of applying empty. const FIRST_FIX = { 5: 'first fix' }; const SECOND_FIX = { 5: 'second fix', 6: 'second fix, continued' }; describe('cherry-pick-patch.yml', function () { let fixture; + before(function () { + if (!GIT_HAS_TREE_MERGE) this.skip(); + }); + beforeEach(function () { fixture = createFixture(); }); @@ -47,8 +59,8 @@ describe('cherry-pick-patch.yml', function () { }); it('makes a second run for a landed change a no-op, and closes the conflict PR an earlier run left', function () { - // #3067: one milestone change fires `demilestoned` and `milestoned`; the first run landed - // the PR's commits and the second re-picked them onto the advanced release tip. + // One milestone change fires `demilestoned` and `milestoned`: the first run lands the PR's + // commits and the second replays them onto the release tip the first one advanced. incidentPr(); fixture.runJob(); const landedTip = fixture.releaseTip(); @@ -136,6 +148,24 @@ describe('cherry-pick-patch.yml', function () { assert.notStrictEqual(run.outputs.conflicts, '', run.log); }); + it('picks a commit whose content main absorbed from another PR before this one merged main', function () { + // After the merge of main, the net change since the merge base is only the second commit, and + // the release already has that much. + const PR_ONLY = { 20: 'pr-only change' }; + fixture.prCommit(FIRST_FIX, 'First fix'); + fixture.prCommit(PR_ONLY, 'PR-only change'); + fixture.mainCommit(FIRST_FIX, 'The same fix, landed on main by another PR'); + fixture.mergeMainIntoPr(); + fixture.squashMerge(); + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines(PR_ONLY)); + git('commit', '-qam', 'Backport the PR-only change'); + }); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines({ ...FIRST_FIX, ...PR_ONLY }), run.log); + }); + it('holds a lone fallback merge commit even when the release branch has that commit', function () { // The PR head reached main directly, so the API's merge SHA is just its last commit. The // release has that commit but not the one before it; only a human can tell it is incomplete. @@ -152,20 +182,20 @@ describe('cherry-pick-patch.yml', function () { assert.match(run.stickies.at(-1), /held for review/); }); - describe('a PR whose merge of main resolved content of its own', function () { - const RESOLVED = { 5: 'resolved' }; + describe('a PR whose merge of main added content of its own', function () { + const IN_MERGE = { 12: 'added in the merge' }; beforeEach(function () { fixture.prCommit(FIRST_FIX, 'First fix'); - fixture.mainCommit({ 5: 'main edit' }, 'Main edit'); - fixture.mergeMainIntoPr(RESOLVED); + fixture.mainCommit({ 30: 'main edit' }, 'Main edit'); + fixture.mergeMainIntoPr(IN_MERGE); fixture.squashMerge(); }); - it('is a no-op when its whole net change, resolution included, is on the release branch', function () { + it('is a no-op when its commits and its merge content are both on the release branch', function () { fixture.onRelease((git) => { - fixture.writeLib(fixture.lines(RESOLVED)); - git('commit', '-qam', 'Backport the resolved change'); + fixture.writeLib(fixture.lines({ ...FIRST_FIX, ...IN_MERGE })); + git('commit', '-qam', 'Backport the whole change'); }); const run = fixture.runJob(); assert.strictEqual(run.outputs.no_op, 'true', run.log); @@ -186,8 +216,17 @@ describe('change-landed.sh', function () { let dir; let env; const git = (...args) => execFileSync('git', args, { cwd: dir, env, encoding: 'utf8', timeout: DEADLINE }).trim(); - const landed = (target, base, head) => - spawnSync('bash', [changeLanded, target, base, head], { cwd: dir, env, encoding: 'utf8', timeout: DEADLINE }); + const landed = (target, base, head, commits = [head]) => + spawnSync('bash', [changeLanded, target, base, head, ...commits], { + cwd: dir, + env, + encoding: 'utf8', + timeout: DEADLINE, + }); + + before(function () { + if (!GIT_HAS_TREE_MERGE) this.skip(); + }); beforeEach(function () { dir = mkdtempSync(join(tmpdir(), 'change-landed-')); @@ -243,6 +282,19 @@ describe('change-landed.sh', function () { }); } + it('does not take an empty net change as proof that its commits landed', function () { + const base = git('rev-parse', 'HEAD'); + changes['a new file'](); + git('commit', '-qm', 'New file'); + const commit = git('rev-parse', 'HEAD'); + git('checkout', '-qb', 'target', base); + const without = landed('target', commit, commit, [commit]); + assert.strictEqual(without.status, 1, without.stdout + without.stderr); + git('cherry-pick', commit); + const withCommit = landed('target', commit, commit, [commit]); + assert.strictEqual(withCommit.status, 0, withCommit.stdout + withCommit.stderr); + }); + it('reports a check that cannot run with a warning and exit 2', function () { const result = landed('refs/heads/no-such-branch', 'HEAD', 'HEAD'); assert.strictEqual(result.status, 2, result.stderr); @@ -363,12 +415,13 @@ if (command === 'api' && /^repos\\/[^/]+\\/[^/]+\\/pulls\\/\\d+$/.test(sub) && a mainState = { ...mainState, ...overrides }; commitLib(mainState, message); }, - mergeMainIntoPr(resolution) { - featureState = { ...mainState, ...resolution }; + // Records the merge with `extra` edited in by hand, the way an author's own resolution would be. + mergeMainIntoPr(extra = {}) { + featureState = { ...featureState, ...mainState, ...extra }; onBranch('feature', () => { - spawnSync('git', ['merge', '-q', 'main'], { cwd: seed, env, timeout: DEADLINE }); + spawnSync('git', ['merge', '-q', '--no-commit', '--no-ff', 'main'], { cwd: seed, env, timeout: DEADLINE }); writeLib(lines(featureState)); - seedGit('commit', '-qam', 'Merge main, resolving the conflict by hand'); + seedGit('commit', '-qam', 'Merge main'); }); }, squashMerge() { From 0374e2a9bd88816c9624611d2970a9105d1dbf6e Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 18:14:39 -0600 Subject: [PATCH 06/15] Fail the cherry-pick suites in CI on a git too old to run the check They skip below git 2.45 so a developer's older git does not fail test:unit:main, but under CI a skip would hide the guard going untested. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- unitTests/github/cherryPickPatch.test.mjs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 43d369f7cb..af04493557 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -22,6 +22,12 @@ const GIT_HAS_TREE_MERGE = (() => { .map(Number); return major > 2 || (major === 2 && minor >= 45); })(); +// CI must exercise the guard; a developer's older git only skips it. +function requireTreeMerge() { + if (GIT_HAS_TREE_MERGE) return; + if (process.env.CI) throw new Error('change-landed.sh needs git 2.45 or newer'); + this.skip(); +} // The second commit rewrites the line the first one changed, so replaying the first onto a release // that already has both conflicts instead of applying empty. const FIRST_FIX = { 5: 'first fix' }; @@ -30,9 +36,7 @@ const SECOND_FIX = { 5: 'second fix', 6: 'second fix, continued' }; describe('cherry-pick-patch.yml', function () { let fixture; - before(function () { - if (!GIT_HAS_TREE_MERGE) this.skip(); - }); + before(requireTreeMerge); beforeEach(function () { fixture = createFixture(); @@ -224,9 +228,7 @@ describe('change-landed.sh', function () { timeout: DEADLINE, }); - before(function () { - if (!GIT_HAS_TREE_MERGE) this.skip(); - }); + before(requireTreeMerge); beforeEach(function () { dir = mkdtempSync(join(tmpdir(), 'change-landed-')); From e779ffb3a2dd2842e223530736f800ff6f2f630d Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 18:28:24 -0600 Subject: [PATCH 07/15] Keep the hold when an excluded merge's PR reads as already landed A merge of main that resolved a conflict by taking main's side discards the PR's own edit and leaves nothing in the net change, so "already on the release" cannot vouch for it. Report such a run held, with no branch or PR, instead of clearing the hold. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 2 +- .github/scripts/change-landed.sh | 1 - .github/workflows/cherry-pick-patch.yml | 14 ++++++++++---- unitTests/github/cherryPickPatch.test.mjs | 22 ++++++++++++++++++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 788b5ac4d1..455dcff0f0 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -32,4 +32,4 @@ Write a fixture's rows in one transaction and await a write only before the step Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch would change nothing. Two `git merge-tree` merges into the release must each be clean and leave its tree unchanged. One merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), which carries merge resolutions no commit does. The other merges the picked commits, replayed in order onto the first one's parent, which carries content main absorbed from another PR and so dropped out of the net change. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed, or conflicting picks as before, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -When both merges change nothing, the excluded-merge hold is cleared too, since the resolutions are in the net change. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. +A hold is never cleared. When both merges change nothing but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index be1bfaf081..953646d283 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -18,7 +18,6 @@ could_not_run() { exit 2 } -# Exits 1 unless merging .. into TARGET is clean and changes nothing. require_landed() { local merged status merged=$(git merge-tree --write-tree --merge-base="$1" "$TARGET" "$2") diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index 6f5aa5993b..ee19e5d66b 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -358,25 +358,31 @@ jobs: fi fi + if [ -n "$EXCLUDED_MERGES" ]; then + HOLD=$(printf 'merge commit(s) `%s` resolved content of their own and cannot be replayed' "$EXCLUDED_MERGES") + fi + # ── Create / reset cherry-pick branch off release branch ──────── git checkout -B "$BRANCH" "origin/$RELEASE_BRANCH" # ── Skip a change the release branch already has ──────────────── # # Replaying a landed change commit by commit conflicts: each - # intermediate commit meets its own final content. + # intermediate commit meets its own final content. A hold still + # stands: a resolution that took one side outright leaves nothing in + # the net change for the check to find. # shellcheck disable=SC2086 if [ -n "$CHANGE_HEAD" ] && "$RUNNER_TEMP/change-landed.sh" "origin/$RELEASE_BRANCH" "$CHANGE_BASE" "$CHANGE_HEAD" $PICK_SHAS; then echo "The change from PR #$PR_NUMBER is already on $RELEASE_BRANCH — nothing to pick" + if [ -n "$HOLD" ]; then + echo "hold=its change appears to be on it already, but $HOLD" >> "$GITHUB_OUTPUT" + fi echo "no_op=true" >> "$GITHUB_OUTPUT" exit 0 fi echo "pick_flags=$PICK_FLAGS" >> "$GITHUB_OUTPUT" echo "pick_shas=$PICK_SHAS" >> "$GITHUB_OUTPUT" - if [ -n "$EXCLUDED_MERGES" ]; then - HOLD=$(printf 'merge commit(s) `%s` resolved content of their own and cannot be replayed' "$EXCLUDED_MERGES") - fi echo "excluded_merges=$EXCLUDED_MERGES" >> "$GITHUB_OUTPUT" echo "hold=$HOLD" >> "$GITHUB_OUTPUT" diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index af04493557..1446589d14 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -186,6 +186,19 @@ describe('cherry-pick-patch.yml', function () { assert.match(run.stickies.at(-1), /held for review/); }); + it('stays held when its merge of main discarded its own edit, even if the release has that edit', function () { + const PR_ONLY = { 20: 'pr-only change' }; + fixture.prCommit({ 5: 'pr side', ...PR_ONLY }, 'PR change'); + fixture.mainCommit({ 5: 'main side' }, 'Main change to the same line'); + fixture.mergeMainIntoPr(); + fixture.squashMerge(); + fixture.onRelease((git) => git('cherry-pick', fixture.prCommits[0])); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.hold ?? '', '', run.log); + assert.ok(run.ran.includes('Report held for review') && !run.ran.includes('Report no-op'), run.log); + assert.deepStrictEqual(run.prCreates, []); + }); + describe('a PR whose merge of main added content of its own', function () { const IN_MERGE = { 12: 'added in the merge' }; @@ -196,15 +209,20 @@ describe('cherry-pick-patch.yml', function () { fixture.squashMerge(); }); - it('is a no-op when its commits and its merge content are both on the release branch', function () { + it('stays held, with no branch or PR, when its change is already on the release branch', function () { + // A merge that took one side outright would leave nothing in the net change to check, so + // "landed" cannot clear the hold. fixture.onRelease((git) => { fixture.writeLib(fixture.lines({ ...FIRST_FIX, ...IN_MERGE })); git('commit', '-qam', 'Backport the whole change'); }); const run = fixture.runJob(); assert.strictEqual(run.outputs.no_op, 'true', run.log); - assert.ok(run.ran.includes('Report no-op'), run.log); + assert.match(run.outputs.hold, /^its change appears to be on it already, but merge commit/); + assert.ok(run.ran.includes('Report held for review') && !run.ran.includes('Report no-op'), run.log); assert.deepStrictEqual(run.prCreates, []); + assert.deepStrictEqual(fixture.cherryPickBranches(), []); + assert.match(run.stickies.at(-1), /held for review/); }); it('is held for review when the release branch lacks it', function () { From 852c07d9c69bad52ce1e9c7f08c4cfec82c83296 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 18:46:06 -0600 Subject: [PATCH 08/15] Refuse to skip when any picked commit alone would change the release A PR whose later commit undoes an earlier one has no trace of either in its net change, so a release holding the earlier commit read as landed while picking would have undone it. change-landed.sh now also merges each commit alone into the release: a clean merge that changes it means not landed. A skip then happens only where the commit-by-commit replay would have changed nothing or stopped on a conflict. Also word the no-branch held report for a change that may already be present. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 2 +- .github/scripts/change-landed.sh | 34 ++++++++++++++++------- .github/workflows/cherry-pick-patch.yml | 4 +-- unitTests/github/cherryPickPatch.test.mjs | 16 ++++++++++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 455dcff0f0..71ab0acf72 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -30,6 +30,6 @@ Write a fixture's rows in one transaction and await a write only before the step ## A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`) -Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch would change nothing. Two `git merge-tree` merges into the release must each be clean and leave its tree unchanged. One merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), which carries merge resolutions no commit does. The other merges the picked commits, replayed in order onto the first one's parent, which carries content main absorbed from another PR and so dropped out of the net change. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed, or conflicting picks as before, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. +Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. No picked commit, merged alone into the release, may apply cleanly and change it; so a skip happens only where the commit-by-commit replay would have changed nothing or stopped on a conflict. Two more `git merge-tree` merges into the release must each be clean and leave its tree unchanged, which is what separates a conflict with landed content from a real one. One merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), which carries merge resolutions no commit does. The other merges the picked commits, replayed in order onto the first one's parent, which carries content main absorbed from another PR and so dropped out of the net change. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed, undone by a later commit of its own, or conflicting picks as before, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. A hold is never cleared. When both merges change nothing but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 953646d283..afffe37df3 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash # Usage: change-landed.sh ... -# Exits 0 only when picking the commits onto would leave it unchanged -# under Git's merge rules. Two merges into must each be clean and -# leave its tree as it was: the net change .., which carries merge -# resolutions no commit does, and the commits replayed in order onto the first -# one's parent, which carries content main absorbed out of ... -# 1 means not landed, 2 that the check could not run; callers pick on either. +# Exits 0 only when picking the commits onto could land nothing new, +# under Git's merge rules: +# - no commit, picked alone onto , applies cleanly and changes it; +# - the net change .., which carries merge resolutions no commit +# does, merges into cleanly without changing it; +# - so do the commits replayed in order onto the first one's parent, which +# carry content main absorbed out of ... +# A commit that conflicts alone is taken as superseded by later ones only +# because the last two hold. 1 means not landed, 2 that the check could not +# run; callers pick on either. set -u TARGET="$1" @@ -18,16 +22,26 @@ could_not_run() { exit 2 } -require_landed() { +# 0: clean and leaves TARGET unchanged; 1: conflicts; 3: clean but changes it. +merge_into_target() { local merged status merged=$(git merge-tree --write-tree --merge-base="$1" "$TARGET" "$2") status=$? [ "$status" -gt 1 ] && could_not_run - [ "$status" -eq 0 ] && [ "${merged%%$'\n'*}" = "$(git rev-parse "$TARGET^{tree}")" ] || exit 1 + [ "$status" -eq 1 ] && return 1 + [ "${merged%%$'\n'*}" = "$TARGET_TREE" ] && return 0 + return 3 } [ "$#" -gt 0 ] || could_not_run -require_landed "$BASE" "$HEAD" +TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run + +for COMMIT in "$@"; do + merge_into_target "$COMMIT^1" "$COMMIT" + [ "$?" -eq 3 ] && exit 1 +done + +merge_into_target "$BASE" "$HEAD" || exit 1 FROM="$1^1" PICKED="$1" @@ -40,5 +54,5 @@ for COMMIT in "$@"; do *) could_not_run ;; esac done -require_landed "$FROM" "$PICKED" +merge_into_target "$FROM" "$PICKED" || exit 1 exit 0 diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index ee19e5d66b..2e837d41ea 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -512,10 +512,10 @@ jobs: --base "$RELEASE_BRANCH" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || true) if [ -n "$STALE_PR" ] && [ "$STALE_PR" != "null" ]; then gh pr close "$STALE_PR" --repo "$GITHUB_REPOSITORY" \ - --comment "Superseded: PR #${PR_NUMBER} no longer produces any commits to cherry-pick onto \`${RELEASE_BRANCH}\`." >/dev/null || true + --comment "Superseded: PR #${PR_NUMBER} has nothing left to cherry-pick onto \`${RELEASE_BRANCH}\`." >/dev/null || true fi git push origin --delete "$BRANCH" 2>/dev/null || true - BODY=$(printf '%s\n## Release cherry-pick `%s`: held for review\n\nNothing could be cherry-picked onto `%s`: %s.\n\n`%s` was **not** updated. Apply this change by hand if it belongs on that line.\n' \ + BODY=$(printf '%s\n## Release cherry-pick `%s`: held for review\n\nNothing could be cherry-picked onto `%s`: %s.\n\n`%s` was **not** updated. Check it, and apply this change by hand if any of it is missing and belongs on that line.\n' \ "$STICKY_MARKER" "$RELEASE_BRANCH" "$RELEASE_BRANCH" "$HOLD" "$RELEASE_BRANCH") node "$RUNNER_TEMP/upsert-sticky-comment.js" "$PR_NUMBER" "$STICKY_MARKER" "$BODY" exit 0 diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 1446589d14..59f86becfc 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -22,7 +22,6 @@ const GIT_HAS_TREE_MERGE = (() => { .map(Number); return major > 2 || (major === 2 && minor >= 45); })(); -// CI must exercise the guard; a developer's older git only skips it. function requireTreeMerge() { if (GIT_HAS_TREE_MERGE) return; if (process.env.CI) throw new Error('change-landed.sh needs git 2.45 or newer'); @@ -186,6 +185,21 @@ describe('cherry-pick-patch.yml', function () { assert.match(run.stickies.at(-1), /held for review/); }); + it('picks a later commit that undoes an earlier one the release branch already has', function () { + // The net change never mentions line 10, but the release holds the first commit's edit to it. + const FINAL = { 20: 'final' }; + fixture.prCommit({ 10: 'temporary' }, 'Temporary change'); + fixture.prCommit({ 10: 'line 10', ...FINAL }, 'Undo it and finish'); + fixture.squashMerge(); + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines({ 10: 'temporary', ...FINAL })); + git('commit', '-qam', 'Backport the first commit and the final line'); + }); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.strictEqual(fixture.releaseFile(), fixture.lines(FINAL), run.log); + }); + it('stays held when its merge of main discarded its own edit, even if the release has that edit', function () { const PR_ONLY = { 20: 'pr-only change' }; fixture.prCommit({ 5: 'pr side', ...PR_ONLY }, 'PR change'); From e3521181215775c49aa9ba3edcf9d11da47a5b07 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 18:57:44 -0600 Subject: [PATCH 09/15] Decide "landed" by replaying the picks onto the release A release holding its own version of a commit the PR later undoes made both of that PR's commits conflict, and the net-change merges never see the undone line, so the change read as landed. Replace the per-commit and replay-from-parent merges with one replay of the picks onto the release, each conflict resolved toward the commit: the change has landed only if that ends at the release's own tree. The net-change merge stays for merge resolutions no commit carries. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 4 +- .github/scripts/change-landed.sh | 54 ++++++++--------------- DESIGN.md | 2 +- unitTests/github/cherryPickPatch.test.mjs | 15 +++++++ 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 71ab0acf72..c396ee4e99 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -30,6 +30,6 @@ Write a fixture's rows in one transaction and await a write only before the step ## A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`) -Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. No picked commit, merged alone into the release, may apply cleanly and change it; so a skip happens only where the commit-by-commit replay would have changed nothing or stopped on a conflict. Two more `git merge-tree` merges into the release must each be clean and leave its tree unchanged, which is what separates a conflict with landed content from a real one. One merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), which carries merge resolutions no commit does. The other merges the picked commits, replayed in order onto the first one's parent, which carries content main absorbed from another PR and so dropped out of the net change. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed, undone by a later commit of its own, or conflicting picks as before, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. +Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. The script replays the picked commits onto the release in order with `git merge-tree`, resolving each conflict toward the commit, and the result must be the release's own tree. A conflict then means only that a commit met content a later commit of the PR already wrote. It also merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), into the release, and that must leave the tree unchanged; this covers merge resolutions that no commit carries. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed by main from another PR, or undone by a later commit of its own picks as before. So does a conflicting change, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -A hold is never cleared. When both merges change nothing but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. +A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index afffe37df3..ee18102761 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -1,15 +1,12 @@ #!/usr/bin/env bash # Usage: change-landed.sh ... -# Exits 0 only when picking the commits onto could land nothing new, -# under Git's merge rules: -# - no commit, picked alone onto , applies cleanly and changes it; -# - the net change .., which carries merge resolutions no commit -# does, merges into cleanly without changing it; -# - so do the commits replayed in order onto the first one's parent, which -# carry content main absorbed out of ... -# A commit that conflicts alone is taken as superseded by later ones only -# because the last two hold. 1 means not landed, 2 that the check could not -# run; callers pick on either. +# Exits 0 only when picking the commits onto would land nothing new, +# under Git's merge rules. Replaying them onto in order, with each +# conflict resolved toward the commit, must end at 's own tree: a +# conflict is then only a commit meeting content a later one already wrote. +# Merging the net change .., which carries merge resolutions no +# commit does, must leave that tree unchanged too. 1 means not landed, 2 that +# the check could not run; callers pick on either. set -u TARGET="$1" @@ -22,37 +19,24 @@ could_not_run() { exit 2 } -# 0: clean and leaves TARGET unchanged; 1: conflicts; 3: clean but changes it. -merge_into_target() { - local merged status - merged=$(git merge-tree --write-tree --merge-base="$1" "$TARGET" "$2") - status=$? - [ "$status" -gt 1 ] && could_not_run - [ "$status" -eq 1 ] && return 1 - [ "${merged%%$'\n'*}" = "$TARGET_TREE" ] && return 0 - return 3 -} - [ "$#" -gt 0 ] || could_not_run TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run +REPLAYED="$TARGET" for COMMIT in "$@"; do - merge_into_target "$COMMIT^1" "$COMMIT" - [ "$?" -eq 3 ] && exit 1 -done - -merge_into_target "$BASE" "$HEAD" || exit 1 - -FROM="$1^1" -PICKED="$1" -shift -for COMMIT in "$@"; do - PICKED=$(git merge-tree --write-tree --merge-base="$COMMIT^1" "$PICKED" "$COMMIT") + REPLAYED=$(git merge-tree --write-tree -X theirs --merge-base="$COMMIT^1" "$REPLAYED" "$COMMIT") case $? in - 0) ;; + 0) REPLAYED="${REPLAYED%%$'\n'*}" ;; 1) exit 1 ;; *) could_not_run ;; esac done -merge_into_target "$FROM" "$PICKED" || exit 1 -exit 0 +[ "$REPLAYED" = "$TARGET_TREE" ] || exit 1 + +MERGED=$(git merge-tree --write-tree --merge-base="$BASE" "$TARGET" "$HEAD") +case $? in + 0) [ "${MERGED%%$'\n'*}" = "$TARGET_TREE" ] && exit 0 ;; + 1) ;; + *) could_not_run ;; +esac +exit 1 diff --git a/DESIGN.md b/DESIGN.md index d8908234e4..388e7f39e5 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -15,7 +15,7 @@ Index of the design notes for the harper core: one line per note, grouped by the - [The lock file must pass `npm ci` under npm 10 and npm 11 (`workflows/lockfile-npm-compat.yml`)](.github/DESIGN.md#the-lock-file-must-pass-npm-ci-under-npm-10-and-npm-11-workflowslockfile-npm-compatyml) — npm 11 writes the lock but accepts some that npm 10's `npm ci` rejects; fix the conflict at its source, never by regenerating with npm 10. - [A release copies to Docker Hub only the image it booted (`workflows/docker-smoke.yml`, `workflows/publish-docker.yaml`)](.github/DESIGN.md#a-release-copies-to-docker-hub-only-the-image-it-booted-workflowsdocker-smokeyml-workflowspublish-dockeryaml) — The release builds once into a runner-local registry, smoke-tests that digest and copies the same index to Docker Hub; never a rebuild. - [Unit-test fixtures don't spend `Unit tests: lmdb` on one durable commit per row (`workflows/unit-test.yml`)](.github/DESIGN.md#unit-test-fixtures-dont-spend-unit-tests-lmdb-on-one-durable-commit-per-row-workflowsunit-testyml) — Every resources suite re-runs on LMDB, where each awaited commit syncs; fixtures batch their writes, and the step cap is the only detector. -- [A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`)](.github/DESIGN.md#a-release-cherry-pick-skips-a-change-its-branch-already-has-workflowscherry-pick-patchyml-scriptschange-landedsh) — skip only when the PR's net change and its replayed commits both merge into the release without changing it; replaying a landed PR commit by commit conflicts instead. +- [A release cherry-pick skips a change its branch already has (`workflows/cherry-pick-patch.yml`, `scripts/change-landed.sh`)](.github/DESIGN.md#a-release-cherry-pick-skips-a-change-its-branch-already-has-workflowscherry-pick-patchyml-scriptschange-landedsh) — skip only when replaying the PR's commits onto the release, conflicts resolved toward each commit, ends at the release's own tree; replaying a landed PR commit by commit conflicts instead. ## resources/ — records, transactions, tables, blobs, audit diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 59f86becfc..639ad8fdd4 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -200,6 +200,21 @@ describe('cherry-pick-patch.yml', function () { assert.strictEqual(fixture.releaseFile(), fixture.lines(FINAL), run.log); }); + it('still opens the conflict PR when the release has its own version of a commit the PR later undoes', function () { + const FINAL = { 20: 'final' }; + fixture.prCommit({ 10: 'temporary' }, 'Temporary change'); + fixture.prCommit({ 10: 'line 10', ...FINAL }, 'Undo it and finish'); + fixture.squashMerge(); + fixture.onRelease((git) => { + fixture.writeLib(fixture.lines({ 10: 'temporary, adapted', ...FINAL })); + git('commit', '-qam', 'Backport an adapted first commit and the final line'); + }); + const run = fixture.runJob(); + assert.notStrictEqual(run.outputs.no_op, 'true', run.log); + assert.notStrictEqual(run.outputs.conflicts, '', run.log); + assert.strictEqual(run.prCreates.length, 1, run.log); + }); + it('stays held when its merge of main discarded its own edit, even if the release has that edit', function () { const PR_ONLY = { 20: 'pr-only change' }; fixture.prCommit({ 5: 'pr side', ...PR_ONLY }, 'PR change'); From 6ffbdfb3218905aa67b11feeea0a5329f62da4f7 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 19:18:33 -0600 Subject: [PATCH 10/15] Give up the landed check when a picked commit changes .gitattributes The replay reads the checked-out .gitattributes for every commit, while the real picks read the copy earlier picks wrote. A PR that switched a path's merge driver partway through could read as landed while its picks would conflict. Exit 2 in that case so the job picks as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/DESIGN.md | 2 +- .github/scripts/change-landed.sh | 13 ++++++------- unitTests/github/cherryPickPatch.test.mjs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index c396ee4e99..0b75df919d 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -32,4 +32,4 @@ Write a fixture's rows in one transaction and await a write only before the step Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. The script replays the picked commits onto the release in order with `git merge-tree`, resolving each conflict toward the commit, and the result must be the release's own tree. A conflict then means only that a commit met content a later commit of the PR already wrote. It also merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), into the release, and that must leave the tree unchanged; this covers merge resolutions that no commit carries. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed by main from another PR, or undone by a later commit of its own picks as before. So does a conflicting change, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the picks. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. +A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the first pick; it gives up, and the job picks, when any picked commit changes a `.gitattributes` file, since later picks would read that copy. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index ee18102761..4c00d2116e 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -1,12 +1,9 @@ #!/usr/bin/env bash # Usage: change-landed.sh ... -# Exits 0 only when picking the commits onto would land nothing new, -# under Git's merge rules. Replaying them onto in order, with each -# conflict resolved toward the commit, must end at 's own tree: a -# conflict is then only a commit meeting content a later one already wrote. -# Merging the net change .., which carries merge resolutions no -# commit does, must leave that tree unchanged too. 1 means not landed, 2 that -# the check could not run; callers pick on either. +# Exits 0 only when picking the commits onto would land nothing new: +# replayed onto it with each conflict resolved toward the commit, they end at +# 's own tree, and so does the net change ... 1 when they +# would land something, 2 when the check cannot tell; callers pick on either. set -u TARGET="$1" @@ -24,6 +21,8 @@ TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run REPLAYED="$TARGET" for COMMIT in "$@"; do + # A real pick reads the .gitattributes earlier picks wrote; merge-tree reads only the checkout's. + git diff-tree --name-only -r "$COMMIT^1" "$COMMIT" | grep -qE '(^|/)\.gitattributes$' && could_not_run REPLAYED=$(git merge-tree --write-tree -X theirs --merge-base="$COMMIT^1" "$REPLAYED" "$COMMIT") case $? in 0) REPLAYED="${REPLAYED%%$'\n'*}" ;; diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 639ad8fdd4..e9230ecddd 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -344,6 +344,19 @@ describe('change-landed.sh', function () { assert.strictEqual(withCommit.status, 0, withCommit.stdout + withCommit.stderr); }); + it('cannot tell when a picked commit changes merge attributes', function () { + const base = git('rev-parse', 'HEAD'); + writeFileSync(join(dir, '.gitattributes'), 'text.txt merge=union\n'); + git('add', '.gitattributes'); + git('commit', '-qm', 'Merge attributes'); + const commit = git('rev-parse', 'HEAD'); + git('checkout', '-qb', 'target', base); + git('cherry-pick', commit); + const result = landed('target', base, commit); + assert.strictEqual(result.status, 2, result.stdout + result.stderr); + assert.match(result.stdout, /^::warning::/m); + }); + it('reports a check that cannot run with a warning and exit 2', function () { const result = landed('refs/heads/no-such-branch', 'HEAD', 'HEAD'); assert.strictEqual(result.status, 2, result.stderr); From 161924c63b6838fa89bef4a21f254a99eb4c041b Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 19:18:50 -0600 Subject: [PATCH 11/15] Drop a test-helper comment that restates its code Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- unitTests/github/cherryPickPatch.test.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index e9230ecddd..4d4b21410c 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -477,7 +477,6 @@ if (command === 'api' && /^repos\\/[^/]+\\/[^/]+\\/pulls\\/\\d+$/.test(sub) && a mainState = { ...mainState, ...overrides }; commitLib(mainState, message); }, - // Records the merge with `extra` edited in by hand, the way an author's own resolution would be. mergeMainIntoPr(extra = {}) { featureState = { ...featureState, ...mainState, ...extra }; onBranch('feature', () => { From 1bf65b5fc948a741e30fb9606b225215d5a8e8c3 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 19:32:37 -0600 Subject: [PATCH 12/15] Match .gitattributes paths NUL-separated, and name why the check gave up git diff-tree quotes a path with non-ASCII bytes, so a nested .gitattributes under such a directory slipped past the guard and the replay ran under attributes the real picks would not use. Read paths with -z. Each give-up warning now says which cause fired. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: harper-cherry-pick-skip-landed --- .github/scripts/change-landed.sh | 13 +++++----- unitTests/github/cherryPickPatch.test.mjs | 29 ++++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 4c00d2116e..9380a51d2a 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -12,22 +12,23 @@ HEAD="$3" shift 3 could_not_run() { - echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD, so it will be picked" + echo "::warning::could not check whether $TARGET already contains $BASE..$HEAD ($1), so it will be picked" exit 2 } -[ "$#" -gt 0 ] || could_not_run -TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run +[ "$#" -gt 0 ] || could_not_run "no commits given" +TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run "$TARGET does not resolve" REPLAYED="$TARGET" for COMMIT in "$@"; do # A real pick reads the .gitattributes earlier picks wrote; merge-tree reads only the checkout's. - git diff-tree --name-only -r "$COMMIT^1" "$COMMIT" | grep -qE '(^|/)\.gitattributes$' && could_not_run + git diff-tree -z --name-only -r "$COMMIT^1" "$COMMIT" | grep -qzE '(^|/)\.gitattributes$' && + could_not_run "$COMMIT changes .gitattributes" REPLAYED=$(git merge-tree --write-tree -X theirs --merge-base="$COMMIT^1" "$REPLAYED" "$COMMIT") case $? in 0) REPLAYED="${REPLAYED%%$'\n'*}" ;; 1) exit 1 ;; - *) could_not_run ;; + *) could_not_run "git merge-tree failed replaying $COMMIT" ;; esac done [ "$REPLAYED" = "$TARGET_TREE" ] || exit 1 @@ -36,6 +37,6 @@ MERGED=$(git merge-tree --write-tree --merge-base="$BASE" "$TARGET" "$HEAD") case $? in 0) [ "${MERGED%%$'\n'*}" = "$TARGET_TREE" ] && exit 0 ;; 1) ;; - *) could_not_run ;; + *) could_not_run "git merge-tree failed merging the net change" ;; esac exit 1 diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 4d4b21410c..72ed4c3ee3 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -344,18 +344,21 @@ describe('change-landed.sh', function () { assert.strictEqual(withCommit.status, 0, withCommit.stdout + withCommit.stderr); }); - it('cannot tell when a picked commit changes merge attributes', function () { - const base = git('rev-parse', 'HEAD'); - writeFileSync(join(dir, '.gitattributes'), 'text.txt merge=union\n'); - git('add', '.gitattributes'); - git('commit', '-qm', 'Merge attributes'); - const commit = git('rev-parse', 'HEAD'); - git('checkout', '-qb', 'target', base); - git('cherry-pick', commit); - const result = landed('target', base, commit); - assert.strictEqual(result.status, 2, result.stdout + result.stderr); - assert.match(result.stdout, /^::warning::/m); - }); + for (const path of ['.gitattributes', 'café/.gitattributes']) { + it(`cannot tell when a picked commit changes ${path}`, function () { + const base = git('rev-parse', 'HEAD'); + mkdirSync(dirname(join(dir, path)), { recursive: true }); + writeFileSync(join(dir, path), '*.txt merge=union\n'); + git('add', path); + git('commit', '-qm', 'Merge attributes'); + const commit = git('rev-parse', 'HEAD'); + git('checkout', '-qb', 'target', base); + git('cherry-pick', commit); + const result = landed('target', base, commit); + assert.strictEqual(result.status, 2, result.stdout + result.stderr); + assert.match(result.stdout, /^::warning::.*changes \.gitattributes/m); + }); + } it('reports a check that cannot run with a warning and exit 2', function () { const result = landed('refs/heads/no-such-branch', 'HEAD', 'HEAD'); @@ -589,8 +592,6 @@ function runJob({ dir, env, origin, prJson, stickyStub, git, openPr, afterStash }; } -// GitHub's expression syntax, limited to the forms this job uses; anything else fails the test -// rather than being guessed at. function expand(text, outputs) { return text.replace(/\$\{\{\s*(.+?)\s*\}\}/g, (_, expression) => { const output = /^steps\.pick\.outputs\.(\w+)$/.exec(expression); From 2faa4a549b06cbe81141294450675f7ae21fd01e Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Tue, 6 Oct 2026 20:37:11 -0600 Subject: [PATCH 13/15] Answer the pre-push review of the rebase Check the argument count before reading the commit arguments, so a short call warns and exits 2 rather than dying on an unbound variable. Move the git and jq prerequisite checks into the suite's before hook instead of running them at import, and skip with a reason locally. State the git 2.45 floor in the design note. Drop two comments that narrated the fixture. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_015HHpeWHS7k1finPHELqC8o Dispatch-Task: pr-maint-b444c4de6b0647417dddd242567c8e7f --- .github/DESIGN.md | 2 +- .github/scripts/change-landed.sh | 6 +++- unitTests/github/cherryPickPatch.test.mjs | 34 +++++++++++------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 0b75df919d..80c8bdcd4f 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -32,4 +32,4 @@ Write a fixture's rows in one transaction and await a write only before the step Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. The script replays the picked commits onto the release in order with `git merge-tree`, resolving each conflict toward the commit, and the result must be the release's own tree. A conflict then means only that a commit met content a later commit of the PR already wrote. It also merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), into the release, and that must leave the tree unchanged; this covers merge resolutions that no commit carries. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed by main from another PR, or undone by a later commit of its own picks as before. So does a conflicting change, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the first pick; it gives up, and the job picks, when any picked commit changes a `.gitattributes` file, since later picks would read that copy. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. +A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the first pick; it gives up, and the job picks, when any picked commit changes a `.gitattributes` file, since later picks would read that copy. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. The check needs git 2.45 or newer (`merge-tree` on trees); the runner images ship newer, and the suite fails under CI on older git rather than skipping. diff --git a/.github/scripts/change-landed.sh b/.github/scripts/change-landed.sh index 9380a51d2a..1ef82050b0 100755 --- a/.github/scripts/change-landed.sh +++ b/.github/scripts/change-landed.sh @@ -6,6 +6,11 @@ # would land something, 2 when the check cannot tell; callers pick on either. set -u +if [ "$#" -lt 4 ]; then + echo "::warning::change-landed.sh needs a target, base, head and at least one commit, so the commits will be picked" + exit 2 +fi + TARGET="$1" BASE="$2" HEAD="$3" @@ -16,7 +21,6 @@ could_not_run() { exit 2 } -[ "$#" -gt 0 ] || could_not_run "no commits given" TARGET_TREE=$(git rev-parse --verify --quiet "$TARGET^{tree}") || could_not_run "$TARGET does not resolve" REPLAYED="$TARGET" diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 72ed4c3ee3..0051d9efe0 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -6,26 +6,27 @@ import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { parse } from 'yaml'; -// Runs the shipped cherry-pick job's `run:` steps against a local origin, with `gh` and the -// sticky-comment helper stubbed, so a test sees exactly the branches and PRs a real run makes. const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..'); const job = parse(readFileSync(join(root, '.github/workflows/cherry-pick-patch.yml'), 'utf8')).jobs['cherry-pick']; const changeLanded = join(root, '.github/scripts/change-landed.sh'); const RELEASE = 'v5.3'; const PR_NUMBER = '7'; const DEADLINE = 60_000; -// change-landed.sh merges trees with an explicit merge base, which git supports from 2.45. -const GIT_HAS_TREE_MERGE = (() => { - const [major, minor] = /(\d+)\.(\d+)/ - .exec(execFileSync('git', ['--version'], { encoding: 'utf8' })) - .slice(1) - .map(Number); - return major > 2 || (major === 2 && minor >= 45); -})(); -function requireTreeMerge() { - if (GIT_HAS_TREE_MERGE) return; - if (process.env.CI) throw new Error('change-landed.sh needs git 2.45 or newer'); - this.skip(); +function gitHasTreeMerge() { + const { stdout = '' } = spawnSync('git', ['--version'], { encoding: 'utf8' }); + const [, major, minor] = /(\d+)\.(\d+)/.exec(stdout) ?? []; + return Number(major) > 2 || (Number(major) === 2 && Number(minor) >= 45); +} +// Skips where a prerequisite is missing; under CI a skip would hide the guard going untested. +function requirePrerequisites({ jq = false } = {}) { + return function () { + const missing = []; + if (!gitHasTreeMerge()) missing.push('git 2.45 or newer'); + if (jq && spawnSync('jq', ['--version']).status !== 0) missing.push('jq'); + if (missing.length === 0) return; + if (process.env.CI) throw new Error(`cherry-pick tests need ${missing.join(' and ')}`); + this.skip(); + }; } // The second commit rewrites the line the first one changed, so replaying the first onto a release // that already has both conflicts instead of applying empty. @@ -35,7 +36,7 @@ const SECOND_FIX = { 5: 'second fix', 6: 'second fix, continued' }; describe('cherry-pick-patch.yml', function () { let fixture; - before(requireTreeMerge); + before(requirePrerequisites({ jq: true })); beforeEach(function () { fixture = createFixture(); @@ -275,7 +276,7 @@ describe('change-landed.sh', function () { timeout: DEADLINE, }); - before(requireTreeMerge); + before(requirePrerequisites()); beforeEach(function () { dir = mkdtempSync(join(tmpdir(), 'change-landed-')); @@ -434,7 +435,6 @@ if (command === 'api' && /^repos\\/[^/]+\\/[^/]+\\/pulls\\/\\d+$/.test(sub) && a seedGit('add', 'lib.txt'); seedGit('commit', '-qm', 'Base'); seedGit('branch', RELEASE); - // main moves on after the release cut, away from the lines the PRs touch let mainState = { 35: 'main-only change' }; commitLib(mainState, 'Main-only change'); seedGit('branch', 'feature'); From 289b9614a2e5a0e6a217b46da81f60cc4a4868da Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Wed, 7 Oct 2026 06:46:13 -0600 Subject: [PATCH 14/15] Don't push an empty-diff branch when a hold's fallback pick is already applied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fast-forwarded PR collapses merge-base onto HEAD, so the job falls back to the API's merge SHA as the sole pick and sets a hold without ever running the new containment check (CHANGE_HEAD is cleared for that path). If the release already has that one commit, apply-picks.sh skips it as already-applied and the branch ends up identical to the release tip — but the no-op guard only short-circuited when the hold was empty, so it force-pushed the unchanged branch anyway and "Report held for review" tried to open a PR with no commits ahead of base. GitHub rejects that for real; only the test's always-succeeds gh stub let it pass. Generalize the guard to fire on "no new commits" regardless of hold, and let the existing PUSHED != true branch in "Report held for review" handle it, as it already does for the earlier non-fallback already-landed case. Dispatch-Task: pr-maint-b444c4de6b0647417dddd242567c8e7f Co-Authored-By: Claude Sonnet 5 --- .github/workflows/cherry-pick-patch.yml | 12 ++++++++---- unitTests/github/cherryPickPatch.test.mjs | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cherry-pick-patch.yml b/.github/workflows/cherry-pick-patch.yml index 2e837d41ea..eb5e14f548 100644 --- a/.github/workflows/cherry-pick-patch.yml +++ b/.github/workflows/cherry-pick-patch.yml @@ -390,11 +390,15 @@ jobs: CONFLICTS=$("$RUNNER_TEMP/apply-picks.sh" "$PICK_FLAGS" "$PICK_SHAS") echo "conflicts=$CONFLICTS" >> "$GITHUB_OUTPUT" - if [ -z "$CONFLICTS" ] && [ -z "$HOLD" ] && [ -z "$(git rev-list "origin/${RELEASE_BRANCH}..HEAD")" ]; then - echo "Nothing to land on $RELEASE_BRANCH — every commit was already present" - echo "no_op=true" >> "$GITHUB_OUTPUT" - # An earlier run may have pushed a branch that is now redundant. + if [ -z "$CONFLICTS" ] && [ -z "$(git rev-list "origin/${RELEASE_BRANCH}..HEAD")" ]; then + # Nothing landed on this branch, so there is nothing to push a + # human could review either — a hold does not change that. An + # earlier run may have pushed a branch that is now redundant. git push origin --delete "$BRANCH" 2>/dev/null || true + if [ -z "$HOLD" ]; then + echo "Nothing to land on $RELEASE_BRANCH — every commit was already present" + echo "no_op=true" >> "$GITHUB_OUTPUT" + fi exit 0 fi diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 0051d9efe0..010e6e817f 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -183,6 +183,9 @@ describe('cherry-pick-patch.yml', function () { const run = fixture.runJob(); assert.notStrictEqual(run.outputs.no_op, 'true', run.log); assert.ok(run.ran.includes('Report held for review'), run.log); + // The lone fallback commit cherry-picks as a no-op, so this branch gets no new commits. + assert.deepStrictEqual(run.prCreates, []); + assert.deepStrictEqual(fixture.cherryPickBranches(), []); assert.match(run.stickies.at(-1), /held for review/); }); From 40faf0941aa385841b5e0ba69fe5835025782747 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 12 Oct 2026 12:46:24 -0600 Subject: [PATCH 15/15] Name the edit-then-delete modify/delete gap in change-landed.sh's exceptions -X theirs only resolves content conflicts, not modify/delete: a commit that edits a file a later commit deletes hits a conflict during replay even when the release already has both, so the PR picks into an empty-diff conflict PR instead of skipping. Fails safe (same as the other exceptions already documented) but was undocumented. Add the case to DESIGN.md and a regression test. Dispatch-Task: pr-maint-b444c4de6b0647417dddd242567c8e7f Co-Authored-By: Claude Sonnet 5 --- .github/DESIGN.md | 2 +- unitTests/github/cherryPickPatch.test.mjs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/DESIGN.md b/.github/DESIGN.md index 80c8bdcd4f..40138370f7 100644 --- a/.github/DESIGN.md +++ b/.github/DESIGN.md @@ -32,4 +32,4 @@ Write a fixture's rows in one transaction and await a write only before the step Before picking, the cherry-pick job asks `scripts/change-landed.sh` whether picking the PR onto the release branch could land anything new. The script replays the picked commits onto the release in order with `git merge-tree`, resolving each conflict toward the commit, and the result must be the release's own tree. A conflict then means only that a commit met content a later commit of the PR already wrote. It also merges the PR's net change, `MERGE_BASE..HEAD_SHA` (`MERGE_SHA^1..MERGE_SHA` for a merge-commit merge), into the release, and that must leave the tree unchanged; this covers merge resolutions that no commit carries. Only that answer skips the PR, with no branch and no PR. A change whose file content is partly present, reverted, absorbed by main from another PR, or undone by a later commit of its own picks as before. So does a conflicting change, and so does a check that cannot run. "Unchanged" is decided by Git's merge rules, the same rules the picks themselves run under: a gitlink the release already moved past, or a configured merge driver that keeps the release's side, counts as present for both. Replaying a landed PR one commit at a time re-applies each intermediate commit against its own final content, which conflicts instead of coming out empty. harper#3067 was the second run of a `demilestoned`/`milestoned` pair re-picking harper#3038 onto the v5.3 the first run had just landed it on. -A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the first pick; it gives up, and the job picks, when any picked commit changes a `.gitattributes` file, since later picks would read that copy. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. The check needs git 2.45 or newer (`merge-tree` on trees); the runner images ship newer, and the suite fails under CI on older git rather than skipping. +A hold is never cleared. When the check finds the change landed but a merge was excluded from the picks, the job reports it held, with no branch and no PR: a resolution that took one side outright leaves no diff in the net change, so "unchanged" cannot vouch for it. The fallback that builds from a lone merge commit is not provably the whole change, so it is never checked and keeps its hold. A PR whose merge of main rewrote its own commits' lines fails the replay merge, so after landing it is still re-picked into a conflict. So does a PR where one commit edits a file a later commit deletes and the release already has both: `-X theirs` only resolves content conflicts, not modify/delete, so the replay exits 1 at the edit and the job picks into a conflict PR whose net diff is empty. The check runs after the release branch is checked out, so it reads the same `.gitattributes` as the first pick; it gives up, and the job picks, when any picked commit changes a `.gitattributes` file, since later picks would read that copy. `unitTests/github/cherryPickPatch.test.mjs` runs the shipped job's steps against a fixture origin. The check needs git 2.45 or newer (`merge-tree` on trees); the runner images ship newer, and the suite fails under CI on older git rather than skipping. diff --git a/unitTests/github/cherryPickPatch.test.mjs b/unitTests/github/cherryPickPatch.test.mjs index 010e6e817f..443bbded35 100644 --- a/unitTests/github/cherryPickPatch.test.mjs +++ b/unitTests/github/cherryPickPatch.test.mjs @@ -369,6 +369,20 @@ describe('change-landed.sh', function () { assert.strictEqual(result.status, 2, result.stderr); assert.match(result.stdout, /^::warning::/m); }); + + it('exits 1 on an edit-then-delete pair even once the target has both', function () { + const base = git('rev-parse', 'HEAD'); + writeFileSync(join(dir, 'gone.txt'), 'edited\n'); + git('commit', '-qam', 'Edit'); + const edit = git('rev-parse', 'HEAD'); + git('rm', '-q', 'gone.txt'); + git('commit', '-qm', 'Delete'); + const head = git('rev-parse', 'HEAD'); + git('checkout', '-qb', 'target', base); + git('cherry-pick', edit, head); + const result = landed('target', base, head, [edit, head]); + assert.strictEqual(result.status, 1, result.stdout + result.stderr); + }); }); function isolatedGitEnv(dir) {