开发者

Git: Run through a filter before commiting/pushing?

开发者 https://www.devze.com 2022-12-26 15:56 出处:网络
Is there a way to run the changed files throu开发者_开发知识库gh a filter before doing the commit? I wish to make sure the files follows the coding standards for the project.

Is there a way to run the changed files throu开发者_开发知识库gh a filter before doing the commit? I wish to make sure the files follows the coding standards for the project.

I would also like to compile and run some test before the commit/push actually takes place, so I know everything in the repo actually works.


Pre-commit hooks. Read up on git hooks. The Git Book has an example of how to write a Ruby script to run RSpec tests, for instance.

You just save the executable as .git/hooks/pre-commit - using a hashbang to specify the language. It is just an ordinary shell script, although you can use any scripting language, so long as it returns 1 if there is a problem and 0 if there isn't.


For the filter part, I would recommend a smudge/clear driver, with the 'clear' script containing all the formatting or checking you need (executing on commit)

Git: Run through a filter before commiting/pushing?

You can declare this git attribute filter driver only for certain types of files, only for certain directories within your repo.

0

精彩评论

暂无评论...
验证码 换一张
取 消