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

running pytest as a pre-commit hook // no such file or directory issue

in my Python project I use pytest as a pre-commit hook. Some tests create and delete temporary files, everything works fine when I run pytest . However, when I run git commit and pre-commit hook triggers pytest, some tests fail…
15
votes
1 answer

With pre-commit, how to use some hooks before commit and others before push

Some hooks can take a while to run, and I would like to run those before I push, but not before each particular commit (for example, pylint can be a bit slow). I've seen the following: Question: Using hooks at different stages mesos-commits mailing…
baxx
  • 3,956
  • 6
  • 37
  • 75
14
votes
2 answers

Run pre-commit only on certain branches

I am looking for a configuration in the .pre-commit-config.yaml to exclude pre-commit from being run on certain branches, or to run it only on some branches. I don't know if this feature not implemented, or if I am missing it in the docs. Thanks!
14
votes
2 answers

How exclude !Ref tag from check-yaml git hook?

There is a serverless.yaml file which contains line like that: VpcId: !Ref MyVpc Yaml files are validated by check-yaml git hook which invoked by pre-commit command. So the pre-commit run --all-files run is failed with error: could not determine a…
Cherry
  • 31,309
  • 66
  • 224
  • 364
13
votes
3 answers

Pre-commit hook to check for Jira issue key

I am looking for somehelp to write a pre-commit hook on windows to check for Jira issue key while commiting.Commit should not be allowed if Jira key is not present.I couldnt find any way.I am new to scripting.Any help would be highly appreciated.
Help required
  • 131
  • 1
  • 1
  • 4
13
votes
3 answers

Automatically add svn keyword properties for new files (server-side)

I want to add svn properties (like svn:keyword=Id Date Rev Author) to files upon commits of new files. For this to work there may be two main options: Client-side: altering the autoprops in the svn client configuration Server-side: do some magic…
13
votes
4 answers

Use PHP_CodeSniffer for modified lines only

I am trying to build a pre-commit script in SVN, and I want to run PHP_CodeSniffer on the modified lines only (as opposed to the whole file). So far I have this script: #!/bin/sh REPOS="$1" TXN="$2" # Make sure that the log message contains some…
Antonio
  • 381
  • 4
  • 12
13
votes
2 answers

Git pre-commit hook: getting list of changed files

I am developing validation and linting utility to be integrated with various commit hooks, including Git one https://github.com/miohtama/vvv Currently validators and linters are run against the whole project codebase on every commit. However, it…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
12
votes
2 answers

Detecting branch reintegration or merge in pre-commit script

Within a pre-commit script, is it possible (and if so, how) to identify commits stemming from an svn merge? svnlook changed ... shows files that have changed, but does not differentiate between merges and manual edits. Ideally, I would also like to…
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
12
votes
3 answers

How to make a pre-commit hook that prevents non-UTF-8 file encodings

Is it possible to make a precommit hook for git or svn that can reject files not committed in a specific encoding? I have worked on several project where it seems to be a problem to stick to a certain file encoding (like UTF-8 for instance)
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
12
votes
6 answers

Enforcing code standards in git before commit is accepted

Alright, here's the scenario: A team of developers wants to ensure all new code matches the defined coding standards and all the unit tests are passing before a commit is accepted. Here's the trick, all of the tests need to run on a dedicated…
Jake A. Smith
  • 2,278
  • 3
  • 17
  • 24
12
votes
3 answers

Perforce client side pre-commit hook

We are using perforce as a source control for Visual studio solution. Working with P4 and P4V. Is it possible to add client side pre-commit hook? for instance to ensure the word "debugger;" is not exist in *.js files. Could find something in…
Igal
  • 1,084
  • 2
  • 13
  • 33
11
votes
1 answer

How to ensure that all pre-commit hooks pass in CI/CD

My team uses Pre-commit in our repositories to run various code checks and formatters. Most of my teammates use it but some skip it entirely by committing with git commit --no-verify. Is there anyway to run something in CI/CD to ensure all…
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
11
votes
1 answer

Pre-commit flake8 with setup.cfg in subfolder

I use flake8 with a bunch of plugins (flake8-docstrings, flake8-isort, flake8-black). I have them all pre-installed into a venv. My repo to be checked with pre-commit: Root folder has two packages Each has its own pyproject.toml (configures black…
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
11
votes
2 answers

Setup environment for pre-commit

How can I source a bash script that contains exports for environment variables? env.sh ... export VARIABLE=test ... test_file.py ... os.environ['VARIABLE'] # Throws KeyError ... How can I use pre-commit to run env.sh to setup an environment that…
user1222324562
  • 965
  • 2
  • 9
  • 24
1 2
3
41 42