From d4fc651fec32b27ae5210d7fbc42178f6e47ecb0 Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Thu, 16 Mar 2023 23:41:08 +0800 Subject: [PATCH] refactor(git.ts): remove unused code and simplify getDiff function feat(git.ts): add message for excluded lock files in getDiff function --- package-lock.json | 1 - src/utils/git.ts | 55 +++++++++++++++-------------------------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index 729f0f6..e6ec109 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,7 +61,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/src/utils/git.ts b/src/utils/git.ts index e65d8a9..3f3dfc8 100644 --- a/src/utils/git.ts +++ b/src/utils/git.ts @@ -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 => { const { stdout: files } = await execa('git', [ @@ -26,15 +22,6 @@ export const getStagedFiles = async (): Promise => { 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 => { (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',