forked from di-sukharev/opencommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
49 lines (41 loc) · 1.03 KB
/
Copy pathgit.ts
File metadata and controls
49 lines (41 loc) · 1.03 KB
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
import { execa } from 'execa';
import { spinner } from '@clack/prompts';
export const assertGitRepo = async () => {
try {
await execa('git', ['rev-parse']);
} catch (error) {
throw new Error(error as string);
}
};
const excludeBigFilesFromDiff = ['*-lock.*', '*.lock'].map(
(file) => `:(exclude)${file}`
);
export interface StagedDiff {
files: string[];
diff: string;
}
export const getStagedGitDiff = async (
isStageAllFlag = false
): Promise<StagedDiff | null> => {
if (isStageAllFlag) {
const stageAllSpinner = spinner();
stageAllSpinner.start('Staging all changes');
await execa('git', ['add', '.']);
stageAllSpinner.stop('Done');
}
const diffStaged = ['diff', '--staged'];
const { stdout: files } = await execa('git', [
...diffStaged,
'--name-only',
...excludeBigFilesFromDiff
]);
if (!files) return null;
const { stdout: diff } = await execa('git', [
...diffStaged,
...excludeBigFilesFromDiff
]);
return {
files: files.split('\n').sort(),
diff
};
};