Questions tagged [pre-commit]

Pre-commit is an action taken prior to committing your code into a version control system.

A pre-commit is an action that would be applied to source code before it is committed to the version control system. To utilize a pre-commit action you'll need to install a pre-commit hook into the repository. Pre-commit hooks are available in most commonly used version control systems such as SVN or git.

Some actions that could be achieved using pre-commit hooks:

  1. Fixing case issues in file names
  2. Validating file content, such as executing a linter or code convention checker.
  3. Preventing specific users from committing code

pre-commit is also the name of a framework for managing such hooks for git.

406 questions
8
votes
1 answer

Pylint ignore file with git-pylint-commit-hook

Im using pylint 1.6.4 and git-pylint-commit-hook 2.1.1 to lint my files on pre-commit. I also use alembic to generate my migrations, they are stored in /migrations/versions. The problem is that the generated migrations are not valid…
Jakub Tesárek
  • 136
  • 1
  • 6
7
votes
5 answers

What to stage after a pre-commit hook was run?

For a pre-commit hook that modifies the staged files, I need to figure out what has to be staged after the hook was run. The pre-commit hook applies some pretty-printing on the files that should be committed. The hook does the following…
eckes
  • 64,417
  • 29
  • 168
  • 201
7
votes
3 answers

Cowardly refusing to install hooks with `core.hooksPath` set

i tried to run this command but it always show this error, i can't fix it with anyway. Help me, please! (venv)<...>pre-commit install [ERROR] Cowardly refusing to install hooks with core.hooksPath set. hint: git config --unset-all core.hooksPath
Hữu Tuân
  • 81
  • 1
  • 3
7
votes
2 answers

The hook `black` requires pre-commit version 2.9.2 but version 2.6.0 is installed

I am having trouble with pre-commit and black. Everything worked fine until I cleared the cache with pre-commit clean. Now I always get the error The hook black requires pre-commit version 2.9.2 but version 2.6.0 is installed. Perhaps run `pip…
shadow
  • 151
  • 2
  • 12
7
votes
1 answer

pre-commit hook to check django migrations

I'm trying to write a pre-commit hook to my Django project that checks for missing migrations. That is, it ensures all changes are reflected in a migrations file. One way to implement this is to PASS the pre-commit hook if the makemigrations command…
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
7
votes
1 answer

Is it possible to add a "Precommit hook" on TFS?

We want every person that does a push in our git repository to run "grunt" before this is done. We enforce this by having a pre-push hook in .git/hooks/pre-push and writing npm install and grunt in that file. We also have a TFS repository. I am…
user3086725
  • 91
  • 1
  • 5
6
votes
2 answers

How to configure pre-commit-config.yaml to work with poetry?

I am on Python 3.10.4 here and using a .pre-commit-config.yaml file in my Poetry 1.1.13 project that uses pyproject.toml Here is what my .pre-commit-config.yaml looks like # See https://pre-commit.com for more information # See…
PirateApp
  • 5,433
  • 4
  • 57
  • 90
6
votes
2 answers

Access python interpreter in VSCode version controll when using pre-commit

I'm using pre-commit for most of my Python projects, and in many of them, I need to use pylint as a local repo. When I want to commit, I always have to activate python venv and then commit; otherwise, I'll get the following…
Mehdi
  • 1,260
  • 2
  • 16
  • 36
6
votes
2 answers

pre-commit giving error with mirrors-mypy, how do I fix it?

I am getting the below error when running "pre-commit run --all-files" and when trying to make a commit, it is some python error, python version in use is "Python 2.7.16". [INFO] Installing environment for…
6
votes
3 answers

env: python3.9: No such file or directory

I have some python code formatters as git pre-commit hook and I have changed my python version as brew list | grep python python@3.7 python@3.9 brew unlink python@3.7 brew unlink python@3.9 brew link python@3.7 python -V Python 3.7.9 and know…
mrgloom
  • 20,061
  • 36
  • 171
  • 301
6
votes
1 answer

CalledProcessError with git pre-commit hook

I'm hitting a snag installing pre-commit hooks. Based on the error below, the hook installation cannot find a python exe in the directory C:\\Users\\dangler\\.cache\\pre-commit\\repoith5dg7x\\py_env-default\\Scripts\\python.EXE (python.EXE doesn't…
Danlger
  • 143
  • 1
  • 1
  • 7
6
votes
1 answer

User permissions for add/remove a file/folder in svn

I have a requirement that I need to control the permission to add/delete(not read/modify/write) a file in svn. I checked if svn access control has ways to do it. But it does not seems to have this kind of restriction. I was checking for some…
6
votes
3 answers

(GitKraken) Pre-commit Failed Exit Code: 1

I'm using GitKraken (not sure if relevant) and as I'm trying to commit, I get this error message: And as I press the button "View Hook Output" I get the following: pre-commit husky > npm run -s precommit (node v8.9.4)[?25l npm > Running tasks for…
Steve Waters
  • 3,348
  • 9
  • 54
  • 94
6
votes
2 answers

specify which hook to skip on git commit --no-verify

If there a way to specify exactly which git-hook to skip when using --no-verify? Or is there another flag other than --no-verify to accomplish this? Perhaps just a flag to only skip pre-commit? I have two hooks that I regularly use, pre-commit and…
Jeremy
  • 1,717
  • 5
  • 30
  • 49
6
votes
3 answers

Temporarily clearing untracked files before commit in Git

Whenever I commit, I worry that I may have missed out a dependency and I'm looking for the simplest way to test my git tree in isolation to ensure whatever is in the git index ("staged") will in fact compile/run on their own. My code's dependencies…
Ash
  • 1,266
  • 4
  • 14
  • 24