Skip to content

Commit d4fc651

Browse files
committed
refactor(git.ts): remove unused code and simplify getDiff function
feat(git.ts): add message for excluded lock files in getDiff function
1 parent 04d40b5 commit d4fc651

File tree

2 files changed

+17
-39
lines changed

2 files changed

+17
-39
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/git.ts

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ export const assertGitRepo = async () => {
99
}
1010
};
1111

12-
export const showSomeFilesExcludedMessage = (files: string[]) => {
13-
outro(
14-
`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
15-
.filter((file) => file.includes('.lock') || file.includes('-lock.'))
16-
.join('\n')}`
17-
);
18-
};
12+
// const excludeBigFilesFromDiff = ['*-lock.*', '*.lock'].map(
13+
// (file) => `:(exclude)${file}`
14+
// );
1915

2016
export const getStagedFiles = async (): Promise<string[]> => {
2117
const { stdout: files } = await execa('git', [
@@ -26,15 +22,6 @@ export const getStagedFiles = async (): Promise<string[]> => {
2622

2723
if (!files) return [];
2824

29-
const excludedFiles = files
30-
.split('\n')
31-
.filter(Boolean)
32-
.filter((file) => file.includes('.lock') || file.includes('-lock.'));
33-
34-
if (excludedFiles.length === files.split('\n').length) {
35-
showSomeFilesExcludedMessage(files.split('\n'));
36-
}
37-
3825
return files.split('\n').sort();
3926
};
4027

@@ -50,41 +37,33 @@ export const getChangedFiles = async (): Promise<string[]> => {
5037
(file) => !!file
5138
);
5239

53-
const filesWithoutLocks = files.filter(
54-
(file) => !file.includes('.lock') && !file.includes('-lock.')
55-
);
56-
57-
if (files.length !== filesWithoutLocks.length) {
58-
showSomeFilesExcludedMessage(files);
59-
}
60-
61-
return filesWithoutLocks.sort();
40+
return files.sort();
6241
};
6342

6443
export const gitAdd = async ({ files }: { files: string[] }) => {
65-
const filteredFiles = files.filter(
66-
(file) => !file.includes('.lock') && !file.includes('-lock.')
67-
);
68-
6944
const gitAddSpinner = spinner();
7045
gitAddSpinner.start('Adding files to commit');
71-
await execa('git', ['add', ...filteredFiles]);
46+
await execa('git', ['add', ...files]);
7247
gitAddSpinner.stop('Done');
73-
74-
if (filteredFiles.length !== files.length) {
75-
showSomeFilesExcludedMessage(files);
76-
}
7748
};
7849

7950
export const getDiff = async ({ files }: { files: string[] }) => {
80-
const filesWithoutLocks = files.filter(
81-
(file) => !file.includes('.lock') && !file.includes('-lock.')
51+
const lockFiles = files.filter(
52+
(file) => file.includes('.lock') || file.includes('-lock.')
8253
);
8354

84-
if (filesWithoutLocks.length !== files.length) {
85-
showSomeFilesExcludedMessage(files);
55+
if (lockFiles.length) {
56+
outro(
57+
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
58+
'\n'
59+
)}`
60+
);
8661
}
8762

63+
const filesWithoutLocks = files.filter(
64+
(file) => !file.includes('.lock') && !file.includes('-lock.')
65+
);
66+
8867
const { stdout: diff } = await execa('git', [
8968
'diff',
9069
'--staged',

0 commit comments

Comments
 (0)