Skip to content

Commit

Permalink
Only allow /usr/bin/git if it’s in PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Apr 26, 2023
1 parent b021b2c commit 0c7244f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/hooks/useSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ export default async function() {
/// on darwin if xcode or xcode/clt is not installed this will fail to our http fallback above
async function git(...args: (string | Path)[]) {
const pkg = await useCellar().has({ project: 'git-scm.org', constraint: new semver.Range('*') })
const git = (pkg?.path ?? new Path("/usr")).join("bin/git")
await run({cmd: [git, ...args]})
const git = (pkg?.path ?? usr())?.join("bin/git")
if (git) await run({cmd: [git, ...args]})

function usr() {
// only return /usr/bin if in the PATH so user can explicitly override this
return Deno.env.get("PATH")?.split(":")?.includes("/usr/bin") ? new Path("/usr") : undefined
}
}

function run(opts: RunOptions) {
Expand Down

0 comments on commit 0c7244f

Please sign in to comment.