forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.ts
46 lines (39 loc) · 1.19 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
import execa from 'execa';
import * as fix from './fix';
export async function bootstrap(fixture?: string, directory?: string) {
const cwd = await fix.bootstrap(fixture, directory);
await init(cwd);
return cwd;
}
export async function clone(
source: string,
args: string[],
directory?: string,
gitCommand = 'git'
) {
const cwd = await fix.bootstrap(undefined, directory);
await execa(gitCommand, ['clone', ...args, source, cwd]);
await setup(cwd, gitCommand);
return cwd;
}
export async function init(cwd: string) {
await execa('git', ['init', cwd]);
await setup(cwd);
return cwd;
}
async function setup(cwd: string, gitCommand = 'git') {
try {
await execa(gitCommand, ['config', 'user.name', 'ava'], {cwd});
await execa(gitCommand, ['config', 'user.email', '[email protected]'], {
cwd,
});
await execa(gitCommand, ['config', 'commit.gpgsign', 'false'], {cwd});
await execa(gitCommand, ['config', 'core.commentChar', '#'], {cwd});
} catch (err: any) {
if (typeof err === 'object' && typeof err.message === 'object') {
console.warn(`git config in ${cwd} failed`, err.message);
} else {
console.error('An unknown error occurred setting up the git environment');
}
}
}