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
96
votes
10 answers

Can a Git hook automatically add files to the commit?

I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit. How would I go about this? I've tried this as a pre-commit hook, but no…
Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
94
votes
6 answers

Git pre-commit hook : changed/added files

I am writing a pre-commit hook. I want to run php -l against all files with .php extension. However I am stuck. I need to obtain a list of new/changed files that are staged. deleted files should be excluded. I have tried using git diff and git…
igorw
  • 27,759
  • 5
  • 78
  • 90
75
votes
14 answers

pre-commit/hook: No such file or directory

I get this error when I try to commit. OS - Latest OSX Git version - git version 2.11.0 (Apple Git-81) .git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
63
votes
5 answers

pre-commit fails to install isort 5.11.4 with error "RuntimeError: The Poetry configuration is invalid"

pre-commit suddenly started to fail installing the isort hook in our builds today with the following error [INFO] Installing environment for https://github.com/pycqa/isort. [INFO] Once installed this environment will be reused. [INFO] This may take…
bagerard
  • 5,681
  • 3
  • 24
  • 48
51
votes
5 answers

black as pre-commit hook always fails my commits

I'm trying to use pre-commit to manage Black as a Git pre-commit hook, but I must be doing it wrong. In my pre-commit config file I have: - repo: https://github.com/psf/black rev: 19.3b0 hooks: - id: black What I'm expecting to…
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
49
votes
2 answers

Exclude some files on running black using pre-commit

I want to configure black in pre-commit and exclude precommit from checking any migrations folder. My pyproject.toml looks like this [tool.black] line-length = 79 target-version = ['py37'] include = '\.pyi?$' exclude = ''' ( /( \.eggs |…
Suyash Salampuria
  • 765
  • 2
  • 6
  • 9
42
votes
5 answers

Git pre-commit hooks only for a specific subfolder?

I currently have a single repo with two projects, each in their own subfolder: one in C# and one in Javascript. I want to have a pre-commit hook that will run jshint but only if any of the staged files are in the Javascript folder If the staged…
somecoolguy
  • 431
  • 1
  • 4
  • 3
40
votes
22 answers

Share common / useful SVN pre-commit hooks

What are some common and/or useful pre-commit hooks for SVN?
powtac
  • 40,542
  • 28
  • 115
  • 170
40
votes
11 answers

SVN pre-commit hook for avoiding changes to tags subdirectories

Is there anybody who has clear instructions on how to add a pre-commit hook that avoids changes to tags subdirectories? I already searched the internet quite a bit. I found this link: SVN::Hooks::DenyChanges , but I can't seem to compile things.
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
34
votes
5 answers

Windows Pre-commit hook for comment length Subversion

I seem to be getting nowhere with this. Either searching the web for a script, etc. Anyone got a script that you can just edit the out-of-box pre-commit.tmpl in a Windows environment that requires x chars to be entered in for a comment on commit…
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
34
votes
2 answers

Where does pre-commit install "environments"?

I'm trying to setup pre-commit for a Python project's repository. Upon running pre-commit install I see an output like this: [INFO] Installing environment for https://github.com/asottile/seed-isort-config. [INFO] Once installed this environment will…
planetp
  • 14,248
  • 20
  • 86
  • 160
32
votes
1 answer

How to run custom shell script file before pre commit hook

In my python project, I have pre-commit-config.YAML where I want to create my custom file. The intention of this file is fail git commit if python lint errors are greater than certain numbers. The following command will be used to count lines pylint…
Kedar Shinde
  • 379
  • 1
  • 4
  • 5
27
votes
4 answers

How can I use husky to check a git commit message format?

I'm trying to enforce a git commit message policy to keep my repositories clean and tidy. I've seen the official docs about server-side and client-side hooks and then I bumped on husky. So far I could work with the first but couldn't set up husky,…
remmargorp
  • 434
  • 1
  • 6
  • 14
25
votes
12 answers

SVN Error: Commit blocked by pre-commit hook (exit code 1) with output: Error: n/a (6)

Some weird error cropped up suddenly outta nowhere and is preventing me from checking in my code via TortoiseSVN. I'm using a free account on myversioncontrol.com This is on a Windows Vista system. It was working fine till earlier in the day. Any…
Steve
  • 1,857
  • 5
  • 32
  • 45
24
votes
5 answers

How do I get lint-staged working with Husky version 6

I try to use Husky's pre-commit and lint-staged. Those are installed: "husky": "^5.1.3", "lint-staged": "^10.5.4", In package.json I have: "scripts": { "build": "gatsby build", "develop": "gatsby develop", "format": "prettier --write…
meez
  • 3,783
  • 5
  • 37
  • 91
1
2 3
27 28