Cosium / git-code-format-maven-plugin

A maven plugin that automatically deploys code formatters as pre-commit git hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pre-commit hook fails on windows when file only contains suppressed lines

ludovic-faure opened this issue · comments

On windows, after 1 line comment suppression in java file, try to commit.
Pre-commit hook fails.

There must be at least one range -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.cosium.code:maven-git-code-format:1.39:on-pre-commit (default-cli) on project core-additional-health-insurance: There must be at least one range
..
Caused by: java.lang.IllegalArgumentException: There must be at least one range
    at com.cosium.code.format.formatter.LineRanges.<init> (LineRanges.java:19)
    at com.cosium.code.format.formatter.LineRanges.of (LineRanges.java:30)
    at com.cosium.code.format.git.GitIndexEntry$EntryFormatter.computeLineRanges (GitIndexEntry.java:191)

This seems to be related to two factors :

  • on windows file is considered as partially staged even if no unstaged change exists
  • partially staged file format fails if no new line exists because it detects no line range to format

I guess this can also be reproduced on unix with this process :

  • suppress comment line on file and stage it
  • modify the file again but don't stage to produce unstaged change
  • try to commit staged modification

Platform :

plugin version 2.1
git version 2.25.0.windows.1

Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Java version: 11.0.2, vendor: Oracle Corporation
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Are you using version 2.1? If not try it please.

Test was done on 2.1 :

 There must be at least one range -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.cosium.code:git-code-format-maven-plugin:2.1:on-pre-commit (default-cli) on project