1

I like to use tools to check code style like flake8 (Python) or jshint (Javascript).

In a Javascript example, I can use the following command to check every .js file in the Git repo:

jshint $(git ls-files | grep .js$ )

I would like to check the code style in the server of continuous integration, but only in the last modified files.

How I can check only the files modified in the current commit?

EDIT

With

 git status --porcelain | sed s/^...//

I can get the name of modified files without commit.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
JuanPablo
  • 23,792
  • 39
  • 118
  • 164

2 Answers2

1

the files modified in the last commit should probably be

git diff HEAD^ --name-only --diff-filter=AM

you then call your linters on those names as usual.

DRC
  • 4,898
  • 2
  • 21
  • 35
0

I find useful it article for my needs. Also see nice comment about pre-commit jshint

Community
  • 1
  • 1
goodniceweb
  • 167
  • 1
  • 10