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

Git pre-commit hooks keeps modifying files even after I have staged previously modified files

I'm running git pre-commit and running black as one of the hooks. Now when I run commit, black fails and says: All done! ✨ ✨ 15 files reformatted, 1 file left unchanged. I reviewed the reformatted files and I'm fine with them. So I stage those…
rrlamichhane
  • 1,435
  • 2
  • 18
  • 34
10
votes
2 answers

Husky needs to make executable for every new branch

If husky hook is not running, we need to execute command chmod +x .husky/*. But I need to run chmod +x .husky/* every time I go to a new branch. Otherwise, it shows this error: hint: The '.husky/pre-commit' hook was ignored because it's not set…
Arif
  • 6,094
  • 4
  • 49
  • 81
10
votes
2 answers

client side pre-commit hooks in subversion

Is any way to setup pre-commit hooks on the client side with an svn client, for example through eclipse or a command line svn client ?
mafalda
  • 1,024
  • 1
  • 13
  • 24
10
votes
4 answers

How to make a git pre-commit code check?

First question... is it even possible to accomplish this with git? :) What I want is this: Sometimes I switch one variable in my code to true (localMode = true;) for my own debugging purposes. But this should never be commited. I should only commit…
timetowonder
  • 5,121
  • 5
  • 34
  • 48
10
votes
1 answer

Modify file before commit with pre-commit hook

I am trying to write a pre-commit hook that modify a line in my code but I do not know even from where to start. The problem is: I have a KEY public static final String APP_KEY = ""; //DELETE THE KEY BEFORE COMMIT!!! In order to avoid publishing…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
10
votes
3 answers

GIT: Have current commit hash and latest tag in file on commit

that's more of a know-how questions probably: I'm versioning with git and send files for a PHP CMS to the test or production site using rsync. Now I'd like to keep track on what commit is currently deployed using a fool-proof and automated system, I…
Martin Rasser
  • 300
  • 2
  • 10
9
votes
1 answer

How to exclude multiple directories in pre-commit

I have multiple file patterns I want to ignore with pre-commit. For example 'migrations/.' and 'tests/.' The exclude parameter available in the pre-commit configuration file only accepts a string and not a list though. My current configuration…
nholaday
  • 251
  • 2
  • 5
9
votes
1 answer

Pre-commit suddenly fails to install Flake8

The pre-commit run suddenly fails without changes being made to the pre-commit configuration file. The log shows the following error message when attempting to initialise the environment for Flake8: ... [INFO] Initializing environment for…
Roald Nefs
  • 1,302
  • 10
  • 29
9
votes
1 answer

zsh: command not found: pre-commit but package installed

Installed pre-commit successfully using the following command in VSCode: python3 -m pip install pre-commit --user but when I try to do the pre-commit install, I get the error message: zsh: command not found: pre-commit
Alexis Han
  • 91
  • 1
  • 1
  • 2
9
votes
0 answers

Use of pre-commit with PyCharm

I am trying to launch my pre-commit hooks from "commit" button in PyCharm (v. 2020.2). I use a conda venv (created with conda create -n py38 python=3.8) where I installed modules with pip install. My .pre-commit-config.yaml reads: repos: - repo:…
keuj6
  • 103
  • 2
  • 2
  • 8
9
votes
3 answers

Running pre-commit hooks (e.g. pylint) when developing with docker

pre-commit hooks are run in a separate virtual environment (or Docker container). However our code is running on Docker and we're also developing using Docker. Up until now we didn't have to install any dependencies on our host systems, but when…
Jann
  • 1,799
  • 3
  • 21
  • 38
9
votes
2 answers

How to access commit message with Husky pre-commit hook?

My husky script: "husky": { "hooks": { "pre-commit": "sh ./tools/githooks/pre-commit.sh" } } Let's say I am doing a git commit -m "I want that text". How can I access to my commit message within the shell script? I tried to echo…
Potatoes
  • 300
  • 3
  • 13
9
votes
3 answers

How can I share a commit-hook in mercurial with all fellow developers?

we are working with mercurial and now we would like to introduce precommit hooks to keep the code clean. We would like everyone to somehow get the hooks, but we would also like to be able to update this in some centralized way. Mercurial does not…
Nemmi
  • 91
  • 1
8
votes
1 answer

Package requires a different Python: 2.7.17 not in '>=3.6.1' while setting up pre-commit

I cloned a repository, installed pre-commit and was committing for the first time. This is the time when pre-commit packages actually get installed and setup. I faced the following issue. [INFO] Installing environment for…
Roopak A Nelliat
  • 2,009
  • 3
  • 19
  • 26
8
votes
3 answers

git clone different repository in git hooks creating trouble

We have a specific requirement in which we have to push all files which arrive for being committed to a certain branch. We are planning to achieve this via git hooks specifically commit-msg hook. While doing so what we do is we clone branch to…
Jatin Dhoot
  • 4,294
  • 9
  • 39
  • 59
1 2
3
27 28