fix(core): reuse ignore checks during index refresh (#45459)

This commit is contained in:
Kit Langton
2026-08-27 11:44:44 -04:00
committed by GitHub
Unverified
parent 8d1d1ee982
commit 6dbb5f5008
4 changed files with 98 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@opencode-ai/core": patch
---
Propagate fatal Git ignore-check errors during index refresh so best-effort snapshot capture returns unavailable instead of treating the check as having no matches.
+8 -14
View File
@@ -398,22 +398,16 @@ const layer = Layer.effect(
],
{ concurrency: 2 },
)
const candidates = Array.from(new Set([...tracked, ...untracked]))
const candidates = Array.from(new Set([...tracked, ...untracked])).map((file) => RelativePath.make(file))
if (!candidates.length) return { skipped: [] }
const ignored = input.ignores
? new Set(
(yield* repositoryOperation("refresh", input.ignores, ["check-ignore", "--no-index", "--stdin", "-z"], {
stdin: candidates.join("\0") + "\0",
}).pipe(Effect.orElseSucceed(() => ({ text: "", stderr: "" })))).text
.split("\0")
.filter(Boolean),
)
: new Set<string>()
const allowed = candidates.filter((item) => !ignored.has(item))
const excluded = input.ignores
? yield* ignored({ repository: input.ignores, paths: candidates })
: new Set<RelativePath>()
const allowed = candidates.filter((item) => !excluded.has(item))
const maximum = input.maximumUntrackedFileBytes
const skipped = maximum
? (yield* Effect.forEach(
untracked.filter((item) => allowed.includes(item)),
untracked.filter((item) => allowed.includes(RelativePath.make(item))),
(item) =>
fs.stat(path.join(input.repository.worktree, item)).pipe(
Effect.map((info) =>
@@ -424,8 +418,8 @@ const layer = Layer.effect(
{ concurrency: 8 },
)).filter((item): item is RelativePath => item !== undefined)
: []
const stage = allowed.filter((item) => !skipped.includes(RelativePath.make(item)))
const remove = [...ignored, ...skipped]
const stage = allowed.filter((item) => !skipped.includes(item))
const remove = [...excluded, ...skipped]
if (remove.length)
yield* repositoryOperation(
"refresh",
+60
View File
@@ -131,6 +131,66 @@ describe("Git worktrees", () => {
})
describe("Git trees", () => {
;[0, 1, 128].forEach((exitCode) => {
it.live(`refresh handles check-ignore exit ${exitCode}`, () =>
Effect.gen(function* () {
const root = yield* Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
)
const project = path.join(root.path, "project")
const paths = ["scope/allowed.txt", "scope/ignored name.txt"].map((file) => RelativePath.make(file))
yield* Effect.promise(async () => {
await fs.mkdir(path.join(project, "scope"), { recursive: true })
await initRepo(project)
await Promise.all(paths.map((file) => Bun.write(path.join(project, file), "one\n")))
await $`git add .`.cwd(project).quiet()
await $`git commit -m initial`.cwd(project).quiet()
})
const git = yield* Git.Service
const source = yield* git.repo.discover(AbsolutePath.make(project))
if (!source) throw new Error("Repository not found")
const repository = yield* git.repo.create({
worktree: source.worktree,
gitDirectory: AbsolutePath.make(path.join(root.path, "storage")),
seed: source,
})
const before = yield* git.tree.write(repository)
yield* Effect.promise(async () => {
await Promise.all(paths.map((file) => Bun.write(path.join(project, file), "two\n")))
await Bun.write(path.join(source.gitDirectory, "info", "exclude"), exitCode === 0 ? `${paths[1]}\n` : "")
if (exitCode === 128) await Bun.write(path.join(source.gitDirectory, "config"), "[broken\n")
const result =
await $`git --git-dir ${source.gitDirectory} --work-tree ${source.worktree} check-ignore --no-index --stdin -z < ${Buffer.from(paths.join("\0") + "\0")}`
.cwd(project)
.quiet()
.nothrow()
expect(result.exitCode).toBe(exitCode)
})
const refresh = git.index.refresh({ repository, scope: RelativePath.make("scope"), ignores: source })
if (exitCode === 128) {
const error = yield* refresh.pipe(Effect.flip)
expect(error).toBeInstanceOf(Git.OperationError)
expect(error.message).toContain("bad config line")
expect(yield* git.tree.write(repository)).toBe(before)
expect(
yield* git.index.refresh({ repository, scope: RelativePath.make("missing"), ignores: source }),
).toEqual({ skipped: [] })
return
}
expect(yield* git.index.ignored({ repository: source, paths })).toEqual(
new Set(exitCode === 0 ? [paths[1]] : []),
)
expect(yield* refresh).toEqual({ skipped: [] })
const after = yield* git.tree.write(repository)
expect((yield* git.tree.diff({ repository, from: before, to: after })).map((file) => file.status)).toEqual([
"modified",
exitCode === 0 ? "deleted" : "modified",
])
}),
)
})
it.live("lists both sides of a rename as separate file changes", () =>
Effect.gen(function* () {
const root = yield* Effect.acquireRelease(
+25
View File
@@ -127,6 +127,31 @@ describe("Snapshot", () => {
),
)
testEffect(Layer.empty).live("treats fatal ignore checks as unavailable captures", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),
(tmp) =>
Effect.gen(function* () {
const project = path.join(tmp.path, "project")
yield* Effect.promise(async () => {
await fs.mkdir(project)
await Bun.write(path.join(project, "tracked.txt"), "one\n")
await initGit(project)
})
yield* Effect.gen(function* () {
const snapshot = yield* Snapshot.Service
expect(yield* snapshot.capture()).toBeDefined()
yield* Effect.promise(async () => {
await Bun.write(path.join(project, "tracked.txt"), "two\n")
await Bun.write(path.join(project, ".git", "config"), "[broken\n")
})
expect(yield* snapshot.capture()).toBeUndefined()
}).pipe(Effect.provide(snapshotLayer(tmp.path, project)))
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
)
testEffect(Layer.empty).live("applies availability transforms", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),