[ 
https://issues.apache.org/jira/browse/HBASE-29388?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

guluo resolved HBASE-29388.
---------------------------
      Assignee: guluo
    Resolution: Fixed

> mvn spotless:apply changes line endings (CRLF to LF) on Windows
> ---------------------------------------------------------------
>
>                 Key: HBASE-29388
>                 URL: https://issues.apache.org/jira/browse/HBASE-29388
>             Project: HBase
>          Issue Type: Bug
>         Environment: hbase master
>            Reporter: guluo
>            Assignee: guluo
>            Priority: Major
>              Labels: pull-request-available
>
> For master branch, after executing `mvn spotless:apply` on Windows, executing 
> `git diff` commands would display warnings message:  "warning: LF will be 
> replaced by CRLF in **", as fallow.
> warning: LF will be replaced by CRLF in CHANGES.txt.
> The file will have its original line endings in your working directory
> warning: LF will be replaced by CRLF in LICENSE.txt.
> The file will have its original line endings in your working directory
> warning: LF will be replaced by CRLF in NOTICE.txt.
> The file will have its original line endings in your working directory
> warning: LF will be replaced by CRLF in README.md.
> The file will have its original line endings in your working directory
> ...
> And core.autolf = true or unset core.autolf in my .gitconfig, the results are 
> all the same.
> This issue doesn't exist on Linux, I'm unsure if it occurs on macOS.
> I checked the commit history and found that this might have been caused  by 
> HBASE-29344
> The reason.
> spotless may change line endings (CRLF to LF)
> spotless introduce a feature in version 2.40.0 :  Set the default line 
> endings to be GIT_ATTRIBUTES_FAST_ALLSAME.  
> Details see:
> [https://github.com/diffplug/spotless/commit/54c0af2bb701fc1b0756b8ff1bfd568d0c43bf65]
> [https://github.com/diffplug/spotless/pull/1838/files]
> {code:java}
> // spotless 
> // GitAttributesLineEndings.LazyAllTheSame.calculateState()
> protected String calculateState() throws Exception {
>     var files = toFormat.get().iterator();
>     if (files.hasNext()) {
>         Runtime runtime = new RuntimeInit(projectDir).atRuntime();
>         return runtime.getEndingFor(files.next());
>     } else {
>         // I suspect this code might convert some CRLF files to LF format 
> after executing 'mvn spotless:apply' on Windows 
>         return LineEnding.UNIX.str();
>     }
> } {code}
>  
> My solution:
> Introduce a tag in Spotless's configuration while still using the previously 
> default LineEnding.GIT_ATTRIBUTES
> <plugin>  
>   <groupId>com.diffplug.spotless</groupId>  
>   <artifactId>spotless-maven-plugin</artifactId>  
>   <version>${spotless.version}</version>  
>   <configuration>  
>     <lineEndings>GIT_ATTRIBUTES</lineEndings>
>   </configuration>
> </plugin>



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to