mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-17 17:43:04 +08:00
fix: preserve upstream ancestry on kilo merge
This commit is contained in:
@@ -548,6 +548,10 @@ async function main() {
|
||||
logger.step(7, 8, "Merging into Kilo branch...")
|
||||
|
||||
await git.checkout(kiloBranch)
|
||||
if (prior) {
|
||||
const linked = await git.recordAncestor(targetVersion.commit, `merge: record upstream ${targetVersion.tag}`)
|
||||
if (linked) logger.info(`Recorded upstream ${targetVersion.tag} as Kilo branch ancestry`)
|
||||
}
|
||||
const mergeResult = await git.merge(opencodeBranch)
|
||||
|
||||
if (!mergeResult.success) {
|
||||
|
||||
@@ -3,7 +3,16 @@ import { mkdtemp, rm } from "node:fs/promises"
|
||||
import { join } from "node:path"
|
||||
import { tmpdir } from "node:os"
|
||||
import { $ } from "bun"
|
||||
import { createCommit, findLatestCompatCommit, getCommitHash, getCommitParents, updateBranch, writeTree } from "./git"
|
||||
import {
|
||||
createCommit,
|
||||
findLatestCompatCommit,
|
||||
getCommitHash,
|
||||
getCommitParents,
|
||||
isAncestor,
|
||||
recordAncestor,
|
||||
updateBranch,
|
||||
writeTree,
|
||||
} from "./git"
|
||||
|
||||
const cwd = process.cwd()
|
||||
let dir = ""
|
||||
@@ -51,8 +60,21 @@ test("finds previous compatibility commit for transformed base", async () => {
|
||||
const tree = await writeTree()
|
||||
const next = await createCommit(tree, "refactor: kilo compat for v1.0.1", 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)
|
||||
expect(await getCommitParents(next)).toEqual([prior])
|
||||
|
||||
await $`git checkout main`.quiet()
|
||||
expect(await recordAncestor(target, "merge: record upstream v1.0.1")).toBe(true)
|
||||
const link = await getCommitHash("HEAD")
|
||||
expect(await getCommitParents(link)).toEqual([prior, target])
|
||||
expect(await isAncestor(target, link)).toBe(true)
|
||||
|
||||
const linked = (await $`git merge-base main opencode-v1.0.1`.text()).trim()
|
||||
expect(linked).toBe(prior)
|
||||
|
||||
await $`git merge opencode-v1.0.1`.quiet()
|
||||
const head = await getCommitHash("HEAD")
|
||||
expect(await getCommitParents(head)).toEqual([link, next])
|
||||
expect(await isAncestor(target, head)).toBe(true)
|
||||
})
|
||||
|
||||
@@ -205,6 +205,16 @@ export async function updateBranch(name: string, commit: string): Promise<void>
|
||||
await $`git update-ref refs/heads/${name} ${commit}`
|
||||
}
|
||||
|
||||
export async function recordAncestor(ref: string, message: string): Promise<boolean> {
|
||||
if (await isAncestor(ref, "HEAD")) return false
|
||||
|
||||
const result = await $`git merge -s ours --no-ff ${ref} -m ${message}`.nothrow()
|
||||
if (result.exitCode !== 0) {
|
||||
throw new Error(`Failed to record ancestor ${ref}: ${result.stderr.toString()}`)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function compatUpstream(message: string): Promise<string | null> {
|
||||
const prefix = "refactor: kilo compat for "
|
||||
if (!message.startsWith(prefix)) return null
|
||||
|
||||
Reference in New Issue
Block a user