Render unchanged diff lines as grey instead of yellow In Gitiles unified diff formatting (HtmlDiffFormatter), unchanged context lines (starting with ' ') are wrapped in <span class="Diff-change">. Previously, dark mode support introduced --diff-change styled as #960 in light mode and #fdd663 in dark mode, causing all unchanged lines in unified diffs to render as yellowish-brown / yellow instead of neutral grey. Update --diff-change to #666 in light mode and #9aa0a6 in dark mode so that unchanged context lines render in grey matching the secondary text palette. Add unit tests to verify that unchanged lines are formatted with Diff-change and that --diff-change resolves to grey colors instead of yellow in base.css. Bug: b/562476907 google-bug-id: 562476907 TAG=agy CONV=f9f02e8a-5730-4ba4-9c5c-f2415cbb4fd7 Change-Id: Ie3c687845b707161f462b5e5cfe10ce481e9fa2b
diff --git a/javatests/com/google/gitiles/DiffServletTest.java b/javatests/com/google/gitiles/DiffServletTest.java index 295418e..5d59a67 100644 --- a/javatests/com/google/gitiles/DiffServletTest.java +++ b/javatests/com/google/gitiles/DiffServletTest.java
@@ -49,6 +49,8 @@ + " href=\"/b/repo/+/%s/foo\">b/foo</a>", c1.name(), c2.name()); assertThat(actual).contains(diffHeader); + assertThat(actual).contains("<span class=\"Diff-change\"> foo</span>"); + assertThat(actual).contains("<span class=\"Diff-insert\">+contents</span>"); } @Test
diff --git a/javatests/com/google/gitiles/ThemeTest.java b/javatests/com/google/gitiles/ThemeTest.java index 7e91a65..4b8cf5d 100644 --- a/javatests/com/google/gitiles/ThemeTest.java +++ b/javatests/com/google/gitiles/ThemeTest.java
@@ -15,8 +15,10 @@ package com.google.gitiles; import static com.google.common.truth.Truth.assertThat; +import static java.nio.charset.StandardCharsets.UTF_8; import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; +import com.google.common.io.Resources; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; import org.eclipse.jgit.junit.TestRepository; @@ -130,6 +132,19 @@ assertThemeElementsPresent(html); } + @Test + public void diffChangeColorIsGreyNotYellow() throws Exception { + String css = + Resources.toString( + Resources.getResource(Renderer.class, "static/base.css"), UTF_8); + // Unchanged lines in unified diffs are formatted with class Diff-change. + // Ensure --diff-change resolves to grey in both light and dark modes instead of yellow. + assertThat(css).contains("--diff-change: #666;"); + assertThat(css).contains("--diff-change: #9aa0a6;"); + assertThat(css).doesNotContain("--diff-change: #960;"); + assertThat(css).doesNotContain("--diff-change: #fdd663;"); + } + private static void assertThemeElementsPresent(String html) { assertThat(html).contains("id=\"gitiles-theme-toggle\""); assertThat(html).contains("Header-themeToggle");
diff --git a/resources/com/google/gitiles/static/base.css b/resources/com/google/gitiles/static/base.css index d5054e7..8c21311 100644 --- a/resources/com/google/gitiles/static/base.css +++ b/resources/com/google/gitiles/static/base.css
@@ -48,7 +48,7 @@ --diff-hunk: #00c; --diff-delete: #c00; --diff-insert: #080; - --diff-change: #960; + --diff-change: #666; --diff-action-add: #060; --diff-action-delete: #600; --diff-action-rename: #006; @@ -99,7 +99,7 @@ --diff-hunk: #8ab4f8; --diff-delete: #f28b82; --diff-insert: #81c995; - --diff-change: #fdd663; + --diff-change: #9aa0a6; --diff-action-add: #81c995; --diff-action-delete: #f28b82; --diff-action-rename: #8ab4f8; @@ -142,7 +142,7 @@ --diff-hunk: #8ab4f8; --diff-delete: #f28b82; --diff-insert: #81c995; - --diff-change: #fdd663; + --diff-change: #9aa0a6; --diff-action-add: #81c995; --diff-action-delete: #f28b82; --diff-action-rename: #8ab4f8;