Skip to content

prompt-cli: check stage before entering prompt  #51

Closed
@marionebl

Description

@marionebl

@commitlint/prompt-cli fails for empty git stages after authoring the commit message. This makes for a frustrating experience.

Check if there are files in stage before entering the prompt.


Edit

The implementation for this should happen before this line: @commitlint/prompt-cli/cli.js#L21

main could look like this:

async function main() {
  if (await isStageEmpty())  {
    console.log(`Nothing to commit. Stage your changes via "git add" execute "commit" again`);
    process.exit(1);
  }

  return prompt();
}

async function isStageEmpty() {
   const result = await execa('git', ['diff', '--cached']);
   return result.stdout === '';
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions