Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ export const _internals = { reset, initialized, boolize }
/// we support a tea installed or system installed git, nothing else
/// eg. `git` could be a symlink in `PATH` to tea, which would cause a fork bomb
/// on darwin if xcode or xcode/clt is not installed this will fail to our http fallback above
function git(prefix: Path, PATH?: string): Path | undefined {
const pkg = prefix.join('git-scm.org/v2').isDirectory()
return (pkg ?? usr())?.join("bin/git")
//TODO be able to use our own git if installed
//NOTE however we don’t want to have to fully hydrate its env when libtea is initialized only when needed so…
function git(_prefix: Path, PATH?: string): Path | undefined {
return usr()

function usr() {
// only return /usr/bin if in the PATH so user can explicitly override this
Expand All @@ -86,6 +87,6 @@ function git(prefix: Path, PATH?: string): Path | undefined {
return // don’t use `git`
}

return rv
return rv?.join("bin/git")
}
}
18 changes: 2 additions & 16 deletions src/hooks/useSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import { writeAll } from "deno/streams/write_all.ts"
import { flock } from "../utils/flock.deno.ts"
import useDownload from "./useDownload.ts"
import useShellEnv from "./useShellEnv.ts"
import { Installation } from "../types.ts"
import SemVer from "../utils/semver.ts"
import usePantry from "./usePantry.ts"
import useConfig from "./useConfig.ts"
import Path from "../utils/Path.ts"
Expand Down Expand Up @@ -69,24 +66,13 @@ export default async function(logger?: Logger) {
//////////////////////// utils

async function git(...args: (string | Path)[]) {
const { git, prefix } = useConfig()
const env = await (async () => {
//TODO lol hacky
if (!git?.string.startsWith(prefix.string)) return
const installation: Installation = {
path: git.parent().parent(),
pkg: { project: 'git-scm.org', version: new SemVer('2.40.0')}
}
const { map, flatten } = useShellEnv()
return flatten(await map({installations: [installation]}))
})()
const { git } = useConfig()
if (!git) throw new Error("no-git") // caught above to trigger http download instead
await run({cmd: [git, ...args], env})
await run({cmd: [git, ...args]})
}

export interface RunOptions {
cmd: (string | Path)[]
env?: Record<string, string>
}

async function run(opts: RunOptions) {
Expand Down