/
git-cmd-client.ts
41 lines (32 loc) · 1.24 KB
/
git-cmd-client.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
import { execSync } from "child_process";
import shellEscape from "shell-escape";
export class GitCmdClient {
private _revParseHash: { [key: string]: string } = {};
currentName() {
return execSync('git branch | grep "^\\*" | cut -b 3-', { encoding: "utf8" });
}
revParse(currentName: string) {
if (!this._revParseHash[currentName]) {
this._revParseHash[currentName] = execSync(`git rev-parse "${currentName}"`, { encoding: "utf8" });
}
return this._revParseHash[currentName];
}
branches() {
return execSync("git branch -a", { encoding: "utf8" });
}
containedBranches(hash: string): string {
return execSync(shellEscape(["git", "branch", "-a", "--contains", hash]), { encoding: "utf8" });
}
logTime(hash: string) {
return execSync(shellEscape(["git", "log", "--pretty=%ci", "-n", "1", hash]), { encoding: "utf8" });
}
logBetween(a: string, b: string) {
return execSync(shellEscape(["git", "log", "--oneline", `${a}..${b}`]), { encoding: "utf8" });
}
logGraph() {
return execSync('git log -n 300 --graph --pretty=format:"%h %p"', { encoding: "utf8" });
}
mergeBase(a: string, b: string) {
return execSync(shellEscape(["git", "merge-base", "-a", a, b]), { encoding: "utf8" });
}
}