Skip to content

Spotless's spotlessSetLicenseHeaderYearsFromGitHistory: Unable to parse date from command #2095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
6 tasks done
SirEndii opened this issue Apr 11, 2024 · 2 comments
Open
6 tasks done

Comments

@SirEndii
Copy link

If you are submitting a bug, please include the following:

  • summary of problem
    • Using the -PspotlessSetLicenseHeaderYearsFromGitHistory=true parameter to generate license headers with the creation year of the file, spotless fails to successful run the task
  • Gradle or Maven version
    • Gradle 8.4
    • Java Eclipse Temurin 17.0.10
    • Git 2.44.0.windows.1
  • spotless version
    • spotless 6.25.0
    • spotless-lib-extra 2.45.0
  • operating system and version
    • Windows 11 Pro 23H2 22635.3430
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
  • copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace
    A small portion:
  Unable to parse date from command 'git log --follow --find-renames=40% --reverse -- C:\Users\info\IdeaProjects\AdvancedPeripherals\src\main\java\de\srendi\advancedperipherals\common\addons\computercraft\owner\IOwnerAbility.java':

  java.lang.IllegalArgumentException: Unable to parse date from command 'git log --follow --find-renames=40% --reverse -- C:\Users\info\IdeaProjects\AdvancedPeripherals\src\main\java\de\srendi\advancedperipherals\common\addons\computercraft\owner\I 
 OwnerAbility.java':

  at com.diffplug.spotless.generic.LicenseHeaderStep$Runtime.parseYear(LicenseHeaderStep.java:467)

Full log: https://gist.github.com/SirEndii/e0ed12833caec97f39e9c14935a0ad0f

The full command I'm trying to use gradlew spotless[Apply/Check] -PspotlessSetLicenseHeaderYearsFromGitHistory=true

When I try to use the git log command, it only works without the --follow parameter. I am not too familiar with the git log command to know exactly what the issue could be. This also happens when I try to use different java files from the project

image

@nxglhez
Copy link

nxglhez commented Mar 14, 2025

I had the same problem, and while I can't speak about spotless in itself, you can "hack" git (this worked on WSL + Debian):

  • write a git bash file, making it +x
  • ensure it is found in the path (I put it in $HOME/bin)
  • detect the git log --follow command and rewrite it if it send nothing
  • run spotless:apply (I use Maven)
  • rename/delete your fake git so that you don't use it.
#!/bin/bash
# this is a hack for spotless which use
# git log --follow --find-renames=40% --diff-filter=A
# git log --follow --find-renames=40% --reverse
declare GIT_COMMAND=/usr/bin/git
declare OUTPUT=''
if [[ "${1:-}:${2:-}:${3:-}" != 'log:--follow:--find-renames=40%' ]]; then
  "${GIT_COMMAND}" "$@"
elif ! OUTPUT=$( "${GIT_COMMAND}" "$@" ) ; then
  echo -n "$OUTPUT"
  exit 2
elif [[ -n "$OUTPUT" ]]; then
  echo -n "$OUTPUT"
else
  shift 2 # remove log follow
  "${GIT_COMMAND}" log "$@"
fi

I suppose that a "good" fix would be to do so in spotless directly by adding yet another try/catch here: https://github.com/diffplug/spotless/blob/main/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java#L430

@SirEndii
Copy link
Author

This is indeed a cursed hack, but interesting. I will try that, thanks

I already thought that this issue is lost forever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants