Pre-commit: Make statement about staging files on pre-commit.com

Created on 19 Dec 2019  路  4Comments  路  Source: pre-commit/pre-commit

I've found out that pre-commit does not allow any plugin to directly modify commits. I was developing my small utility to do one simple task before push and I have to run git diff + git add -u + git commit --amend manually for one place to be changed.

I would like to ask, what is a point of using pre-commit if I can just have the same results with just running linters in VSCode on every save?

Git is doing auto CRLF shenanigans for ages and I would imagine if this would work in the same way as pre-commit, it would make people crazy. Commit is not a guarantee that things will work or that quality is guaranteed - we have CI, code reviews and staging for that.

Auto-formatting went through because tools like gofmt and black does not ask questions, they simply do the job.

At least this behavior should be clear on the pre-commit hooks developing page.

question

Most helpful comment

@alkuzad please chill out, I understand you're frustrated but please use more amenable language -- "what is the point" is not an acceptable way to talk to anyone and I'd encourage you to improve that demeanor, especially when addressing those providing you _free software_. The truth is, we don't owe you shit and if you're going to be disrespectful you're asking for a close / ignore.

as you may have found via - searching - the - issue - tracker, it is not just a stance on safety but also on correctness. if pre-commit were to stage files during an autofix it could not support partial commits (what if the autofix conflicted with partially staged contents?)

if you'd like, I'd encourage you to commit some documentation for this as you've suggested -- the documentation repository exists at https://github.com/pre-commit/pre-commit.github.io -- what do you think?

All 4 comments

In my experience, standardizing pre-commit hooks and configuration is easier than standardizing editor configurations. Also, pre-commit pre-dates lot of auto-formatting tools, even though those are becoming more popular. To have your hook block a commit, it just needs to return a non-zero status code if it modifies anything. You'll still need to git add and then commit again, but you don't need to --amend anything.

That said, the issue of pre-commit refusing (correctly IMO) to stage and include changes in a commit is a common one, and may be worth calling out in the docs.

@alkuzad please chill out, I understand you're frustrated but please use more amenable language -- "what is the point" is not an acceptable way to talk to anyone and I'd encourage you to improve that demeanor, especially when addressing those providing you _free software_. The truth is, we don't owe you shit and if you're going to be disrespectful you're asking for a close / ignore.

as you may have found via - searching - the - issue - tracker, it is not just a stance on safety but also on correctness. if pre-commit were to stage files during an autofix it could not support partial commits (what if the autofix conflicted with partially staged contents?)

if you'd like, I'd encourage you to commit some documentation for this as you've suggested -- the documentation repository exists at https://github.com/pre-commit/pre-commit.github.io -- what do you think?

@gtback amend is needed as this is pre-push hook :) And yeah I was experimenting with mypy and black but actually they rarely fire due to VScode showing all errors first. I see there are a lot more checks that are available in code editor, but I don't see ones that would change my life, maybe the git conflicts checker :)

@asottile

I think "own you shit" is far more unacceptable than "what is the point". The one seems frustrated is clearly you and I understand that this issue is bumping from time to time on gh. This is why I want to give clear docs on that on the material devs read first - how to write the stuff doc. This is what this ticket is about - to rise this issue to the place it belongs as not only me is confused by this behavior.

I actually never stumbled across #922 and I found it only because you used keyword - "autofix", which by fast ddg search, appears only on github and is known by people accustomed to pre-commit and it's behaviors, I've stumbled on it not so long ago.

Partial commits can be there but also is corner case that can be detected and this could lead to current behavior.

If you would have "edit this page on GitHub" button I would probably open a ticket there in the first place. I would love to clarify that but when digging through the repos I've found pre-commit was not designed this way from the beginning so I'm not the best to explain why it is done this way:

https://github.com/pre-commit/pre-commit/issues/392
https://github.com/psf/black/issues/103#issuecomment-378682178
https://github.com/pre-commit/pre-commit/issues/806

it has always been this way, I'll write something up -- thanks for the issue -- just next time please be nicer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

metmajer picture metmajer  路  4Comments

DaveParr picture DaveParr  路  4Comments

jeunii picture jeunii  路  3Comments

jacobseiler picture jacobseiler  路  4Comments

hectorv picture hectorv  路  3Comments