refactor(core): combine git discovery queries (#36321)
This commit is contained in:
parent
8e76adb08f
commit
6b3c4f5839
2 changed files with 26 additions and 8 deletions
|
|
@ -189,16 +189,14 @@ const layer = Layer.effect(
|
||||||
if (!dotgit) return undefined
|
if (!dotgit) return undefined
|
||||||
|
|
||||||
const cwd = path.dirname(dotgit)
|
const cwd = path.dirname(dotgit)
|
||||||
const git = run(cwd, proc)
|
const result = yield* run(cwd, proc)(["rev-parse", "--git-dir", "--git-common-dir", "--show-toplevel"])
|
||||||
const topLevel = yield* git(["rev-parse", "--show-toplevel"])
|
const [gitDir, commonDir, topLevel] = result.text.split(/\r?\n/)
|
||||||
const gitDir = yield* git(["rev-parse", "--git-dir"])
|
if (!gitDir || !commonDir) return undefined
|
||||||
const commonDir = yield* git(["rev-parse", "--git-common-dir"])
|
|
||||||
if (gitDir.exitCode !== 0 || commonDir.exitCode !== 0) return undefined
|
|
||||||
|
|
||||||
return new Repository({
|
return new Repository({
|
||||||
worktree: AbsolutePath.make(topLevel.exitCode === 0 ? resolvePath(cwd, topLevel.text) : cwd),
|
worktree: AbsolutePath.make(topLevel ? resolvePath(cwd, topLevel) : cwd),
|
||||||
gitDirectory: AbsolutePath.make(resolvePath(cwd, gitDir.text)),
|
gitDirectory: AbsolutePath.make(resolvePath(cwd, gitDir)),
|
||||||
commonDirectory: AbsolutePath.make(resolvePath(cwd, commonDir.text)),
|
commonDirectory: AbsolutePath.make(resolvePath(cwd, commonDir)),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,26 @@ import { testEffect } from "./lib/effect"
|
||||||
const it = testEffect(LayerNode.compile(Git.node))
|
const it = testEffect(LayerNode.compile(Git.node))
|
||||||
|
|
||||||
describe("Git", () => {
|
describe("Git", () => {
|
||||||
|
it.live("discovers repository metadata without a work tree", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const root = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
|
yield* Effect.promise(async () => {
|
||||||
|
await initRepo(root.path)
|
||||||
|
await $`git config core.bare true`.cwd(root.path).quiet()
|
||||||
|
})
|
||||||
|
const directory = AbsolutePath.make(yield* Effect.promise(() => fs.realpath(root.path)))
|
||||||
|
const git = yield* Git.Service
|
||||||
|
const repository = yield* git.repo.discover(directory)
|
||||||
|
|
||||||
|
expect(repository?.worktree).toBe(directory)
|
||||||
|
expect(repository?.gitDirectory).toBe(AbsolutePath.make(path.join(directory, ".git")))
|
||||||
|
expect(repository?.commonDirectory).toBe(repository?.gitDirectory)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
it.live("clones a remote and reads checkout metadata", () =>
|
it.live("clones a remote and reads checkout metadata", () =>
|
||||||
withRemote((fixture) =>
|
withRemote((fixture) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue