File stage checker not working as expected
See original GitHub issueDescription
If we have changed files not staged, and not staged files, then I don’t get the “No files added to staging!”.
Steps to reproduce
Assuming you have a project with commitizen installed and the project is tracked by git, then we can do:
- Edit an existing file
- Run
cz commit
Current behavior
The questionnaire will pop up without erroring out with No files added to staging!
since no files are yet added to stage.
Desired behavior
The desired behaviour should be what the error says (“No files added to staging!”), so if no files are added to the stage, then the error should pop.
Environment
- commitizen version: 2.17.11
- python version: Python 3.7.9
- operating system: Linux
This is an application bug, so it happens with any Python version and OS.
Extra
This issue is related to #45 (fixed in #49), which was the original issue related to this problem, but in my opinion, was never fixed the right way. I am not randomly opening this issue, I am doing it because I bumped into this frustrating problem all the time where:
- I run
cz commit
- Fill the questionnaire (~1 minute)
- Pre-commit runs (~1 minute)
- Get an error because the stage is empty
- Then, I have to stage the files, and run
cz commit --retry
It seems that this was deliberately done in the code since just this command is needed:
git diff --no-ext-diff --cached --name-only
The no-cached one will pick up files that are unstaged. In fact, in the more recent versions of git
one can use --staged
flag which is an alias for --cached
.
I understand if this was picked up from here in cz-cli, but it has the same problem in there, and this PR is a proposal for the fix in that repo (not yet merged).
If this is a recognized bug, and we are willing to fix it, I offer myself to open the PR if needed.
Thank you for the great work and this amazing tool!
Regards, Xavi M.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
I created #420, we can review changes in there.
Hi both,
This is not a bad idea. This is what commitizen/cz-cli already has, and the fix for commitizen/cz-cli#818 will:
git diff --no-ext-diff --cached --name-only
if there are staged filesgit diff --no-ext-diff --cached --name-only
andgit diff --no-ext-diff --name-only
if the-a
is passed forgit
args likecz commit -- -a
as you suggested.Considering this commitizen does not have the option for
git
args, the solution to this problem is removing the checkgit diff --no-ext-diff --name-only
and leave only the--cached
one:Does this make sense to you both?
Regards, Xavi M.