1

Running: RH7, Python 3.8.3, pre-commit 2.8.2

I download a repo from github. I make a "bad" change to an existing file, such as not enough empty lines preceding class statement. I run

pre-commit run yapf --all-files

and I get Failed as expected.

However, if I create a new file with the same mistake, no error is found! It's as if the new file is not being seen.

Please advise.

ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
user2133121
  • 341
  • 1
  • 3
  • 12

1 Answers1

3

pre-commit only runs on files which are checked in to the repository

this makes it so you generally don't need exclusion rules that many other tools require (to exclude virtualenvs, .tox, .git, other junk files, etc.)

it also allows pre-commit to do smart things when making commits, such as only sending the changed files to the underlying tools

try git add thatfile.py and then running pre-commit run yapf (and/or --all-files)


disclaimer: I'm the author of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • Just to add to the excitement, I use eclipse along with a few command line tools. When the new file is unstaged under eclipse, pre-commit does not find it. But when it is staged under eclipse, then it is found by pre-commit. So unlike previously committed (old) files that have new changes pending, it seems that for new files the git add is not done until the file is moved from unstaged to staged. Thanks! – user2133121 Nov 10 '20 at 20:01