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

[GSoC PATCH 2/2] t4074: add test for diffstat width when prefix contains ANSI chars

From
LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Date
Feb 24, 2026, 01:20 UTC
Message-ID
<ce251505932712839dcaabffcd1762760439edff.1771895921.git.lorenzo.pegorari2002@gmail.com>
In-Reply-To
<cover.1771894207.git.lorenzo.pegorari2002@gmail.com>

Add test checking the calculation of the diffstat display width when the line_prefix contains ANSI characters.

Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
---
 t/meson.build                               |  1 +
 t/t4074-diff-stat-width-with-line-prefix.sh | 42 +++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100755 t/t4074-diff-stat-width-with-line-prefix.sh
diff --git a/t/meson.build b/t/meson.build
index f80e366cff..2867ba8a77 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -502,6 +502,7 @@ integration_tests = [
   't4071-diff-minimal.sh',
   't4072-diff-max-depth.sh',
   't4073-diff-stat-name-width.sh',
+  't4074-diff-stat-width-with-line-prefix.sh',
   't4100-apply-stat.sh',
   't4101-apply-nonl.sh',
   't4102-apply-rename.sh',
diff --git a/t/t4074-diff-stat-width-with-line-prefix.sh b/t/t4074-diff-stat-width-with-line-prefix.sh
new file mode 100755
index 0000000000..69ab85bf25
--- /dev/null
+++ b/t/t4074-diff-stat-width-with-line-prefix.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+test_description='git-diff check diffstat width when line_prefix is not empty'
+
+. ./test-lib.sh
+
+
+# The terminal, during a test, should default to a width of 80 columns
+FILE_MAX="filename-with-exact-length-to-take-the-max-amount-of-space-in-diffstat"
+FILE_LONGER="...name-with-exact-length-to-take-the-max-amount-of-space-in-diffstat+"
+
+setup () {
+	rm -rf * ".git" &&
+	git init &&
+	git config color.diff always
+}
+
+test_expect_success 'check width with max name-width' '
+	setup &&
+	touch "${FILE_MAX}" &&
+	git add . &&
+	git commit -m "init" &&
+	echo "text" >"${FILE_MAX}" &&
+	git add . &&
+	git commit -m "text" &&
+	git log --graph --stat >out &&
+	grep "${FILE} | 1" out
+'
+
+test_expect_success 'check width with longer name-width' '
+	setup &&
+	touch "${FILE_MAX}+" &&
+	git add . &&
+	git commit -m "init" &&
+	echo "text" >"${FILE_MAX}+" &&
+	git add . &&
+	git commit -m "text" &&
+	git log --graph --stat >out &&
+	grep "${FILE_LONGER} | 1" out
+'
+
+test_done
-- 
2.43.0
Previous: LorenzoPegorariNext: Junio C Hamano
Message 3 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.