Skip to content

Commit ec2e4c6

Browse files
committed
fix(commit.ts): fix typo in outro message
feat(commit.ts): add support for staging all files and generating commit message when no files are staged feat(commit.ts): add support for committing changes when no files are staged and some files are changed but not staged
1 parent c787329 commit ec2e4c6

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

src/commands/commit.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ ${chalk.grey('——————————————————')}`
6060

6161
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
6262
const { stdout } = await execa('git', ['commit', '-m', commitMessage]);
63+
6364
outro(`${chalk.green('✔')} successfully committed`);
65+
6466
outro(stdout);
67+
6568
const isPushConfirmedByUser = await confirm({
6669
message: 'Do you want to run `git push`?'
6770
});
@@ -83,8 +86,8 @@ export async function commit(isStageAllFlag = false) {
8386
const changedFiles = await getChangedFiles();
8487
if (changedFiles) await gitAdd({ files: changedFiles });
8588
else {
86-
outro("No changes detected, write some code and run `oc` again");
87-
process.exit(1);
89+
outro('No changes detected, write some code and run `oc` again');
90+
process.exit(1);
8891
}
8992
}
9093

@@ -105,29 +108,7 @@ export async function commit(isStageAllFlag = false) {
105108
const stagedFilesSpinner = spinner();
106109
stagedFilesSpinner.start('Counting staged files');
107110

108-
if (!stagedFiles.length && isStageAllFlag) {
109-
outro(
110-
`${chalk.red(
111-
'No changes detected'
112-
)} — write some code, stage the files ${chalk
113-
.hex('0000FF')
114-
.bold('`git add .`')} and rerun ${chalk
115-
.hex('0000FF')
116-
.bold('`oc`')} command.`
117-
);
118-
119-
process.exit(1);
120-
}
121-
122111
if (!stagedFiles.length) {
123-
outro(
124-
`${chalk.red('Nothing to commit')} — stage the files ${chalk
125-
.hex('0000FF')
126-
.bold('`git add .`')} and rerun ${chalk
127-
.hex('0000FF')
128-
.bold('`oc`')} command.`
129-
);
130-
131112
stagedFilesSpinner.stop('No files are staged');
132113
const isStageAllAndCommitConfirmedByUser = await confirm({
133114
message: 'Do you want to stage all files and generate commit message?'
@@ -137,7 +118,8 @@ export async function commit(isStageAllFlag = false) {
137118
isStageAllAndCommitConfirmedByUser &&
138119
!isCancel(isStageAllAndCommitConfirmedByUser)
139120
) {
140-
return await commit(true);
121+
await commit(true);
122+
process.exit(1);
141123
}
142124

143125
if (stagedFiles.length === 0 && changedFiles.length > 0) {
@@ -154,7 +136,8 @@ export async function commit(isStageAllFlag = false) {
154136
await gitAdd({ files });
155137
}
156138

157-
commit(false);
139+
await commit(false);
140+
process.exit(1);
158141
}
159142

160143
stagedFilesSpinner.stop(

0 commit comments

Comments
 (0)