diffplug / spotless

Keep your code spotless

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Executing `gradle spotlessApply` changes permission on the changed files from `644` to `755`

tglaeser opened this issue · comments

summary of problem

Executing gradle spotlessApply changes permission on the changed files from 644 to 755

gradle or maven version

Gradle 6.5.1

spotless version

plugins {
    id 'com.diffplug.spotless' version '5.1.0'
}

operating system and version

Running MSYS2 on Windows 10

full Spotless configuration block(s)

    spotless {
        format 'misc', {
            target '*.gradle', '*.md', '*.txt', '.gitignore', '.gitattributes'
            trimTrailingWhitespace()
            indentWithSpaces()
            endWithNewline()
        }
        project.plugins.withType(JavaPlugin) {
            java {
                licenseHeaderFile(rootProject.file('copyright.txt'))
                removeUnusedImports()
            }
        }
    }

git config

$ git config --list --show-origin
...
file:.git/config        core.filemode=true
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.symlinks=false
file:.git/config        core.ignorecase=true
...

Note that the result is the same with core.filemode set to false.

Interesting! There are two tasks involved. spotless<Format> writes a correctly formatted file out to a temp location in the build folder:

public void writeCanonicalTo(File file) throws IOException {
Files.write(file.toPath(), canonicalBytes());
}

And then spotless<Format>Apply copies that file into the final locaiton

Files.copy(fileVisitDetails.getFile().toPath(), originalSource.toPath(), StandardCopyOption.REPLACE_EXISTING);

The purpose of the temp location is that it allows check and apply to depend on a single, cacheable task. Happy to take a PR to fix this.

I guess maven users probably have the same problem. The case there is a little simpler, there's no copy, just writeCanonicalTo. No obligation for a PR to fix all plugins, but I'll leave this open until it has been fixed in both plugins.

Thanks for the pointers. With java.nio.file.attribute not providing an files system agnostic file mode approach, I believe the only option then would be remembering the original file attributes by copying the original file to the temp location, updating it, and then copying it back to the final location; a PR for this is in the making.

Fixed in plugin-gradle 5.1.1