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
31 pre commit docs #36
Conversation
docs/pre-commit.md
Outdated
### 3 versions of every file that make up our git authoring lifecycle (HEAD, Staged, Unstaged) | ||
|
||
### Running the pre-commit hook directly from the .git folder | ||
- run `bash .git/hooks/pre-commit` to execute pre-commit hook without committing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I figured out why this didn't work as expected for me yesterday--I believe this command runs the hook only on the files that are staged, and I didn't have anything staged at the time. If you want to run pre-commit on everything in the repo regardless of staging, it's pre-commit run --all-files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly! Let's get that added to the docs so it's clear when we'd choose to run each command?
I think this doc is in a good spot right now, but I'm still open to suggestions. Otherwise let's merge it in! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to ask someone else to look at this too; I found some parts confusing but that might just be because I'm new to pre-commit
docs/pre-commit.md
Outdated
- Install: | ||
- Using pip: `pip install pre-commit` | ||
- Using Homebrew: `brew install pre-commit` | ||
|
||
- Setup | ||
- run `pre-commit install` to set up the git hook script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just link to the pre-commit docs, in case they change their instructions later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fully support both linking to docs and excerpting key text over here (in case the docs are moved or deleted later)
docs/pre-commit.md
Outdated
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If pre-commit only runs on staged contents (2nd sentence), then how would you be a position to run hooks on unstaged changes (1st sentence)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a direct quote from the docs. https://pre-commit.com/#pre-commit-during-commits I'm not sure how to answer that question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way to run hooks on unstaged changes. This is part of the pre-commit design philosophy and is very important: pre-commit has side effects and by only running on staged changes you can always see the difference between what you wrote and what pre-commit changed.
docs/pre-commit.md
Outdated
|
||
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. | ||
|
||
> 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this a quote from? I find it a bit confusing, though that could just be shaky understanding of pre-commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alec quoted this pre-commit/pre-commit#747 (comment), so I'll add a link to give more context
docs/pre-commit.md
Outdated
|
||
> 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. | ||
|
||
Always stage the the changes you intend to commit before running `pre-commit`. If a hook changes our code and fails you will need to manually stage the changes made by `pre-commit`, viewing them one by one with `git add -p` or your preferred git GUI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "before running pre-commit
" mean? Running it with the bash script below? (Once I've done pre-commit install
, it runs automatically every time I try to commit, so everything is always already staged.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
means anytime pre-commit hooks are run, whether running pre-commit explicitly or by committing. but ill clarify it
docs/pre-commit.md
Outdated
|
||
### Write commit a message so it doesn't get blown away by a failed pre-commit hook | ||
|
||
- run `git commit` without a comment when that will then run pre-commit and should it fail you won't lose your commit message. Once it passes it will prompt you to input a commit message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- run `git commit` without a comment when that will then run pre-commit and should it fail you won't lose your commit message. Once it passes it will prompt you to input a commit message. | |
- run `git commit` without a comment and that will then run pre-commit and should it fail you won't lose your commit message. Once it passes it will prompt you to input a commit message. |
docs/pre-commit.md
Outdated
### Write commit a message so it doesn't get blown away by a failed pre-commit hook | ||
|
||
- run `git commit` without a comment when that will then run pre-commit and should it fail you won't lose your commit message. Once it passes it will prompt you to input a commit message. | ||
- **Recomend** on the first commit of a branch to make a commit message body that refs the issue your branch is related. When opening a pull-request this will automatically link your PR to the issue on GitHub. This can be accomplished by creating the commit message in an editor and adding new line at the end of the message and writing `ref #<issue>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **Recomend** on the first commit of a branch to make a commit message body that refs the issue your branch is related. When opening a pull-request this will automatically link your PR to the issue on GitHub. This can be accomplished by creating the commit message in an editor and adding new line at the end of the message and writing `ref #<issue>` | |
- **Recomend** on the first commit of a branch, make a commit message body that refs the issue your branch is related to. When opening a pull-request this will automatically link your PR to the issue on GitHub. This can be accomplished by creating the commit message in an editor and adding new line at the end of the message and writing `ref #<issue>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you can end sentences with prepositions, I just don't like to. I'll make the change :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any grammar/spelling suggestions from me will only be for clarity--I have no prescriptive feelings about preposition placement, oxford commas, etc.
Co-authored-by: Brianna Cerkiewicz <77306764+BCerki@users.noreply.github.com>
Co-authored-by: Brianna Cerkiewicz <77306764+BCerki@users.noreply.github.com>
PR adds:
Docs relating to using pre-commit locally