feat(core): copy file changes when warping (#26190)

This commit is contained in:
James Long
2026-05-07 10:24:17 -04:00
committed by GitHub
parent b6ff1b18c7
commit 3c4b4d5faf
23 changed files with 955 additions and 28 deletions

View File

@@ -68,6 +68,7 @@ export interface Options {
readonly cwd: string
readonly env?: Record<string, string>
readonly maxOutputBytes?: number
readonly stdin?: ChildProcess.CommandInput
}
export interface Interface {
@@ -85,6 +86,7 @@ export interface Interface {
readonly patchAll: (cwd: string, ref: string, options?: PatchOptions) => Effect.Effect<Patch>
readonly patchUntracked: (cwd: string, file: string, options?: PatchOptions) => Effect.Effect<Patch>
readonly statUntracked: (cwd: string, file: string) => Effect.Effect<Stat | undefined>
readonly applyPatch: (cwd: string, patch: string) => Effect.Effect<Result>
}
const kind = (code: string): Kind => {
@@ -101,6 +103,8 @@ export const layer = Layer.effect(
Service,
Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
const encoder = new TextEncoder()
const stdin = (text: string) => Stream.make(encoder.encode(text))
const run = Effect.fn("Git.run")(
function* (args: string[], opts: Options) {
@@ -108,7 +112,7 @@ export const layer = Layer.effect(
cwd: opts.cwd,
env: opts.env,
extendEnv: true,
stdin: "ignore",
stdin: opts.stdin ?? "ignore",
stdout: "pipe",
stderr: "pipe",
})
@@ -316,9 +320,13 @@ export const layer = Layer.effect(
cwd,
maxOutputBytes: 4096,
})
if (result.truncated) return
const parts = result.text().split("\t")
const text = result.text()
const parts = text.split("\t")
if (parts.length < 2) return
const additions = parts[0] === "-" ? 0 : Number.parseInt(parts[0] || "0", 10)
const deletions = parts[1] === "-" ? 0 : Number.parseInt(parts[1] || "0", 10)
return {
@@ -328,6 +336,10 @@ export const layer = Layer.effect(
} satisfies Stat
})
const applyPatch = Effect.fn("Git.applyPatch")(function* (cwd: string, patch: string) {
return yield* run(["apply", "-"], { cwd, stdin: stdin(patch) })
})
return Service.of({
run,
branch,
@@ -343,6 +355,7 @@ export const layer = Layer.effect(
patchAll,
patchUntracked,
statUntracked,
applyPatch,
})
}),
)