feat(cli): --exclude flag for ignoring files (#162)

Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
tomaskudlicka
2023-03-27 03:24:48 +02:00
committed by GitHub
parent 7f6bdd93b5
commit 52b62d5a50
4 changed files with 41 additions and 16 deletions

View File

@@ -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 {