Skip to content

Commit

Permalink
Fix git line ending handling (#540) which was broken by #1119 (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Apr 6, 2022
2 parents 75e925f + 43dadf5 commit e1d34dc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions plugin-gradle/CHANGES.md
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions plugin-maven/CHANGES.md
Expand Up @@ -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))
Expand Down

0 comments on commit e1d34dc

Please sign in to comment.