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.

feature: Skip some hooks when using `--all-files`

See original GitHub issue

I realize this may be a pretty far-fetched request, but I figured it couldn’t hurt to start a discussion.

We’d like a configurable way to disable some hooks from running when using pre-commit run --all-files. However, the hook should still run when --all-files is not supplied or when it is explicitly specified as an arg.

Use Case

We have a monorepo and some hooks (like terraform) have special dependencies that aren’t always managed or installed by pre-commit. The files that the hooks run on are isolated to a specific folder. Most teams never interact with these files, but if they do, the hooks should trigger.

Occasionally, we like to run pre-commit run --all-files as hooks (or their dependencies) are upgraded to ensure everything is still passing. A recent example of why this may be needed was when we upgraded black and had files that were reformatted after the upgrade.

We periodically run into issues where engineers don’t have the correct setup and those special hooks fail, resulting in confusion and blocked progress.

Workarounds

I realize that we could use SKIP for this. The issue is that SKIP is opt-in and not configurable via .pre-commit-config.yaml. This means that the whole engineering team needs to set the variable and then unset it when they want to run the team-specific hooks. What we’d like to is sort of the opposite, have hooks that are skipped by default but can be opted-into.

Risks

I realize this is a slippery slope and may not even be possible with the current architecture (I’m guilty of not taking a deeper look into the codebase yet). There’s definitely a chance files get committed that should have been linted. We hope that by limiting the skipping to just the bare pre-commit run --all-files that this chance is sufficiently small that it is an acceptable trade off.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jalazizcommented, Feb 17, 2022

yeah I just mean you could have ./pre-commit-run-all-files which is just #!/usr/bin/env bash\nexec SKIP=... pre-commit run --all-files

Yup. Was hoping to keep it contained within the workflow of pre-commit (to avoid the inevitable person who doesn’t search internal docs first), but I completely understand it not being worth implementing.

1reaction
jalazizcommented, Feb 17, 2022

--all-files is a conscious decision to run, so you’d only run the script in that case

I think this is where the issue lies. We want to not run something in that case and run that same something in all other cases.

Yes, it’s a conscious decision, but that doesn’t mean an entire engineering organization is aware that they should set SKIP in their local environment.

Ultimately, it seems like the workaround is a script that sets SKIP and trying to educate users to use that script instead of pre-commit run --all-files.

Thank you for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run hooks on files in specific dir, rather than using `--all-files`
Now, I'm trying to run the hooks just on files in a particular directory. I think I'm not understanding the docs and I...
Read more >
pre-commit: Various Ways to Run Hooks - Adam Johnson
Commit Whilst Skipping All Hooks · Commit Whilst Skipping A Few Hooks · Run All Hooks Against Staged Files · Run One Hook...
Read more >
git hook to batch unstage all files in a path
Here is a solution that seems to work. Simply add to .git/hooks/pre-commit the following: git reset -- devlog/*.
Read more >
.gitignore file - ignoring files in Git | Atlassian Git Tutorial
Git ignore patterns are used to exclude certain files in your working directory from your Git history. They can be local, global, or...
Read more >
pre-commit
We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements....
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