-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit.ts
83 lines (78 loc) · 3.84 KB
/
git.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { evaluateSystemCommand, spawn } from "../src/helpers.ts";
import Plugin from "../src/plugin.ts";
import Brew from "./brew.ts";
class Git implements Plugin {
name = "git";
commands: Record<string, (params: string[]) => Promise<void>>;
constructor() {
this.commands = {
add: (args: string[]) => spawn(this.name, ["add", ...args]),
init: (args: string[]) => spawn(this.name, ["init", ...args]),
mv: (args: string[]) => spawn(this.name, ["mv", ...args]),
restore: (args: string[]) => spawn(this.name, ["restore", ...args]),
rm: (args: string[]) => spawn(this.name, ["rm", ...args]),
checkout: (args: string[]) => spawn(this.name, ["checkout", ...args]),
bisect: (args: string[]) => spawn(this.name, ["bisect", ...args]),
diff: (args: string[]) => spawn(this.name, ["diff", ...args]),
grep: (args: string[]) => spawn(this.name, ["grep", ...args]),
show: (args: string[]) => spawn(this.name, ["show", ...args]),
rebase: (args: string[]) => spawn(this.name, ["rebase", ...args]),
"cherry-pick": (args: string[]) =>
spawn(this.name, ["cherry-pick", ...args]),
reset: (args: string[]) => spawn(this.name, ["reset", ...args]),
switch: (args: string[]) => spawn(this.name, ["switch", ...args]),
fetch: (args: string[]) => spawn(this.name, ["fetch", ...args]),
clone: (args: string[]) => spawn(this.name, ["clone", ...args]),
pull: (args: string[]) => spawn(this.name, ["pull", ...args]),
push: (args: string[]) => spawn(this.name, ["push", ...args]),
commit: (args: string[]) => spawn(this.name, ["commit", ...args]),
status: (args: string[]) => spawn(this.name, ["status", ...args]),
branch: (args: string[]) => spawn(this.name, ["branch", ...args]),
log: (args: string[]) => spawn(this.name, ["log", ...args]),
merge: (args: string[]) => spawn(this.name, ["merge", ...args]),
tag: (args: string[]) => spawn(this.name, ["tag", ...args]),
help: () => {
console.log(` Git Commands:
add Add file contents to the index
init Create an empty Git repository or reinitialize an existing one
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
checkout Switch branches or restore working tree files
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
show Show various types of objects
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
clone Clone a repository into a new directory
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
commit Record changes to the repository
status Show the working tree status
branch List, create, or delete branches
log Show the commit logs
merge Join two or more development histories together
tag Create, list, delete, or verify a tag object signed with GPG`);
return Promise.resolve();
},
};
}
async evaluate(command: string): Promise<void> {
const [cmd, ...params] = command.split(" ");
if (this.commands[cmd]) {
await this.commands[cmd](params);
return;
}
if (cmd === "") {
return;
}
await evaluateSystemCommand(command);
}
async install(): Promise<void> {
await new Brew().install();
await spawn("sh", ["-c", "type git > /dev/null || brew install git"]);
}
}
export default Git;