-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitcmds.ts
43 lines (40 loc) · 1.36 KB
/
gitcmds.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
// gitcmds.ts this holds various commands to interact with Git in a Git repository.
import * as path from "@std/path";
export async function gitReleaseHash(): Promise<string> {
const command = new Deno.Command("git", {
args: [
"log",
"--pretty=format:%h",
"-n",
"1",
],
});
const { code, stdout, stderr } = await command.output();
console.assert(code === 0);
return (new TextDecoder()).decode(stdout);
}
async function getRemoteOriginURL(): Promise<string> {
const command = new Deno.Command("git", {
args: [
"config",
"--get",
"remote.origin.url",
],
});
const { code, stdout, stderr } = await command.output();
console.assert(code === 0);
return (new TextDecoder()).decode(stdout);
}
export async function gitOrgOrPerson(): Promise<string> {
// NOTE: Group directory is a fall back git there is no remote in the Git config
const groupDir: string = path.basename(path.join(Deno.cwd(), "../"));
const remoteOriginURL: string | undefined = await getRemoteOriginURL();
// QUESTION: should I get the URL from the Git repo config or from CodeMeta?
const u = URL.parse(
remoteOriginURL.replace("[email protected]:", "https://github.com/"),
);
if (remoteOriginURL === undefined || remoteOriginURL === "" || u === null) {
return groupDir;
}
return path.dirname(u.pathname).replace(/^\//, "");
}