Skip to content

File stage checker not working as expected #418

Closed
@xaviml

Description

@xaviml

Description

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:

  1. Edit an existing file
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions