Skip to content

Commit

Permalink
feat: 'ratchetFrom' in git submodule supported (diffplug#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
conderls committed Dec 23, 2020
1 parent 75fdd3e commit 8891bfb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
14 changes: 0 additions & 14 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Changed
* Update default ktfmt from 0.16 to 0.18 ([#748](https://github.com/diffplug/spotless/issues/748))

## [2.10.2] - 2020-11-16
### Fixed
* Fixed a bug which occurred if the root directory of the project was also the filesystem root ([#732](https://github.com/diffplug/spotless/pull/732))

## [2.10.1] - 2020-11-13
### Fixed
* Bump JGit from `5.8.0` to `5.9.0` to improve performance ([#726](https://github.com/diffplug/spotless/issues/726))

## [2.10.0] - 2020-11-02
### Added
* Added support to npm-based steps for picking up `.npmrc` files ([#727](https://github.com/diffplug/spotless/pull/727))

## [2.9.0] - 2020-10-20
### Added
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

0 comments on commit 8891bfb

Please sign in to comment.