question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File stage checker not working as expected

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xavimlcommented, Sep 11, 2021

I created #420, we can review changes in there.

0reactions
xavimlcommented, Sep 11, 2021

Hi both,

Given the need to propagate many different flags to git commit, one idea we have is to use --, something like this:

This is not a bad idea. This is what commitizen/cz-cli already has, and the fix for commitizen/cz-cli#818 will:

  • Check with git diff --no-ext-diff --cached --name-only if there are staged files
  • Check with git diff --no-ext-diff --cached --name-only and git diff --no-ext-diff --name-only if the -a is passed for git args like cz commit -- -a as you suggested.

Considering this commitizen does not have the option for git args, the solution to this problem is removing the check git diff --no-ext-diff --name-only and leave only the --cached one:

def is_staging_clean() -> bool:
    """Check if staing is clean."""
    c = cmd.run("git diff --no-ext-diff --cached --name-only")
    return not bool(c.out)

Does this make sense to you both?

Regards, Xavi M.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix It When Spell Check Is Not Working in Word - Lifewire
The spell-check tool might not work as expected if a user has made exceptions for checking the spelling or grammar. Open Word in...
Read more >
Troubleshoot checking spelling and grammar in multiple ...
Checking spelling and grammar in multiple languages can present unique problems, such as correctly spelled words being flagged as incorrect, or misspelled ...
Read more >
6 Ways to Fix SFC SCANNOW Cannot Repair Corrupted Files
Step 1. Right-click the target partition that has a problem. Step 2. Choose "Advanced" > "Check File System". Step 3.
Read more >
Microsoft Word Spell Check Not Working? (5 Solutions)
1. Click the File tab. 2. From the left menu, select Options at the bottom. 3. In the Word Options dialog, click Proofing....
Read more >
Troubleshoot scanner issues when scanning using Acrobat
Fixes for the common issues that occur when you scan from Adobe Acrobat.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found