feat: config command (#71)
This commit is contained in:
39
src/utils/git.ts
Normal file
39
src/utils/git.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { execa } from 'execa';
|
||||
|
||||
export const assertGitRepo = async () => {
|
||||
const { stdout } = await execa('git', ['rev-parse', '--is-inside-work-tree'], { reject: false });
|
||||
|
||||
if (stdout !== 'true') {
|
||||
throw new Error('The current directory must be a Git repository!');
|
||||
}
|
||||
};
|
||||
|
||||
const excludeFromDiff = [
|
||||
'package-lock.json',
|
||||
'yarn.lock',
|
||||
'pnpm-lock.yaml',
|
||||
].map(file => `:(exclude)${file}`);
|
||||
|
||||
export const getStagedDiff = async () => {
|
||||
const diffCached = ['diff', '--cached'];
|
||||
const { stdout: files } = await execa(
|
||||
'git',
|
||||
[...diffCached, '--name-only', ...excludeFromDiff],
|
||||
);
|
||||
|
||||
if (!files) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { stdout: diff } = await execa(
|
||||
'git',
|
||||
[...diffCached, ...excludeFromDiff],
|
||||
);
|
||||
|
||||
return {
|
||||
files: files.split('\n'),
|
||||
diff,
|
||||
};
|
||||
};
|
||||
|
||||
export const getDetectedMessage = (files: string[]) => `Detected ${files.length.toLocaleString()} staged file${files.length > 1 ? 's' : ''}`;
|
||||
Reference in New Issue
Block a user