Skip to content

Commit

Permalink
Fix issue with root windows drive found in #760
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Jan 4, 2021
1 parent be2150c commit 793e20b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)).
* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)).
* fixed error when running on root of windows mountpoint ([#760](https://github.com/diffplug/spotless/pull/760)).

## [2.10.2] - 2020-11-16
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/FileSignature.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -200,6 +200,9 @@ public static String subpath(String root, String child) {
if (child.startsWith(root)) {
return child.substring(root.length());
} else {
if (machineIsWin() && root.endsWith("://") && child.startsWith(root.substring(0, root.length() - 1))) {
return child.substring(root.length() - 1);
}
throw new IllegalArgumentException("Expected '" + child + "' to start with '" + root + "'");
}
}
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* `ratchetFrom` now works with git-submodule ([#746](https://github.com/diffplug/spotless/issues/746))
* ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)).
* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)).
* fixed error when running on root of windows mountpoint ([#760](https://github.com/diffplug/spotless/pull/760)).

## [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 @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Fix broken test for spotlessFiles parameter on windows ([#737](https://github.com/diffplug/spotless/pull/737))
* ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)).
* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)).
* fixed error when running on root of windows mountpoint ([#760](https://github.com/diffplug/spotless/pull/760)).

## [2.6.1] - 2020-11-16
### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 DiffPlug
* Copyright 2016-2021 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.List;

import org.assertj.core.api.Assertions;
import org.junit.Test;

public class FileSignatureTest extends ResourceHarness {
Expand Down Expand Up @@ -79,4 +80,11 @@ private List<File> getTestFiles(final String[] paths) throws IOException {
public void testSubpath() {
assertThat(FileSignature.subpath("root/", "root/child")).isEqualTo("child");
}

@Test
public void windowsRoot() {
org.junit.Assume.assumeTrue(FileSignature.machineIsWin());
String subpath = FileSignature.subpath("S://", "S:/build.gradle");
Assertions.assertThat(subpath).isEqualTo("build.gradle");
}
}

0 comments on commit 793e20b

Please sign in to comment.