Skip to content

Fix a bug in GitRatchet which meant that it only worked on files in root directory #594

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

Merged
merged 3 commits into from
Jun 3, 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
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Fixed
* `ratchetFrom` had a bug (now fixed) such that it reported all files outside the root directory as changed. ([#594](https://github.com/diffplug/spotless/pull/594))

## [4.1.0] - 2020-06-01
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static boolean isClean(Project project, ObjectId treeSha, File file) thro
DirCache dirCache = repo.readDirCache();

try (TreeWalk treeWalk = new TreeWalk(repo)) {
treeWalk.setRecursive(true);
treeWalk.addTree(treeSha);
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(new FileTreeIterator(repo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.Test;

public class RatchetFromTest extends GradleIntegrationTest {
private static final String TEST_PATH = "src/markdown/test.md";

@Test
public void singleProjectExhaustive() throws Exception {
Git git = Git.init().setDirectory(rootFolder()).call();
Expand All @@ -29,13 +31,13 @@ public void singleProjectExhaustive() throws Exception {
"spotless {",
" ratchetFrom 'baseline'",
" format 'misc', {",
" target '*.md'",
" target 'src/markdown/*.md'",
" custom 'lowercase', { str -> str.toLowerCase() }",
" bumpThisNumberIfACustomStepChanges(1)",
" }",
"}");
setFile("test.md").toContent("HELLO");
git.add().addFilepattern("test.md").call();
setFile(TEST_PATH).toContent("HELLO");
git.add().addFilepattern(TEST_PATH).call();
git.commit().setMessage("Initial state").call();
// tag this initial state as the baseline for spotless to ratchet from
git.tag().setName("baseline").call();
Expand All @@ -45,41 +47,41 @@ public void singleProjectExhaustive() throws Exception {
assertClean();

// but if we change it so that it is not clean, spotless will now say it is dirty
setFile("test.md").toContent("HELLO WORLD");
setFile(TEST_PATH).toContent("HELLO WORLD");
assertDirty();
gradleRunner().withArguments("spotlessApply").build();
assertFile("test.md").hasContent("hello world");
assertFile(TEST_PATH).hasContent("hello world");

// but if we make it unchanged again, it goes back to being clean
setFile("test.md").toContent("HELLO");
setFile(TEST_PATH).toContent("HELLO");
assertClean();

// and if we make the index dirty
setFile("test.md").toContent("HELLO WORLD");
git.add().addFilepattern("test.md").call();
setFile(TEST_PATH).toContent("HELLO WORLD");
git.add().addFilepattern(TEST_PATH).call();
{
// and the content dirty in the same way, then it's dirty
assertDirty();
// if we make the content something else dirty, then it's dirty
setFile("test.md").toContent("HELLO MOM");
setFile(TEST_PATH).toContent("HELLO MOM");
assertDirty();
// if we make the content unchanged, even though index it and index are dirty, then it's clean
setFile("test.md").toContent("HELLO");
setFile(TEST_PATH).toContent("HELLO");
assertClean();
// if we delete the file, but it's still in the index, then it's clean
setFile("test.md").deleted();
setFile(TEST_PATH).deleted();
assertClean();
}
// if we remove the file from the index
git.rm().addFilepattern("test.md").setCached(true).call();
git.rm().addFilepattern(TEST_PATH).setCached(true).call();
{
// and it's gone in real life too, then it's clean
assertClean();
// if the content is there and unchanged, then it's clean
setFile("test.md").toContent("HELLO");
setFile(TEST_PATH).toContent("HELLO");
assertClean();
// if the content is dirty, then it's dirty
setFile("test.md").toContent("HELLO WORLD");
setFile(TEST_PATH).toContent("HELLO WORLD");
assertDirty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public void registerDependencies() throws IOException {
if (JreVersion.thisVm() == JreVersion._8) {
String oldestSupported = gradleRunner()
.withArguments("spotlessCheck").build().getOutput();
Assertions.assertThat(oldestSupported.replace("\r", "")).startsWith(
":spotlessCheck UP-TO-DATE\n" +
":spotlessInternalRegisterDependencies\n" +
":sub:spotlessJava\n" +
Assertions.assertThat(oldestSupported.replace("\r", ""))
.startsWith(":spotlessCheck UP-TO-DATE\n" +
":spotlessInternalRegisterDependencies\n")
.contains(":sub:spotlessJava\n" +
":sub:spotlessJavaCheck\n" +
":sub:spotlessCheck\n" +
"\n" +
Expand All @@ -56,10 +56,10 @@ public void registerDependencies() throws IOException {
setFile("gradle.properties").toLines();
String newestSupported = gradleRunner().withGradleVersion("6.0")
.withArguments("spotlessCheck").build().getOutput();
Assertions.assertThat(newestSupported.replace("\r", "")).startsWith(
"> Task :spotlessCheck UP-TO-DATE\n" +
"> Task :spotlessInternalRegisterDependencies\n" +
"> Task :sub:spotlessJava\n" +
Assertions.assertThat(newestSupported.replace("\r", ""))
.startsWith("> Task :spotlessCheck UP-TO-DATE\n" +
"> Task :spotlessInternalRegisterDependencies\n")
.contains("> Task :sub:spotlessJava\n" +
"> Task :sub:spotlessJavaCheck\n" +
"> Task :sub:spotlessCheck\n" +
"\n" +
Expand Down