Null pointer exception due to workingTreeIterator being null for git ignored files.

If there is a file that is already committed and later becomes a part of .gitignore, this file creates a null pointer exception in spotless when used with ratchetFrom.

This happens because workingTreeIterator evaluates to null (here) for these files.

This is an exceptional case so maybe by adding a null check, we will ignore these files?

Steps to recreate the bug(example repo)

  1. I created a file Wow.js inside a package useless (commit)
  2. In a later commit I gitignored this package (names useless) (commit).
  3. Now even though the package is git ignored the file Wow.java will always be there as it was already committed and will create problems for spotless when used with ratchetFrom.
  4. Now if I add spotless it to the project, spotlessCheck fails with a null pointer exception due to this file. (commit)

Technical Details

  • Gradle Version: Gradle 6.1.1
  • Spotless version: 5.12.4
  • Os: macOS Big Sur 11.2.2
  • Test project: here