( extraArgs: string[] = [], context: string = '', isStageAllFlag: Boolean = false, fullGitMojiSpec: boolean = false, skipCommitConfirmation: boolean = false )
| 264 | }; |
| 265 | |
| 266 | export async function commit( |
| 267 | extraArgs: string[] = [], |
| 268 | context: string = '', |
| 269 | isStageAllFlag: Boolean = false, |
| 270 | fullGitMojiSpec: boolean = false, |
| 271 | skipCommitConfirmation: boolean = false |
| 272 | ) { |
| 273 | if (isStageAllFlag) { |
| 274 | const changedFiles = await getChangedFiles(); |
| 275 | |
| 276 | if (changedFiles) await gitAdd({ files: changedFiles }); |
| 277 | else { |
| 278 | outro('No changes detected, write some code and run `oco` again'); |
| 279 | process.exit(1); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | const [stagedFiles, errorStagedFiles] = await trytm(getStagedFiles()); |
| 284 | const [changedFiles, errorChangedFiles] = await trytm(getChangedFiles()); |
| 285 | |
| 286 | if (!changedFiles?.length && !stagedFiles?.length) { |
| 287 | outro(chalk.red('No changes detected')); |
| 288 | process.exit(1); |
| 289 | } |
| 290 | |
| 291 | intro('open-commit'); |
| 292 | if (errorChangedFiles ?? errorStagedFiles) { |
| 293 | outro(`${chalk.red('✖')} ${errorChangedFiles ?? errorStagedFiles}`); |
| 294 | process.exit(1); |
| 295 | } |
| 296 | |
| 297 | const stagedFilesSpinner = spinner(); |
| 298 | |
| 299 | stagedFilesSpinner.start('Counting staged files'); |
| 300 | |
| 301 | if (stagedFiles.length === 0) { |
| 302 | stagedFilesSpinner.stop('No files are staged'); |
| 303 | |
| 304 | const isStageAllAndCommitConfirmedByUser = await confirm({ |
| 305 | message: 'Do you want to stage all files and generate commit message?' |
| 306 | }); |
| 307 | |
| 308 | if (isCancel(isStageAllAndCommitConfirmedByUser)) process.exit(1); |
| 309 | |
| 310 | if (isStageAllAndCommitConfirmedByUser) { |
| 311 | await commit(extraArgs, context, true, fullGitMojiSpec); |
| 312 | process.exit(0); |
| 313 | } |
| 314 | |
| 315 | if (stagedFiles.length === 0 && changedFiles.length > 0) { |
| 316 | const files = (await multiselect({ |
| 317 | message: chalk.cyan('Select the files you want to add to the commit:'), |
| 318 | options: changedFiles.map((file) => ({ |
| 319 | value: file, |
| 320 | label: file |
| 321 | })) |
| 322 | })) as string[]; |
| 323 |
no test coverage detected
searching dependent graphs…