feat: add support for .opencommitignore file (#22)

* feat: add support for .opencommitignore
This commit is contained in:
Stuart van Beek
2023-03-19 09:01:57 +01:00
committed by GitHub
parent d793bf1340
commit 3f7025d50a
5 changed files with 40 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
import { execa } from 'execa';
import { outro, spinner } from '@clack/prompts';
import { readFileSync } from 'fs';
import ignore, { Ignore } from 'ignore';
export const assertGitRepo = async () => {
try {
@@ -13,16 +15,32 @@ export const assertGitRepo = async () => {
// (file) => `:(exclude)${file}`
// );
export const getOpenCommitIgnore = (): Ignore => {
const ig = ignore();
try {
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
} catch(e) {}
return ig;
}
export const getStagedFiles = async (): Promise<string[]> => {
const { stdout: files } = await execa('git', [
'diff',
'--name-only',
'--cached'
'--cached',
]);
if (!files) return [];
const filesList = files.split('\n');
return files.split('\n').sort();
const ig = getOpenCommitIgnore();
const allowedFiles = filesList.filter(file => !ig.ignores(file));
if (!allowedFiles) return [];
return allowedFiles.sort();
};
export const getChangedFiles = async (): Promise<string[]> => {