diff --git a/CHANGES.md b/CHANGES.md index 0b2af47551..ea34ee65b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [2.24.1] - 2022-03-30 ### Fixed * Fixed access modifiers for setters in KtfmtStep configuration diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index 4aab23e142..ae9f0ceec1 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -172,7 +172,7 @@ static class RuntimeInit { ////////////////////////// // REPO-SPECIFIC VALUES // ////////////////////////// - RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir); + RepositorySpecificResolver repositoryResolver = GitWorkarounds.fileRepositoryResolverForProject(projectDir, userConfig); if (repositoryResolver.getGitDir() != null) { workTree = repositoryResolver.getWorkTree(); repoConfig = repositoryResolver.getRepositoryConfig(); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java index a66650b38f..70f0b9cb99 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitWorkarounds.java @@ -62,7 +62,20 @@ private GitWorkarounds() {} * @return the builder. */ static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir) { - RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(); + return fileRepositoryResolverForProject(projectDir, null); + } + + /** + * Creates a {@link RepositorySpecificResolver} for the given project directory. + * + * This applies a workaround for JGit not supporting worktrees properly. + * + * @param projectDir the project directory. + * @param baseConfig the user and system level git config. + * @return the builder. + */ + static RepositorySpecificResolver fileRepositoryResolverForProject(File projectDir, @Nullable Config baseConfig) { + RepositorySpecificResolver repositoryResolver = new RepositorySpecificResolver(baseConfig); repositoryResolver.findGitDir(projectDir); repositoryResolver.readEnvironment(); if (repositoryResolver.getGitDir() != null || repositoryResolver.getWorkTree() != null) { @@ -94,6 +107,16 @@ static class RepositorySpecificResolver extends FileRepositoryBuilder { private File commonDirectory; + private Config baseConfig; + + public RepositorySpecificResolver() { + this(null); + } + + public RepositorySpecificResolver(@Nullable Config baseConfig) { + this.baseConfig = baseConfig; + } + /** @return the repository specific configuration. */ Config getRepositoryConfig() { return Errors.rethrow().get(this::getConfig); @@ -108,7 +131,12 @@ Config getRepositoryConfig() { protected Config loadConfig() throws IOException { if (getGitDir() != null) { File path = resolveWithCommonDir(Constants.CONFIG); - FileBasedConfig cfg = new FileBasedConfig(path, safeFS()); + FileBasedConfig cfg = null; + if (this.baseConfig == null) { + cfg = new FileBasedConfig(path, safeFS()); + } else { + cfg = new FileBasedConfig(baseConfig, path, safeFS()); + } try { cfg.load(); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 67413e9014..f420e83323 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [6.4.1] - 2022-03-30 ### Fixed * Fixed ktfmt options configuration in Gradle plugin for Gradle Kotlin scripts (kts). diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 508e7f4997..8863af1825 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Git user config and system config also included for defaultEndings configuration. ([#540](https://github.com/diffplug/spotless/issues/540)) + ## [2.22.0] - 2022-03-28 ### Added * Added support for setting custom parameters for Kotlin ktfmt in Maven plugin. ([#1145](https://github.com/diffplug/spotless/pull/1145))