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
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
7
votes
2 answers

Searching files with pre-commit

I am trying to add a git pre-commit hook that will check all changed and new file for TODO: text. I tried #!/bin/sh . git-sh-setup # for die git-diff-index -p -M --cached HEAD -- | grep '^+' | grep TODO: && die Blocking commit because string…
codingninja
  • 1,360
  • 2
  • 13
  • 24
7
votes
2 answers

git pre-commit hook code formatting with partial commit?

is there a way to have a pre-commit hook which auto-formats the code (for example with astyle) but does not destroy a partial commit? Workflow: # edit a file.txt git add -p file.txt # add one chunk, but not another git commit -m 'a…
musicmatze
  • 4,124
  • 7
  • 33
  • 48
7
votes
2 answers

Subversion: how to remove property on commit

My situation is this: I have a Subversion server set up at my home, and we also use Subversion at the company where I work. At work, we use the lock/edit/unlock model (mainly because we are transitioning from Visual SourceSafe and it's easier for…
Mark Bell
  • 28,985
  • 26
  • 118
  • 145
7
votes
2 answers

Pipe STDIN to a script that is itself being piped to the Python interpreter?

I need to implement an SVN pre-commit hook which executes a script that itself is stored in SVN. I can use the svn cat command to pipe that script to the Python interpreter, as follows: svn cat file://$REPO/trunk/my_script.py | python - --argument1…
kostmo
  • 6,222
  • 4
  • 40
  • 51
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
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
2 answers

pre-commit hook failing for a Python project

I have a Python project that when I try to commit (through miniconda) with: $ git add -A && git commit -m `test` I get the following failure: (base) D:\machinelearning.com-python>git commit -m 'test' [WARNING] Unstaged files detected. [INFO]…
Viewsonic
  • 827
  • 2
  • 15
  • 34
6
votes
1 answer

How to propertly configure my pre-commit and pre-push hooks?

I have a simple python project with a single file currently. It exists within the static/cgi-bin folder of my project. Currently, in the base of my directory, I have a .pre-commit-config.yaml file, and I have not touched the files in the .git/hooks…
niketp
  • 409
  • 1
  • 9
  • 20
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
1 answer

jest: running tests with coverage in pre-commit-hook exits with 1 if no coverage was found

I'm trying to run tests on the staged files in a pre-commit hook with jest. So far, so good. Got it working with the pre-commit and lint-staged NPM packages. Snippet from the package.json: { // ... "scripts": { "hook": "lint-staged", //…
Philipp Kyeck
  • 18,402
  • 15
  • 86
  • 123
6
votes
1 answer

Pre-commit hook for Git when Hudson build has failed

I'm trying to figure out how to write a pre-commit hook for Git that checks the status of my Hudson build. If the previous build failed, it should disallow anyone from committing without first writing a specific line, e.g. "fixed build." EDIT: The…
Josh Smith
  • 14,674
  • 18
  • 72
  • 118
6
votes
1 answer

Regex pattern to match directories with a prefix

I am a bit of regex newbie and I can't figure out how to set up a regular expression for this pattern I am trying to do. The expression is meant to be in a Python pre-commit script and it will run a pre-commit hook if the files being commits match…
MechaStorm
  • 1,432
  • 3
  • 17
  • 29