-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod.ts
44 lines (38 loc) · 1.26 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { join, isAbsolute } from "https://deno.land/std/path/mod.ts";
import { exists, existsSync } from "https://deno.land/std/fs/exists.ts";
/**
* Return `true` if the file apth is a git repository.
*
* Requires the `--allow-read` flag.
*
* @param filepath default is `Deno.cwd()`, the current working directory.
*/
export function isGitSync(filepath = Deno.cwd()): boolean {
let current = isAbsolute(filepath) ? filepath : join(Deno.cwd(), filepath);
let parent = join(current, "..");
for (; parent! !== current; parent = join(current, "..")) {
if (existsSync(join(current, ".git"))) {
return true;
}
current = parent!;
}
return existsSync(join(current, ".git"));
}
/**
* Return `true` if the file path is a git repository synchronously.
*
* Requires the `--allow-read` flag.
*
* @param filepath default is `Deno.cwd()`, the current working directory.
*/
export async function isGit(filepath = Deno.cwd()): Promise<boolean> {
let current = isAbsolute(filepath) ? filepath : join(Deno.cwd(), filepath);
let parent = join(current, "..");
for (; parent! !== current; parent = join(current, "..")) {
if (await exists(join(current, ".git"))) {
return true;
}
current = parent!;
}
return exists(join(current, ".git"));
}