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

In Eclipse How Can I Edit With One Format And Commit With Another

Everyone on my team uses the same formater settings so files in the SVN repo dont have changes based on formatting. The format that was chosen I dislike and I can barely read. Is there a plugin for Eclipse or a setting in Eclipse that will auto…
Eric
  • 7,787
  • 5
  • 19
  • 34
4
votes
1 answer

How to test current commit and not the working tree?

I am trying to set up a pre-commit hook to test my project before any commit goes through, but I can't find how to make sure that only HEAD (with patches from the current commit) are tested and not the current working_tree (which in most cases is…
Sedrik
  • 2,161
  • 17
  • 17
4
votes
0 answers

Pre-commit fixes a file correctly using the cli, but changes it back when I attempt to commit the file

I am trying to use isort to automatically fix import orders. When I run pre-commit run --files=myfile.py it correctly updates my imports (by adding a line between known third party imports and internal package imports). However, when I try to commit…
cammil
  • 9,499
  • 15
  • 55
  • 89
4
votes
7 answers

How to find out what commit a checked out file came from

When I check out a file with git checkout $commit $filename and I forget $commit but still remember $filename, how do I find out what $commit was?
j-pb
  • 822
  • 2
  • 8
  • 12
4
votes
1 answer

Flakehell with .toml configuration and pre-commit hook

I'm trying to run flakehell as pre-commit hook. my .pre-commit-config.yaml: repos: - repo: local hooks: - id: flakehell name: flakehell entry: flakehell lint project/ language: python …
tomm
  • 271
  • 2
  • 14
4
votes
0 answers

Husky failed to install cannot read property of 'toString' of null

I have an issue installing husky (with lint-staged) for a while now and I would very much appreciate any help. My project setup is: node JS, npm with eslint, prettier set-up and now trying to add husky with lint-staged. THE MAIN ISSUE: When…
DavidR
  • 49
  • 4
4
votes
0 answers

Git pre-commit hooks per directory

How do I format a .pre-commit-config.yaml so it's different depending on my directory? My project has different directories. One directory is a UI directory with a package.json and Django files. Another one is a Python package, which does not have a…
simonzack
  • 19,729
  • 13
  • 73
  • 118
4
votes
1 answer

How to use this Git pre-commit hook

Yelp detect secrets is a system that prevents secrets from entering your code base. I would like to install the pre-commit hook it provides. I've never used Git hooks before, but all the example files I see in .git/hooks/ are in bash, while the…
kramer65
  • 50,427
  • 120
  • 308
  • 488
4
votes
1 answer

mysqldump schema only, schema update without drop

I'm looking at using the git pre-commit hook to export a MySQL db schema prior to commiting changes so that other developers can update their own databases with a SQL script from the git repo. By default a mysqldump (I'm using --no-data) will drop…
Mark Williams
  • 1,240
  • 2
  • 13
  • 28
4
votes
1 answer

Using git add inside a pre-commit hook

TL;DR: Using eslint --fix && git add in a pre-commit hook works but it leaves staged and not staged files! Using a post-commit hook to git reset seems to work but is there a solution for this? To give some background, I started using…
Samuel Sharpe
  • 196
  • 1
  • 6
4
votes
1 answer

git precommit-hook: check whether line content has changed

Szenario: On file commit with git I want to check within pre-commit hook whether a certain line has been modified. Therefore I want to compare parts of a line from the modified file with the corresponding linepart from the repository. Background: I…
hoppfrosch
  • 581
  • 5
  • 12
4
votes
0 answers

Mercurial pre-commit hook: How to tell apart changed and committed files

I have following piece of code for fetching a list of all files in current changeset: def changesets(repo, node): if node == None: yield repo[None] else: for rev in xrange(repo[node].rev(), len(repo)): yield…
shabunc
  • 23,119
  • 19
  • 77
  • 102
4
votes
2 answers

Find files that were conflicting or locally edited during git merge commit

Background: I'm working on a pre-commit tool. As a developer it can be quite frustrating to pull another developer's branch and have the pre-commit hook complain loudly about files that I haven't even touched. What I'd like to be able to do in my…
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
4
votes
2 answers

my git pre-commit hook is not executing Astyle, and isnt setting variables. why?

IM writting a simple git pre-commit hook to run Astyle (a code beautifier) in the files that are going to be commited. Here is the code: #!/bin/sh echo "git diff:" FICHEROS=`git diff --name-only` if [ -z "${FICHEROS}" ]; then echo "Files not…
RGonza
  • 107
  • 2
  • 10
3
votes
1 answer

How to run pre-commit on current active file in Pycharm?

I'm looking for a way to run my pre-commit hooks on the currently active file in Pycharm without committing the file. I do not want to artificially add changes to the file and then commit it. The intent is to clean my code while writing it, without…
emilaz
  • 1,722
  • 1
  • 15
  • 31