Skip to content

Commit 04768b8

Browse files
di-sukharevzenobit
authored andcommitted
style(commit.ts): format code with prettier
refactor(commit.ts): add types to commit function parameters fix(git.ts): handle empty string returned from getStagedFiles function refactor(mergeStrings.ts): remove unnecessary blank line and add missing semicolon
1 parent a637a02 commit 04768b8

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/commands/commit.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ ${chalk.grey('——————————————————')}`
6060
});
6161

6262
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
63-
const { stdout } = await execa('git', ['commit', '-m', commitMessage, ...extraArgs]);
63+
const { stdout } = await execa('git', [
64+
'commit',
65+
'-m',
66+
commitMessage,
67+
...extraArgs
68+
]);
6469

6570
outro(`${chalk.green('✔')} successfully committed`);
6671

@@ -83,8 +88,10 @@ ${chalk.grey('——————————————————')}`
8388
} else outro(`${chalk.gray('✖')} process cancelled`);
8489
};
8590

86-
87-
export async function commit(extraArgs=[], isStageAllFlag = false) {
91+
export async function commit(
92+
extraArgs: string[] = [],
93+
isStageAllFlag: Boolean = false
94+
) {
8895
if (isStageAllFlag) {
8996
const changedFiles = await getChangedFiles();
9097

@@ -123,7 +130,6 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
123130
isStageAllAndCommitConfirmedByUser &&
124131
!isCancel(isStageAllAndCommitConfirmedByUser)
125132
) {
126-
127133
await commit(extraArgs, true);
128134
process.exit(1);
129135
}
@@ -153,7 +159,10 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
153159
);
154160

155161
const [, generateCommitError] = await trytm(
156-
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs)
162+
generateCommitMessageFromGitDiff(
163+
await getDiff({ files: stagedFiles }),
164+
extraArgs
165+
)
157166
);
158167

159168
if (generateCommitError) {

src/utils/git.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@ export const getOpenCommitIgnore = (): Ignore => {
2020

2121
try {
2222
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
23-
} catch(e) {}
23+
} catch (e) {}
2424

2525
return ig;
26-
}
26+
};
2727

2828
export const getStagedFiles = async (): Promise<string[]> => {
2929
const { stdout: files } = await execa('git', [
3030
'diff',
3131
'--name-only',
32-
'--cached',
32+
'--cached'
3333
]);
3434

35-
const filesList = files.split('\n');
35+
if (!files) return [];
3636

37+
const filesList = files.split('\n');
3738

3839
const ig = getOpenCommitIgnore();
39-
const allowedFiles = filesList.filter(file => !ig.ignores(file));
40+
const allowedFiles = filesList.filter((file) => !ig.ignores(file));
4041

4142
if (!allowedFiles) return [];
4243

@@ -85,6 +86,7 @@ export const getDiff = async ({ files }: { files: string[] }) => {
8586
const { stdout: diff } = await execa('git', [
8687
'diff',
8788
'--staged',
89+
'--',
8890
...filesWithoutLocks
8991
]);
9092

src/utils/mergeStrings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export function mergeStrings(arr: string[], maxStringLength: number): string[] {
99
currentItem = item;
1010
}
1111
}
12+
1213
mergedArr.push(currentItem);
14+
1315
return mergedArr;
1416
}

0 commit comments

Comments
 (0)