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

Working with pre-commit #31

Closed
wenzowski opened this issue Dec 2, 2021 · 3 comments · Fixed by #36
Closed

Working with pre-commit #31

wenzowski opened this issue Dec 2, 2021 · 3 comments · Fixed by #36
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@wenzowski
Copy link

@BryanGK any notes/tips from our call on pre-commit that can be recorded in the repo docs? Maybe a bit about the 3 versions of every file that make up our git authoring lifecycle (HEAD, Staged, Unstaged), a bit about running hooks directly from the .git folder, thoughts on how to respond to failed pre-commit hooks, and/or something about when/where to write commit messages so they don't get blown away by a failed pre-commit hook?

@wenzowski wenzowski added the documentation Improvements or additions to documentation label Dec 2, 2021
@BryanGK
Copy link

BryanGK commented Dec 2, 2021

I'll create a pre-commit.md in the docs folder and let me see what I put together.

@BryanGK
Copy link

BryanGK commented Dec 3, 2021

@wenzowski I'm putting together the docs for this issue but I can't quite remember what you said re: the git authoring lifecycle. It was something like pre-commit won't run on unstage files, is that correct? Is there anything else to add? Would you happen to have some docs I can read about it?

I'll push up what I have so far and link back to this issue, if you wouldn't mind giving me some ideas of how I can make it better would be much appreciated.

BryanGK added a commit that referenced this issue Dec 3, 2021
@BryanGK BryanGK linked a pull request Dec 3, 2021 that will close this issue
@wenzowski
Copy link
Author

wenzowski commented Dec 3, 2021

Running hooks on unstaged changes can lead to both false-positives and false-negatives during committing. pre-commit only runs on the staged contents of files by temporarily saving the contents of your files at commit time and stashing the unstaged changes while running hooks.
https://pre-commit.com/#pre-commit-during-commits

pre-commit itself will never touch the staging area. These are good ways to silently break commits. In my mind this is one of the worst things that lint-staged does and suggests -- hooks are very frequently not perfect and magically changing what's being committed should not be taken lightly.
pre-commit/pre-commit#747 (comment)

So when working with pre-commit we need to always have staged all the changes we intend to commit, and if a hook that changes our code fails we need to go through and manually stage the changes made by pre-commit, preferably reviewing them as we go with, say, git add -p otherwise we won't be able to commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants