Skip to content
Permalink
Browse files
398: git webrev cannot handle a file named index.html
Reviewed-by: jvernee
  • Loading branch information
rwestberg committed May 11, 2020
1 parent 9573e79 commit 6b6952e4cdb3c3ad34378d29767d1846e7773ed1
Showing with 29 additions and 2 deletions.
  1. +6 −1 webrev/src/main/java/org/openjdk/skara/webrev/RawView.java
  2. +23 −1 webrev/src/test/java/org/openjdk/skara/webrev/WebrevTests.java
@@ -50,7 +50,12 @@ public RawView(Path out, Path file, byte[] binary) {

public void render(Writer w) throws IOException {
var rawFile = out.resolve(file.toString());
Files.createDirectories(rawFile.getParent());
if (Files.exists(rawFile)) {
// If the raw file collides with a file generated by the webrev (such as index.html), rename it
rawFile = out.resolve("_" + file.toString());
} else {
Files.createDirectories(rawFile.getParent());
}

if (binary != null) {
Files.write(rawFile, binary);
@@ -36,7 +36,7 @@

class WebrevTests {
void assertContains(Path file, String text) throws IOException {
var contents = Files.readString(file);
var contents = Files.readString(file).replaceAll("\\R", "\n");
assertTrue(contents.contains(text));
}

@@ -55,6 +55,7 @@ void simple(VCS vcs) throws IOException {
var hash2 = repo.commit("Commit 2", "a", "a@a.a");

new Webrev.Builder(repo, webrevFolder.path()).generate(hash1, hash2);
assertContains(webrevFolder.path().resolve("x.txt"), "1\n2\n3\n4\n");
assertContains(webrevFolder.path().resolve("index.html"), "<td>1 lines changed; 1 ins; 0 del; 0 mod; 3 unchg</td>");
}
}
@@ -173,4 +174,25 @@ void modifyBinaryFile(VCS vcs) throws IOException {
new Webrev.Builder(repo, tmp.path().resolve("webrev")).generate(hash1, hash2);
}
}

@ParameterizedTest
@EnumSource(VCS.class)
void reservedName(VCS vcs) throws IOException {
try (var repoFolder = new TemporaryDirectory();
var webrevFolder = new TemporaryDirectory()) {
var repo = Repository.init(repoFolder.path(), vcs);
var file = repoFolder.path().resolve("index.html");
Files.writeString(file, "1\n2\n3\n", StandardCharsets.UTF_8);
repo.add(file);
var hash1 = repo.commit("Commit", "a", "a@a.a");
Files.writeString(file, "1\n2\n3\n4\n", StandardCharsets.UTF_8);
repo.add(file);
var hash2 = repo.commit("Commit 2", "a", "a@a.a");

new Webrev.Builder(repo, webrevFolder.path()).generate(hash1, hash2);
assertContains(webrevFolder.path().resolve("_index.html"), "1\n2\n3\n4\n");
assertContains(webrevFolder.path().resolve("index.html"), "<td>1 lines changed; 1 ins; 0 del; 0 mod; 3 unchg</td>");
}
}

}

0 comments on commit 6b6952e

Please sign in to comment.