git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC PATCH v2 2/2] t4052: add test for diffstat width when prefix contains UTF-8 chars

From
LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Date
Feb 27, 2026, 16:08 UTC
Message-ID
<984fa10d728aad049d0430472e85f1ed0e5ea4de.1772136203.git.lorenzo.pegorari2002@gmail.com>
In-Reply-To
<cover.1772136203.git.lorenzo.pegorari2002@gmail.com>

Add test checking the calculation of the diffstat display width when the `line_prefix`, which is text that goes before the diffstat, contains UTF-8 characters.

This situation happens, for example, when `git log --stat --graph` is
executed:
* `--stat` will create a diffstat for each commit
* `--graph` will stuff `line_prefix` with the graph portion of the log,
  which contains UTF-8 characters (ANSI escape codes to color the text)
Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
---
 t/b                    |  0
 t/t4052-stat-output.sh | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 t/b
diff --git a/t/b b/t/b
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
index 740bb97091..cc4665047d 100755
--- a/t/t4052-stat-output.sh
+++ b/t/t4052-stat-output.sh
@@ -413,4 +413,34 @@ test_expect_success 'merge --stat respects COLUMNS with long name' '
 	test_cmp expect actual
 '
 
+# git-log will print only 1 commit containing a single branch graph and a diffstat.
+# The diffstat will be only one file, with a placeholder FILENAME, that, with
+# enough terminal display width, will contain the following line:
+#     "<RED>|<RESET>  ${FILENAME} | 0"
+# where "<RED>" and "<RESET>" are ANSI escape codes to color the text.
+# To calculate the minimium terminal display width MIN_TERM_WIDTH so that the
+# FILENAME in the diffstat will not be shortened, we take the FILENAME length
+# and add 9 to it.
+# To check if the diffstat width, when the line_prefix (the "<RED>|<RESET>" of
+# the graph) contains UTF-8 characters (the ANSI escape codes), is calculated
+# correctly, we:
+#     1. check if it contains the line defined before when using MIN_TERM_WIDTH
+#     2. check if it contains the line defined before, but with the FILENAME
+#        shortened by only one character, when using MIN_TERM_WIDTH - 1
+
+test_expect_success 'diffstat where line_prefix contains UTF-8 chars is correct width' '
+	FILENAME="placeholder-text-placeholder-text" &&
+	FILENAME_TRIMMED="...eholder-text-placeholder-text" &&
+	MIN_TERM_WIDTH=$((${#FILENAME} + 9)) &&
+	test_config color.diff always &&
+	git commit --allow-empty --allow-empty-message &&
+	>${FILENAME} &&
+	git add ${FILENAME} &&
+	git commit --allow-empty-message &&
+	COLUMNS=$((MIN_TERM_WIDTH)) git log --graph --stat -n1 | test_decode_color >out &&
+	test_grep "<RED>|<RESET>  ${FILENAME} | 0" out &&
+	COLUMNS=$((MIN_TERM_WIDTH - 1)) git log --graph --stat -n1 | test_decode_color >out &&
+	test_grep "<RED>|<RESET>  ${FILENAME_TRIMMED} | 0" out
+'
+
 test_done
-- 
2.43.0
Previous: LorenzoPegorariNext: Junio C Hamano
Message 9 of 14 in “diff: handle ANSI chars in prefix when calculating diffstat width”
  1. 0/2 diff: handle ANSI chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 24, 2026
  2. 1/2 diff: handle ANSI chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 24, 2026
  3. 2/2 t4074: add test for diffstat width when prefix contains ANSI charsLorenzoPegorari, Feb 24, 2026
  4. Junio C HamanoFeb 24, 2026
  5. Lorenzo PegorariFeb 25, 2026
  6. Junio C HamanoFeb 24, 2026
  7. 0/2 diff: handle UTF-8 chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  8. 1/2 diff: handle UTF-8 chars in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  9. 2/2 t4052: add test for diffstat width when prefix contains UTF-8 charsLorenzoPegorari, Feb 27, 2026
  10. Junio C HamanoFeb 27, 2026
  11. Junio C HamanoFeb 27, 2026
  12. 0/2 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  13. 1/2 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari, Feb 27, 2026
  14. 2/2 t4052: test for diffstat width when prefix contains ANSI escape codesLorenzoPegorari, Feb 27, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.