Add `ratchetFrom` to maven by nedtwigg · Pull Request #603 · diffplug/spotless

@Test
public void singleProjectExhaustive() throws Exception {
try (Git git = Git.init().setDirectory(rootFolder()).call()) {
setFile("build.gradle").toLines(
"plugins { id 'com.diffplug.gradle.spotless' }",
"spotless {",
" ratchetFrom 'baseline'",
" format 'misc', {",
" target 'src/markdown/*.md'",
" custom 'lowercase', { str -> str.toLowerCase() }",
" bumpThisNumberIfACustomStepChanges(1)",
" }",
"}");
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();
// so at this point we have test.md, and it would normally be dirty,
// but because it is unchanged, spotless says it is clean
assertClean();
// but if we change it so that it is not clean, spotless will now say it is dirty
setFile(TEST_PATH).toContent("HELLO WORLD");
assertDirty();
gradleRunner().withArguments("spotlessApply").build();
assertFile(TEST_PATH).hasContent("hello world");
// but if we make it unchanged again, it goes back to being clean
setFile(TEST_PATH).toContent("HELLO");
assertClean();
// and if we make the index dirty
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_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_PATH).toContent("HELLO");
assertClean();
// if we delete the file, but it's still in the index, then it's clean
setFile(TEST_PATH).deleted();
assertClean();
}
// if we remove the file from the index
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_PATH).toContent("HELLO");
assertClean();
// if the content is dirty, then it's dirty
setFile(TEST_PATH).toContent("HELLO WORLD");
assertDirty();
}
// new files always get checked
setFile("new.md").toContent("HELLO");
{
assertDirty();
// even if they are added
git.add().addFilepattern("new.md").call();
assertDirty();
}
}
}