Git pre-commit hook: getting a list of modified files

I am developing a validation and linting utility for integration with various commit latches, including Git one

https://github.com/miohtama/vvv

Currently, validators and letters are launched against the entire project code base with each commit. However, it would be much more optimal to run them only with modified files. To do this, I need to know the list of modified files in my Git pre-hook (in Python)

https://github.com/miohtama/vvv/blob/master/vvv/hooks/git.py

What options do I need to extract a list of modified files (in Python, if that matters)?

+7
source share
1 answer

Capturing a pre-commit is a bit of a pain if you really want everything to work β€œcorrectly” because what doesn’t necessarily coincide in the work tree with what needs to be done:

$ echo morestuff >> file1; echo morestuff >> file2 $ git add file1 # but not file2 $ git commit -m 'modified two files but check in just one' 

You can use git diff-index --cached HEAD to get a "how about registration" list. See also, for example, http://newartisans.com/2009/02/building-a-better-pre-commit-hook-for-git/ .

+5
source

All Articles