-
Notifications
You must be signed in to change notification settings - Fork 11
/
git.ts
30 lines (23 loc) · 884 Bytes
/
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
const util = require('util');
const exec = util.promisify(require('child_process').exec);
import { getWorkspaceFolder } from './workspace';
export class Git {
static exists() {
return this.execute(getWorkspaceFolder(), '', ['--version']);
}
static async add() {
const { stdout: changes } = await this.diff(['--cached']);
if (changes.length === 0) {
return this.execute(getWorkspaceFolder(), 'add', [`--all`]);
}
}
static async commit(message: string, options: string[]) {
return this.execute(getWorkspaceFolder(), 'commit', [`--message="${message}"`, ...options]);
}
static execute(cwd: string, command?: string, options: string[] = []) {
return exec(`git ${command} ${options.join(' ')}`, { cwd });
}
private static async diff(options: string[] = []) {
return this.execute(getWorkspaceFolder(), 'diff', [...options]);
}
}