fix(core): reduce snapshot repository setup (#38162)
Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
parent
6b9136e797
commit
59ad593d9c
2 changed files with 51 additions and 14 deletions
|
|
@ -17,6 +17,25 @@ export class Repository extends Schema.Class<Repository>("Git.Repository")({
|
|||
commonDirectory: AbsolutePath,
|
||||
}) {}
|
||||
|
||||
// Included from $GIT_DIR/config via include.path (git >= 1.7.10); OpenCode owns
|
||||
// this file entirely, so updates are plain rewrites with no config parsing.
|
||||
const snapshotConfigFile = "opencode.gitconfig"
|
||||
const snapshotConfigInclude = `[include]
|
||||
path = ${snapshotConfigFile}
|
||||
`
|
||||
const snapshotConfig = `[core]
|
||||
autocrlf = false
|
||||
longpaths = true
|
||||
symlinks = true
|
||||
fsmonitor = false
|
||||
untrackedCache = true
|
||||
[feature]
|
||||
manyFiles = true
|
||||
[index]
|
||||
version = 4
|
||||
threads = true
|
||||
`
|
||||
|
||||
export const ChangeSet = Schema.String.pipe(Schema.brand("Git.ChangeSet"))
|
||||
export type ChangeSet = typeof ChangeSet.Type
|
||||
|
||||
|
|
@ -376,19 +395,24 @@ const layer = Layer.effect(
|
|||
commonDirectory: input.gitDirectory,
|
||||
})
|
||||
yield* repositoryOperation("create", repository, ["init"])
|
||||
yield* Effect.forEach(
|
||||
[
|
||||
["core.autocrlf", "false"],
|
||||
["core.longpaths", "true"],
|
||||
["core.symlinks", "true"],
|
||||
["core.fsmonitor", "false"],
|
||||
["feature.manyFiles", "true"],
|
||||
["index.version", "4"],
|
||||
["index.threads", "true"],
|
||||
["core.untrackedCache", "true"],
|
||||
],
|
||||
([key, value]) => repositoryOperation("create", repository, ["config", key, value]),
|
||||
{ discard: true },
|
||||
yield* Effect.gen(function* () {
|
||||
yield* fs.writeFileString(path.join(input.gitDirectory, snapshotConfigFile), snapshotConfig)
|
||||
const config = path.join(input.gitDirectory, "config")
|
||||
const current = yield* fs.readFileString(config)
|
||||
if (current.includes(snapshotConfigInclude)) return
|
||||
yield* fs.writeFileString(config, `${current.endsWith("\n") ? "\n" : "\n\n"}${snapshotConfigInclude}`, {
|
||||
flag: "a",
|
||||
})
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new OperationError({
|
||||
operation: "create",
|
||||
directory: input.gitDirectory,
|
||||
message: "Failed to configure Git storage",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
)
|
||||
if (!input.seed) return repository
|
||||
yield* fs.ensureDir(path.join(input.gitDirectory, "objects", "info")).pipe(
|
||||
|
|
|
|||
|
|
@ -148,8 +148,21 @@ describe("Git trees", () => {
|
|||
const git = yield* Git.Service
|
||||
const source = yield* git.repo.discover(AbsolutePath.make(root.path))
|
||||
if (!source) throw new Error("Repository not found")
|
||||
const storage = AbsolutePath.make(path.join(root.path, ".snapshot"))
|
||||
const storage = AbsolutePath.make(path.join(root.path, ".snapshot storage"))
|
||||
const repository = yield* git.repo.create({ worktree: source.worktree, gitDirectory: storage, seed: source })
|
||||
yield* Effect.promise(() => $`git --git-dir ${storage} config --add include.path first.gitconfig`.quiet())
|
||||
yield* Effect.promise(() => $`git --git-dir ${storage} config --add include.path second.gitconfig`.quiet())
|
||||
yield* Effect.promise(() => $`git --git-dir ${storage} config core.autocrlf true`.quiet())
|
||||
yield* git.repo.create({ worktree: source.worktree, gitDirectory: storage, seed: source })
|
||||
expect(
|
||||
yield* Effect.promise(() => $`git --git-dir ${storage} config --local --includes core.autocrlf`.text()),
|
||||
).toBe("false\n")
|
||||
expect(
|
||||
(yield* Effect.promise(() => fs.readFile(path.join(storage, "config"), "utf8"))).match(/opencode\.gitconfig/g),
|
||||
).toHaveLength(1)
|
||||
expect(
|
||||
yield* Effect.promise(() => $`git --git-dir ${storage} config --local --get-all include.path`.text()),
|
||||
).toBe("opencode.gitconfig\nfirst.gitconfig\nsecond.gitconfig\n")
|
||||
yield* git.index.refresh({ repository, scope: RelativePath.make("scope") })
|
||||
const before = yield* git.tree.write(repository)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue