fix: resolve compat bases from version tags

This commit is contained in:
kiloconnect[bot]
2026-05-05 08:00:21 +00:00
parent 4b22bfbc57
commit fe3724605f
2 changed files with 18 additions and 0 deletions
+2
View File
@@ -33,8 +33,10 @@ test("finds previous compatibility commit for transformed base", async () => {
await Bun.write("brand.txt", "opencode B\n")
const target = await commit("release: v1.0.1")
await $`git tag v1.0.1 ${target}`.quiet()
await $`git checkout -b main ${old}`.quiet()
await $`git tag v1.0.0 ${old}`.quiet()
await Bun.write("brand.txt", "kilo A\n")
const prior = await commit("refactor: kilo compat for v1.0.0")
+16
View File
@@ -205,6 +205,19 @@ export async function updateBranch(name: string, commit: string): Promise<void>
await $`git update-ref refs/heads/${name} ${commit}`
}
async function compatUpstream(message: string): Promise<string | null> {
const prefix = "refactor: kilo compat for "
if (!message.startsWith(prefix)) return null
const tag = message.slice(prefix.length).trim().split(/\s+/)[0]
if (!tag) return null
const ref = `${tag}^{commit}`
const result = await $`git rev-parse ${ref}`.quiet().nothrow()
if (result.exitCode !== 0) return null
return result.stdout.toString().trim()
}
export async function findLatestCompatCommit(base: string, target: string): Promise<CompatBase | null> {
const grep = "^refactor: kilo compat for "
const result = await $`git log --format=%H%x00%s --grep=${grep} ${base}`.quiet().nothrow()
@@ -222,6 +235,9 @@ export async function findLatestCompatCommit(base: string, target: string): Prom
const [commit, message = ""] = line.split("\0")
if (!commit) continue
const upstream = await compatUpstream(message)
if (upstream && (await isAncestor(upstream, target))) return { commit, upstream, message }
const parents = await getCommitParents(commit)
for (const parent of parents) {
if (await isAncestor(parent, target)) return { commit, upstream: parent, message }