LicenseHeaderStep with `git --follow` in some repositories produces garbage year history
- [x] summary of problem
I have been working on migrating a project to use spotless for license headers. The project hasn't been great on keeping license headers up to date - so I used spotless's feature to allow fixing the header years from git history.
However with the project the --follow option for git produces a lot of garbage header years.
Examples being small functional interfaces created in 2020 resolving to get an incorrect year range of 2018, 2020.
Possible solution:
Allow disabling the --follow option for git history check here: https://github.com/diffplug/spotless/blob/a30553386acfa24f0d97f587249c38f44feb79b6/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java#L289-L294
-
[x] gradle or maven version Gradle 6.7.1
-
[x] spotless version 5.8.2
Proposal:
spotless { java {
licenseHeader(...).yearsFromGitHistory(
'git log --follow --find-renames=40% --diff-filter=A',
'git log --follow --find-renames=40% --reverse')
...
The idea is that yearsFromGitHistory will take an array of strings, and it will try to find a year by executing the first string, then the second, etc. until it finds a date (and fail if none of them do). The values above will be the defaults.
Happy to take a PR for this, I have no plans to implement. If anyone does take the time to dig in, it would improve the reliability and performance if this hunk of code were refactored to use ProcessRunner.