Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Check for staged files prior to spawning the prompt #818

Merged

Conversation

ognjenjevremovic
Copy link
Contributor

Fixes #785 and #585 (since the cause of these issues was related)

Changes

  • Checks the staging area prior to spawning the prompt when running git-cz,
  • If no files are present in the staging area (prior to running git-cz command) throw "No files added to staging!" error ,
  • Preserve the functionality of the git -a flag (--all) - running git-cz --all should add all the changed files to the staging area prior to spawning the prompt (no error thrown),
  • Provided the necessary set tests for this change.

Checklist

After the changes I ensured that:

  • no stylistic or unwanted errors are present (by following the conventions described in the CONTRIBUTING.md),
  • no tests are failing, by running npm run test,
  • build passes with no issues, by running npm run build,
  • checked the build output locally by:
    • initializing a new npm & git repository (mkdir test && cd test && npm init -y && git init),
    • locally built the cz-cli package by running npm run build, from within cz-cli directory,
    • made a few changes in the dummy project files,
    • run the command node /path/to/cz-cli/project/bin/git-cz (with and without —all flag, in different case scenarios),
    • ensured everything works as expected.

Done

  • Added/updated unit tests for this change
  • Included links to related issues/PRs

Ognjen Jevremovic added 3 commits March 25, 2021 18:43
Check for staged files before running the prompt. Running the `git-cz` command with no files staged
reports "No files added to staging". Preserve the functionality of `git -a` (--all) flag - `git-cz
-a` command with no files added to staging area, adds all files to staging and opens the prompt (no
error thrown).

"fix commitizen#785"
Extend upon the existing commit unit tests. Assert the error is thrown when running commitizen
commit command with no files add to staging.

"re commitizen#585"
Extend upon the existing staging unit tests. Assert that the files are added to staging area when
running commitizen commit command with -a (--all) flag, prior to spawning the prompt.

"re commitizen#785"
@amaltson
Copy link

amaltson commented Apr 23, 2021

Love this, thank you for adding it! I run into this several times a day because I'm used to running git commit -a, but forget to add -a to commitizen. It's definitely super frustrating to fill out the questionnaire and then have it do nothing b/c I forgot to stage files. This would preserve the behaviour that Git itself has:

$ git commit
On branch properly-approve-rfc-33
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   ... the files that are unstaged ...

no changes added to commit (use "git add" and/or "git commit -a")

@ognjenjevremovic
Copy link
Contributor Author

Any updates on the PR review?

@amaltson
Copy link

amaltson commented Nov 7, 2021

Yeah this would be awesome to get a review of this, thank you!

@LinusU LinusU merged commit fdb73cd into commitizen:master Nov 8, 2021
@LinusU
Copy link
Contributor

LinusU commented Nov 8, 2021

Thanks! Sorry for the delay on this

@amaltson
Copy link

amaltson commented Nov 8, 2021

👏 yay! Thank you so much! Can't wait for this to be released, appreciate all the hard work @LinusU!

@github-actions
Copy link

🎉 This PR is included in version 4.2.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants