Questions tagged [pre-commit-hook]

In the context of Software Configuration Management (SCM), a pre-commit hook is a command run just before a commit is performed.

Typically, this hook is used to protect against commits that are disallowed due to content or location (e.g. to forbid empty commit log messages).

Usually, i.e. with SVN, if the pre-commit hook program returns a nonzero exit value, the commit is aborted, the commit transaction is removed, and anything printed to stderr is marshalled back to the client.

Related tags

  • Tag may be used in combination with this tag for git specific pre-commit hooks
  • Tag may be used in combination with this tag for SVN specific pre-commit hooks
626 questions
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
23
votes
5 answers

Run eslint "ONLY" on the staged files

I am trying to use a pre-commit hook to detect eslint errors before commit happens. I am using husky and lint-staged. But it runs the lint command for all the files in src and not on staged files only. Here is my package.json file. "scripts": { …
23
votes
5 answers

How Do I Run Prettier Only on Files That I Want to Commit?

Using Husky, I've set up my package.json with a precommit hook so that my JavaScript code is formatted using Prettier before every commit: { "name": "prettier-demo", "scripts": { "precommit": "prettier --write **/*.js && git add ." }, …
Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
21
votes
5 answers

does github support precommithooks?

Currently we are using SVN. I would like to start using GitHub, but one absolute requirement is that we will need to have precommit (premerge) validation of the code like we currently have. Does GitHub support precommithooks (premergehooks)? We're a…
Corno
  • 5,448
  • 4
  • 25
  • 41
20
votes
2 answers

How to have a single source of truth for poetry and pre-commit package version?

I'm looking into this Python project template. They use poetry to define dev dependencies [tool.poetry.dev-dependencies] black = {version = "*", allow-prereleases = true} flake8 = "*" isort = "^5.6" mypy = ">0.900,<1" ... They use also pre-commit…
floatingpurr
  • 7,749
  • 9
  • 46
  • 106
19
votes
2 answers

pylint and pre-commit hook unable to import

My project structure looks like this: project/ app/ main.py venv/ .pylintrc .pre-commit-config.yaml When I am trying to edit project/app/main.py and it fails with Unable to import 'psycopg2' (import-error) But when I am trying to…
palkan
  • 321
  • 2
  • 5
19
votes
5 answers

Skip pre-commit hook in "npm version" command

npm version commits the change to package.json and creates a tag. Is there a way to prevent commit hook from being executed while using this command?
esp
  • 7,314
  • 6
  • 49
  • 79
19
votes
2 answers

Svn pre-commit hook to disallow svn:mergeinfo on non-root directories

I would like to use a pre-commit hook that prevents developers from setting svn:mergeinfo on non-root directories. That is, I want to enforce that svn:mergeinfo can only be set on directories like "trunk" or "branches/branchName". Developers…
Stuart Lange
  • 4,049
  • 6
  • 24
  • 30
18
votes
4 answers

How can I run git pre-commit checks only on staged content?

Suppose git status gives this: # On branch X # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: file1.cc # modified: file1.h # modified: file1_test.cc # modified: SConscript # # Changes not…
user334856
17
votes
2 answers

How to lint for Typescript compilation issues?

Take the following Typescript arrow function: /** * Returns a probably unique component name. * * @param baseName a suggested name to make unique. * @returns a probably unique name. */ export const getUniqueComponentName = ( baseName ):…
Tom
  • 8,536
  • 31
  • 133
  • 232
17
votes
1 answer

How to validate Jinja syntax without variable interpolation

I have had no success in locating a good precommit hook I can use to validate that a Jinja2 formatted file is well-formed without attempting to substitute variables. The goal is something that will return a shell code of zero if the file is…
Jeff Ferland
  • 17,832
  • 7
  • 46
  • 76
17
votes
3 answers

Pre Commit Hook for JSLint in Mercurial and Git

I want to run JSLint before a commit into either a Mercurial or Git repo is done. I want this as an automatic step that is set up instead of relying on the developer (mainly me) remembering to run JSLint before-hand. I normally run JSLint while…
jrburke
  • 6,776
  • 1
  • 32
  • 23
16
votes
2 answers

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

[INFO] Installing environment for https://github.com/pycqa/isort. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... An unexpected error has occurred: CalledProcessError: command:…
LOTEAT
  • 181
  • 1
  • 4
16
votes
4 answers

How do I add clang-formatting to pre-commit hook?

I am new to commit hooks as well as Clang formatting and am attempting to integrate the two. I have the pre-commit hook set up and I know how to run the Clang formatting on the command line, but am unsure of how to add it to the file. This is the…
Martina
  • 163
  • 1
  • 1
  • 5
16
votes
5 answers

Testing what is about to be committed in a pre-commit hook

When a pre-commit hook runs, the repository might not be clean. So if you naively run your tests, they will not be against what you're committing, but whatever happens to be in your working tree. The obvious thing to do is to git stash --keep-index…
pwaller
  • 601
  • 6
  • 10
1
2
3
41 42