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

Black pre-commit git hook persistent fail status #17

Closed
felipepenha opened this issue Mar 25, 2021 · 4 comments · Fixed by #19 or #20
Closed

Black pre-commit git hook persistent fail status #17

felipepenha opened this issue Mar 25, 2021 · 4 comments · Fixed by #19 or #20
Labels
bug Something isn't working

Comments

@felipepenha
Copy link
Owner

When trying to commit, pre-commit runs and alters python files. When you try running git commit again, it fails yielding a warning

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files ...

This issue was detected during a Twitch live stream. The solution was found minutes later, and will be posted in the comments below.

@felipepenha
Copy link
Owner Author

felipepenha commented Mar 25, 2021

The solution is realizing that due to changes made by black, it is necessary to repeat the operation git add. Thus, the workflow is as follows:

$ git add [file]
$ git commit -m "[message]"
black........................Failed
reformatted [file]
All done! ✨ 🍰 ✨
1 file reformatted.
$ git add -u
$ git commit -m "[message]"
black........................Passed
``
`git add -u` only adds currently tracked files (which have been modified) to the staging area and also checks if they have been deleted (if yes, they are removed from staging area). This means that it does not stage new files.

@felipepenha
Copy link
Owner Author

felipepenha commented Mar 25, 2021

Related issues in the pre-commit repo:
pre-commit/pre-commit#806
pre-commit/pre-commit#747
pre-commit/pre-commit#879

In stackoverflow, including a response from the author of pre-commit:
https://stackoverflow.com/questions/58398995/black-as-pre-commit-hook-always-fails-my-commits

@felipepenha
Copy link
Owner Author

To Do: find out whether it is feasible to include git add -u in the hook itself.

felipepenha added a commit that referenced this issue Mar 25, 2021
Pre-commit failing with black Issue #17 fixed
@felipepenha felipepenha linked a pull request Mar 25, 2021 that will close this issue
@felipepenha
Copy link
Owner Author

Solution for pre-commit failing with black Issue #17: sequence of commands defined via make add-commit.

@felipepenha felipepenha added the bug Something isn't working label Mar 25, 2021
@felipepenha felipepenha linked a pull request Mar 25, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant