Skip to content
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

no ability to specifiy default fallback line ending for a repo with core.autocrlf=false #1559

Open
4 of 5 tasks
jtnord opened this issue Feb 6, 2023 · 3 comments
Open
4 of 5 tasks

Comments

@jtnord
Copy link

jtnord commented Feb 6, 2023

with spotless and a cross platform repository it is not easily possible to enable spotless for all (windows) users.

if a Windows user has core.autocrlf=false to disable line end conversion so they end up with exactly what the repository has, then spotless falls back to assuming that \r\n should be used (which is incorrect in this case).

you can force \n on everyone by adding a .gitattributes to the repository but this will impact windows users whose default tooling may not cope well with linux line ends.

in other words - this fallback should not fallback to native but a configurable option in spotbugs (ie Unix if not changed by local git config).

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

Maven 3.8.6
Java 11.0.15
Windows 11

      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <version>2.31.0</version>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <configuration>
              <java>
                <endWithNewline />
                <googleJavaFormat>
                  <style>AOSP</style>
                </googleJavaFormat>
                <importOrder />
                <indent>
                  <spaces>true</spaces>
                </indent>
                <removeUnusedImports />
                <trimTrailingWhitespace />
              </java>
              <pom>
                <sortPom>
                  <encoding>UTF-8</encoding>
                  <lineSeparator>\n</lineSeparator>
                  <expandEmptyElements>false</expandEmptyElements>
                  <spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
                  <sortDependencies>scope,groupId,artifactId</sortDependencies>
                  <sortDependencyExclusions>groupId,artifactId</sortDependencyExclusions>
                  <sortPlugins>groupId,artifactId</sortPlugins>
                  <sortModules>true</sortModules>
                  <sortExecutions>true</sortExecutions>
                </sortPom>
              </pom>
            </configuration>
          </execution>
        </executions>
      </plugin>

  • summary of problem
  • gradle or maven version
  • spotless version
  • operating system and version
  • [] 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

If you're just submitting a feature request or question, no need for the above.

@jtnord jtnord changed the title no ability to specifiy fallback default line ending for a repo with core.autocrlf=false no ability to specifiy default fallback line ending for a repo with core.autocrlf=false Feb 6, 2023
@nedtwigg
Copy link
Member

nedtwigg commented Feb 6, 2023

Hmmm... You can do <lineEndings>PLATFORM_NATIVE</lineEndings>. But also we did add support for core.autocrlf in plugin-maven 2.20.1.

I wonder if we somehow broke it at somepoint... We still have a test for it, so I don't think so

@Test
void policyDefaultLineEndingTest() throws GitAPIException {
Git git = Git.init().setDirectory(rootFolder()).call();
git.close();
setFile(".git/config").toContent(StringPrinter.buildStringFromLines(
"[core]",
"autocrlf=true",
"eol=lf"));
LineEnding.Policy policy = LineEnding.GIT_ATTRIBUTES.createPolicy(rootFolder(), () -> testFiles());
Assertions.assertThat(policy.getEndingFor(newFile("someFile"))).isEqualTo("\r\n");
}

@jtnord
Copy link
Author

jtnord commented Mar 9, 2023

You can do PLATFORM_NATIVE. But also we did add support for core.autocrlf in plugin-maven 2.20.1.

"autocrlf=true" but what about autocrlf=false

basically checkout as is, check in as is, no line normalisation, let the user decide if they want unix line ends in a java source file locally or not. (some files will be forced by attributes to \r\n like bat files.

in other words - if the users setup is by default not platform native but repository native... git may not have been explicitly told that default is \n - but this can be the case. and if so I would like a configutation option to say
if .gitattributes is not set, if core.autocrlf is not set and if core.eol is not set then as a fallback this project will be using "insert default" (or in this case - probably if none of the rest are set then perhaps the best is not to be platform native at all but to use unix line ends?

@nedtwigg
Copy link
Member

My opinion on this is:

  • line endings don't matter
  • complicated specs for line endings especially don't matter
  • so put yourself into the simplest part of the spec and get real work done

There is only one place within the spec that makes sense to me: unix everywhere -> .gitattributes file with just * text eol=lf.

But I'm happy to support any dark corner of the spec that users are willing to write features and unit tests for :)

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

No branches or pull requests

2 participants