summaryrefslogtreecommitdiff
path: root/src/lib/git/index.ts
blob: 23a13eb31b8b7d59e4aef8bc37d6286bc66aaec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { get, instanciate } from "../../utils/anonymous.ts";

let cachedGitDir: Promise<URL> | undefined;

export function gitDir(): Promise<URL> {
  if (!cachedGitDir) {
    cachedGitDir = new Deno.Command("git", {
      args: ["rev-parse", "--show-toplevel"],
    }).output()
      .then(get("stdout"))
      .then((x) => `file://${new TextDecoder().decode(x).trim()}/`)
      .then(instanciate(URL));
  }

  return cachedGitDir;
}