mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
refactor(git.ts): remove unused code and simplify getDiff function
feat(git.ts): add message for excluded lock files in getDiff function
This commit is contained in:
@@ -9,13 +9,9 @@ export const assertGitRepo = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export const showSomeFilesExcludedMessage = (files: string[]) => {
|
||||
outro(
|
||||
`Some files are .lock files which are excluded by default as it's too big, commit it yourself, don't waste your api tokens. \n${files
|
||||
.filter((file) => file.includes('.lock') || file.includes('-lock.'))
|
||||
.join('\n')}`
|
||||
);
|
||||
};
|
||||
// const excludeBigFilesFromDiff = ['*-lock.*', '*.lock'].map(
|
||||
// (file) => `:(exclude)${file}`
|
||||
// );
|
||||
|
||||
export const getStagedFiles = async (): Promise<string[]> => {
|
||||
const { stdout: files } = await execa('git', [
|
||||
@@ -26,15 +22,6 @@ export const getStagedFiles = async (): Promise<string[]> => {
|
||||
|
||||
if (!files) return [];
|
||||
|
||||
const excludedFiles = files
|
||||
.split('\n')
|
||||
.filter(Boolean)
|
||||
.filter((file) => file.includes('.lock') || file.includes('-lock.'));
|
||||
|
||||
if (excludedFiles.length === files.split('\n').length) {
|
||||
showSomeFilesExcludedMessage(files.split('\n'));
|
||||
}
|
||||
|
||||
return files.split('\n').sort();
|
||||
};
|
||||
|
||||
@@ -50,41 +37,33 @@ export const getChangedFiles = async (): Promise<string[]> => {
|
||||
(file) => !!file
|
||||
);
|
||||
|
||||
const filesWithoutLocks = files.filter(
|
||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
||||
);
|
||||
|
||||
if (files.length !== filesWithoutLocks.length) {
|
||||
showSomeFilesExcludedMessage(files);
|
||||
}
|
||||
|
||||
return filesWithoutLocks.sort();
|
||||
return files.sort();
|
||||
};
|
||||
|
||||
export const gitAdd = async ({ files }: { files: string[] }) => {
|
||||
const filteredFiles = files.filter(
|
||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
||||
);
|
||||
|
||||
const gitAddSpinner = spinner();
|
||||
gitAddSpinner.start('Adding files to commit');
|
||||
await execa('git', ['add', ...filteredFiles]);
|
||||
await execa('git', ['add', ...files]);
|
||||
gitAddSpinner.stop('Done');
|
||||
|
||||
if (filteredFiles.length !== files.length) {
|
||||
showSomeFilesExcludedMessage(files);
|
||||
}
|
||||
};
|
||||
|
||||
export const getDiff = async ({ files }: { files: string[] }) => {
|
||||
const lockFiles = files.filter(
|
||||
(file) => file.includes('.lock') || file.includes('-lock.')
|
||||
);
|
||||
|
||||
if (lockFiles.length) {
|
||||
outro(
|
||||
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
|
||||
'\n'
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
const filesWithoutLocks = files.filter(
|
||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
||||
);
|
||||
|
||||
if (filesWithoutLocks.length !== files.length) {
|
||||
showSomeFilesExcludedMessage(files);
|
||||
}
|
||||
|
||||
const { stdout: diff } = await execa('git', [
|
||||
'diff',
|
||||
'--staged',
|
||||
|
||||
Reference in New Issue
Block a user