fix: preserve upstream compat merge bases

This commit is contained in:
kiloconnect[bot]
2026-05-04 15:54:19 +00:00
parent 419ddea52a
commit 4b1c1930c2
3 changed files with 58 additions and 4 deletions
+1 -1
View File
@@ -536,7 +536,7 @@ async function main() {
const compatMessage = `refactor: kilo compat for ${targetVersion.tag}`
if (prior) {
const tree = await git.writeTree()
const commit = await git.commitTree(tree, compatMessage, [targetVersion.commit, prior.commit])
const commit = await git.createMergeCommit(tree, compatMessage, targetVersion.commit, prior.commit)
await git.updateBranch(opencodeBranch, commit)
await git.checkout(opencodeBranch)
} else {
+55
View File
@@ -0,0 +1,55 @@
import { afterEach, beforeEach, expect, test } from "bun:test"
import { mkdtemp, rm } from "node:fs/promises"
import { join } from "node:path"
import { tmpdir } from "node:os"
import { $ } from "bun"
import { createMergeCommit, findLatestCompatCommit, getCommitHash, updateBranch, writeTree } from "./git"
const cwd = process.cwd()
let dir = ""
async function commit(message: string) {
await $`git add -A`.quiet()
await $`git -c user.name=Test -c user.email=test@example.com commit -m ${message}`.quiet()
return getCommitHash("HEAD")
}
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "kilo-upstream-git-"))
process.chdir(dir)
await $`git init -b upstream`.quiet()
await $`git config user.name Test`.quiet()
await $`git config user.email test@example.com`.quiet()
})
afterEach(async () => {
process.chdir(cwd)
await rm(dir, { recursive: true, force: true })
})
test("finds previous compatibility commit for transformed merge base", async () => {
await Bun.write("brand.txt", "opencode A\n")
const old = await commit("release: v1.0.0")
await Bun.write("brand.txt", "opencode B\n")
const target = await commit("release: v1.0.1")
await $`git checkout -b main ${old}`.quiet()
await Bun.write("brand.txt", "kilo A\n")
const prior = await commit("refactor: kilo compat for v1.0.0")
const found = await findLatestCompatCommit("main", target)
expect(found?.commit).toBe(prior)
expect(found?.upstream).toBe(old)
await $`git checkout ${target}`.quiet()
await $`git checkout -b opencode-v1.0.1`.quiet()
await Bun.write("brand.txt", "kilo B\n")
await $`git add -A`.quiet()
const tree = await writeTree()
const next = await createMergeCommit(tree, "refactor: kilo compat for v1.0.1", target, prior)
await updateBranch("opencode-v1.0.1", next)
const base = (await $`git merge-base main opencode-v1.0.1`.text()).trim()
expect(base).toBe(prior)
})
+2 -3
View File
@@ -196,9 +196,8 @@ export async function writeTree(): Promise<string> {
return result.trim()
}
export async function commitTree(tree: string, message: string, parents: string[]): Promise<string> {
const args = parents.flatMap((parent) => ["-p", parent])
const result = await $`git commit-tree ${tree} ${args} -m ${message}`.text()
export async function createMergeCommit(tree: string, message: string, first: string, second: string): Promise<string> {
const result = await $`git commit-tree ${tree} -p ${first} -p ${second} -m ${message}`.text()
return result.trim()
}