feat(cli): --exclude flag for ignoring files (#162)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
@@ -9,19 +9,30 @@ export const assertGitRepo = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const excludeFromDiff = [
|
||||
const excludeFromDiff = (path: string) => `:(exclude)${path}`;
|
||||
|
||||
const filesToExclude = [
|
||||
'package-lock.json',
|
||||
'pnpm-lock.yaml',
|
||||
|
||||
// yarn.lock, Cargo.lock, Gemfile.lock, Pipfile.lock, etc.
|
||||
'*.lock',
|
||||
].map(file => `:(exclude)${file}`);
|
||||
].map(excludeFromDiff);
|
||||
|
||||
export const getStagedDiff = async () => {
|
||||
export const getStagedDiff = async (excludeFiles?: string[]) => {
|
||||
const diffCached = ['diff', '--cached'];
|
||||
const { stdout: files } = await execa(
|
||||
'git',
|
||||
[...diffCached, '--name-only', ...excludeFromDiff],
|
||||
[
|
||||
...diffCached,
|
||||
'--name-only',
|
||||
...filesToExclude,
|
||||
...(
|
||||
excludeFiles
|
||||
? excludeFiles.map(excludeFromDiff)
|
||||
: []
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
if (!files) {
|
||||
@@ -30,7 +41,10 @@ export const getStagedDiff = async () => {
|
||||
|
||||
const { stdout: diff } = await execa(
|
||||
'git',
|
||||
[...diffCached, ...excludeFromDiff],
|
||||
[
|
||||
...diffCached,
|
||||
...filesToExclude,
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user