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

feat: 'ratchetFrom' in git submodule supported (#746) #754

Merged
merged 2 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Changed
* Added support for git-submodule with `ratchetFrom` ([#746](https://github.com/diffplug/spotless/issues/746))
* Update default ktfmt from 0.16 to 0.18 ([#748](https://github.com/diffplug/spotless/issues/748))
* fix typo in javadoc comment for SQL\_FORMATTER\_INDENT\_TYPE ([#753](https://github.com/diffplug/spotless/pull/753))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -183,13 +185,37 @@ protected Repository repositoryFor(Project project) throws IOException {
return null;
}

/**
* When populating a new submodule directory with "git submodule init", the $GIT_DIR meta-information directory
* for submodules is created inside $GIT_DIR/modules// directory of the super-project
* and referenced via the git-file mechanism.
*/
private static @Nullable File getDotGitDir(File dir, String dotGit) {
File dotGitPath = new File(dir, dotGit);

if (dotGitPath.isDirectory()) {
return dotGitPath;
} else if (dotGitPath.isFile()) {
try {
String relativePath = new String(Files.readAllBytes(dotGitPath.toPath()), StandardCharsets.UTF_8)
.split(":")[1].trim();
return getDotGitDir(dir, relativePath);
} catch (IOException e) {
System.err.println("failed to parse git meta: " + e.getMessage());
return null;
}
} else {
return null;
}
}

private static boolean isGitRoot(File dir) {
File dotGit = new File(dir, Constants.DOT_GIT);
return dotGit.isDirectory() && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED);
File dotGit = getDotGitDir(dir, Constants.DOT_GIT);
return dotGit != null && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED);
}

static Repository createRepo(File dir) throws IOException {
return FileRepositoryBuilder.create(new File(dir, Constants.DOT_GIT));
return FileRepositoryBuilder.create(getDotGitDir(dir, Constants.DOT_GIT));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Changed
* Updated default eclipse-jdt from 4.17.0 to 4.18.0.
* Updated default eclipse-wtp from 4.17.0 to 4.18.0.
### Fixed
* `ratchetFrom` now works with git-submodule ([#746](https://github.com/diffplug/spotless/issues/746))

## [5.8.2] - 2020-11-16
### Fixed
Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Updated default eclipse-jdt from 4.17.0 to 4.18.0.
* Updated default eclipse-wtp from 4.17.0 to 4.18.0.
### Fixed
* `ratchetFrom` now works with git-submodule ([#746](https://github.com/diffplug/spotless/issues/746))
* Fix broken test for spotlessFiles parameter on windows ([#737](https://github.com/diffplug/spotless/pull/737))

## [2.6.1] - 2020-11-16
Expand Down