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
5
votes
1 answer

What is the format of the deltas in a subversion respository, and how badly can I blow it up if I change them in a pre-commit hook?

Help me do some damage! I'm tired of just a half-dozen Google hits that tell me never to do this. Let's muck things up real good! I'm pretty sure that I can get ahold of the actual files in db/transactions, so how can I screw these up in interesting…
John O
  • 4,863
  • 8
  • 45
  • 78
5
votes
1 answer

Run mypy from pre-commit for different directories

I have the following structure for my project: project/ ├── backend │   ├── api_v1 │   ├── api_v2 │   └── api_v3 └── frontend Each of the API dirs, api_v1, api_v2, and api_v3, have python files. I would like to run pre-commit for each of these…
npk
  • 1,512
  • 1
  • 13
  • 26
5
votes
2 answers

Uninstalled pre-commit preventing 'git commit' (pipenv)

I recently uninstalled pre-commit from my environment. I performed the following in pipenv: pipenv --rm pipenv install -r requirements.txt I ensured that the pre-commit module was no longer in the…
pymat
  • 1,090
  • 1
  • 23
  • 45
5
votes
1 answer

pre-commit not using virtual environment

I added this to pre-commit-config.yml - repo: local hooks: - id: python-hook name: python-hook entry: python python_script.py language: python pass_filenames: false Where python_script.py has the…
caverac
  • 1,505
  • 2
  • 12
  • 17
5
votes
1 answer

Use pre-commit hook for black with multiple language versions for python

We are using pre-commit to format our Python code using black with the following configuration in .pre-commit-config.yaml: repos: - repo: https://github.com/ambv/black rev: 20.8b1 hooks: - id: black language_version:…
Cord Kaldemeyer
  • 6,405
  • 8
  • 51
  • 81
5
votes
1 answer

Why does mypy raise error when I run it with pre-commit for django-reset-framework?

I'm trying to automate my tests and code static analysis with pre-commit.My .pre-commit-config.yaml is like below: # . # . # . - repo: https://github.com/pre-commit/mirrors-mypy rev: 'v0.910' hooks: - id: mypy args:…
5
votes
1 answer

Pre-commit hook based on an executable (not git repo)

I'd like to run executable coming from pip that isn't available as a git repository. It seems that documentation assumes anything you'd like to run comes from git repositories: https://pre-commit.com/#plugins. How can I run arbitrary shell commands…
ikamen
  • 3,175
  • 1
  • 25
  • 47
5
votes
1 answer

Pre-commit not finding python packages

Im using pyenv to support having different versions of python. In a project using python 3.7 I also want linting with pre-commit to run when doing code changes. But when the lint rules run, pre-commit seem to be looking in a cache folder under the…
Tomas B
  • 121
  • 2
  • 6
5
votes
3 answers

Prettier using pre-commit(.com) does not re-stage changes

I started using Prettier + eslint using pretty-quick & husky (option 2). It behaves as-expected, i.e., reformats code during a commit (or amend) and includes the changes in the commit. My monorepo needed (several) more pre-commit hooks, so I ended…
Zane Claes
  • 14,732
  • 15
  • 74
  • 131
5
votes
0 answers

How can I run black formatting on a cookiecutter template?

I am using pre-commit with black and flake8 hooks. I got this error: cannot format when trying to black-format the following code from {{cookiecutter.project_name}} import my_module Is there anyway to indicate black, to skip/ignore…
5
votes
2 answers

How do i add a command line prompt as the $EDITOR when committing in svn and git

Is it possible to have a small shell script to replace the $EDTIOR for git and svn? So when a person not familiar with vi or emacs makes a commit and forgets to add a -m "fixed the foo bug" parameters it would not open an editor they do not know how…
5
votes
1 answer

Git hook not running on windows

I'm just getting started with hooks and have met some trouble with simply running the script, as I commit with git. The script works completely as intended when ran from bash terminal with the bash pre-commit command. But it doesn't run at all when…
5
votes
1 answer

Is there a way to 'script' a git commit - only accepting some diffs?

I have applied some static code analysis - and transformed all Java package level fields into protected. This is mostly correct, as I forgot to set the access modifier explicitly, and protected is generally what I was after in those…
user2800708
  • 1,890
  • 2
  • 18
  • 31
5
votes
5 answers

how to automate or facilitate multiplatform build/test before committing?

Our software is built on linux and windows platforms. Depending on the preference of the developer a contribution is developed and tested on either platform and then committed to our subversion repository. It then turns out that the contribution…
5
votes
1 answer

Running Django Tests with a Precommit Hook

I would like to run all my django tests using mercurial's precommit hook. Whenever a test fails the commit will be aborted. The goal is to block build-breaking commits as often as possible. edit: Ended up using the external script route. Here is the…
Jiaaro
  • 74,485
  • 42
  • 169
  • 190