Skip to content

Commit 061b981

Browse files
authored
Merge pull request #594 from diffplug/feat/fix-ratchet
Fix a bug in GitRatchet which meant that it only worked on files in root directory
2 parents e04fae5 + 5efdf30 commit 061b981

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

Diff for: plugin-gradle/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Fixed
7+
* `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))
68

79
## [4.1.0] - 2020-06-01
810
### Added

Diff for: plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchet.java

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static boolean isClean(Project project, ObjectId treeSha, File file) thro
6666
DirCache dirCache = repo.readDirCache();
6767

6868
try (TreeWalk treeWalk = new TreeWalk(repo)) {
69+
treeWalk.setRecursive(true);
6970
treeWalk.addTree(treeSha);
7071
treeWalk.addTree(new DirCacheIterator(dirCache));
7172
treeWalk.addTree(new FileTreeIterator(repo));

Diff for: plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RatchetFromTest.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.junit.Test;
2020

2121
public class RatchetFromTest extends GradleIntegrationTest {
22+
private static final String TEST_PATH = "src/markdown/test.md";
23+
2224
@Test
2325
public void singleProjectExhaustive() throws Exception {
2426
Git git = Git.init().setDirectory(rootFolder()).call();
@@ -29,13 +31,13 @@ public void singleProjectExhaustive() throws Exception {
2931
"spotless {",
3032
" ratchetFrom 'baseline'",
3133
" format 'misc', {",
32-
" target '*.md'",
34+
" target 'src/markdown/*.md'",
3335
" custom 'lowercase', { str -> str.toLowerCase() }",
3436
" bumpThisNumberIfACustomStepChanges(1)",
3537
" }",
3638
"}");
37-
setFile("test.md").toContent("HELLO");
38-
git.add().addFilepattern("test.md").call();
39+
setFile(TEST_PATH).toContent("HELLO");
40+
git.add().addFilepattern(TEST_PATH).call();
3941
git.commit().setMessage("Initial state").call();
4042
// tag this initial state as the baseline for spotless to ratchet from
4143
git.tag().setName("baseline").call();
@@ -45,41 +47,41 @@ public void singleProjectExhaustive() throws Exception {
4547
assertClean();
4648

4749
// but if we change it so that it is not clean, spotless will now say it is dirty
48-
setFile("test.md").toContent("HELLO WORLD");
50+
setFile(TEST_PATH).toContent("HELLO WORLD");
4951
assertDirty();
5052
gradleRunner().withArguments("spotlessApply").build();
51-
assertFile("test.md").hasContent("hello world");
53+
assertFile(TEST_PATH).hasContent("hello world");
5254

5355
// but if we make it unchanged again, it goes back to being clean
54-
setFile("test.md").toContent("HELLO");
56+
setFile(TEST_PATH).toContent("HELLO");
5557
assertClean();
5658

5759
// and if we make the index dirty
58-
setFile("test.md").toContent("HELLO WORLD");
59-
git.add().addFilepattern("test.md").call();
60+
setFile(TEST_PATH).toContent("HELLO WORLD");
61+
git.add().addFilepattern(TEST_PATH).call();
6062
{
6163
// and the content dirty in the same way, then it's dirty
6264
assertDirty();
6365
// if we make the content something else dirty, then it's dirty
64-
setFile("test.md").toContent("HELLO MOM");
66+
setFile(TEST_PATH).toContent("HELLO MOM");
6567
assertDirty();
6668
// if we make the content unchanged, even though index it and index are dirty, then it's clean
67-
setFile("test.md").toContent("HELLO");
69+
setFile(TEST_PATH).toContent("HELLO");
6870
assertClean();
6971
// if we delete the file, but it's still in the index, then it's clean
70-
setFile("test.md").deleted();
72+
setFile(TEST_PATH).deleted();
7173
assertClean();
7274
}
7375
// if we remove the file from the index
74-
git.rm().addFilepattern("test.md").setCached(true).call();
76+
git.rm().addFilepattern(TEST_PATH).setCached(true).call();
7577
{
7678
// and it's gone in real life too, then it's clean
7779
assertClean();
7880
// if the content is there and unchanged, then it's clean
79-
setFile("test.md").toContent("HELLO");
81+
setFile(TEST_PATH).toContent("HELLO");
8082
assertClean();
8183
// if the content is dirty, then it's dirty
82-
setFile("test.md").toContent("HELLO WORLD");
84+
setFile(TEST_PATH).toContent("HELLO WORLD");
8385
assertDirty();
8486
}
8587

Diff for: plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RegisterDependenciesTaskTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public void registerDependencies() throws IOException {
4343
if (JreVersion.thisVm() == JreVersion._8) {
4444
String oldestSupported = gradleRunner()
4545
.withArguments("spotlessCheck").build().getOutput();
46-
Assertions.assertThat(oldestSupported.replace("\r", "")).startsWith(
47-
":spotlessCheck UP-TO-DATE\n" +
48-
":spotlessInternalRegisterDependencies\n" +
49-
":sub:spotlessJava\n" +
46+
Assertions.assertThat(oldestSupported.replace("\r", ""))
47+
.startsWith(":spotlessCheck UP-TO-DATE\n" +
48+
":spotlessInternalRegisterDependencies\n")
49+
.contains(":sub:spotlessJava\n" +
5050
":sub:spotlessJavaCheck\n" +
5151
":sub:spotlessCheck\n" +
5252
"\n" +
@@ -56,10 +56,10 @@ public void registerDependencies() throws IOException {
5656
setFile("gradle.properties").toLines();
5757
String newestSupported = gradleRunner().withGradleVersion("6.0")
5858
.withArguments("spotlessCheck").build().getOutput();
59-
Assertions.assertThat(newestSupported.replace("\r", "")).startsWith(
60-
"> Task :spotlessCheck UP-TO-DATE\n" +
61-
"> Task :spotlessInternalRegisterDependencies\n" +
62-
"> Task :sub:spotlessJava\n" +
59+
Assertions.assertThat(newestSupported.replace("\r", ""))
60+
.startsWith("> Task :spotlessCheck UP-TO-DATE\n" +
61+
"> Task :spotlessInternalRegisterDependencies\n")
62+
.contains("> Task :sub:spotlessJava\n" +
6363
"> Task :sub:spotlessJavaCheck\n" +
6464
"> Task :sub:spotlessCheck\n" +
6565
"\n" +

0 commit comments

Comments
 (0)