t4073: add test for diffstat paths length when containing UTF-8 chars

Add test checking the length of filepaths containing UTF-8 chars when generating a diffstat with various `name-width`s. Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com> [jc: fixed up t/meson.build to spell the name of the new test file correctly] Signed-off-by: Junio C Hamano <gitster@pobox.com>

LorenzoPegorari committed Jan 16, 2026 at 01:05 UTC 04f5d95ef7715e952c93f078e2973c44bb6f3396
2 files changed +62
t/meson.build
+1
@@ -496,6 +496,7 @@ integration_tests = [
496 't4070-diff-pairs.sh',
497 't4071-diff-minimal.sh',
498 't4072-diff-max-depth.sh',
499 + 't4073-diff-stat-name-width.sh',
500 't4100-apply-stat.sh',
501 't4101-apply-nonl.sh',
502 't4102-apply-rename.sh',
t/t4073-diff-stat-name-width.sh new
+61
@@ -0,0 +1,61 @@
1 +#!/bin/sh
2 +
3 +test_description='git-diff check diffstat filepaths length when containing UTF-8 chars'
4 +
5 +. ./test-lib.sh
6 +
7 +
8 +create_files () {
9 + mkdir -p "d你好" &&
10 + touch "d你好/f再见"
11 +}
12 +
13 +test_expect_success 'setup' '
14 + git init &&
15 + git config core.quotepath off &&
16 + git commit -m "Initial commit" --allow-empty &&
17 + create_files &&
18 + git add . &&
19 + git commit -m "Added files"
20 +'
21 +
22 +test_expect_success 'test name-width long enough for filepath' '
23 + git diff HEAD~1 HEAD --stat --stat-name-width=12 >out &&
24 + grep "d你好/f再见 |" out &&
25 + git diff HEAD~1 HEAD --stat --stat-name-width=11 >out &&
26 + grep "d你好/f再见 |" out
27 +'
28 +
29 +test_expect_success 'test name-width not long enough for dir name' '
30 + git diff HEAD~1 HEAD --stat --stat-name-width=10 >out &&
31 + grep ".../f再见 |" out &&
32 + git diff HEAD~1 HEAD --stat --stat-name-width=9 >out &&
33 + grep ".../f再见 |" out
34 +'
35 +
36 +test_expect_success 'test name-width not long enough for slash' '
37 + git diff HEAD~1 HEAD --stat --stat-name-width=8 >out &&
38 + grep "...f再见 |" out
39 +'
40 +
41 +test_expect_success 'test name-width not long enough for file name' '
42 + git diff HEAD~1 HEAD --stat --stat-name-width=7 >out &&
43 + grep "...再见 |" out &&
44 + git diff HEAD~1 HEAD --stat --stat-name-width=6 >out &&
45 + grep "...见 |" out &&
46 + git diff HEAD~1 HEAD --stat --stat-name-width=5 >out &&
47 + grep "...见 |" out &&
48 + git diff HEAD~1 HEAD --stat --stat-name-width=4 >out &&
49 + grep "... |" out
50 +'
51 +
52 +test_expect_success 'test name-width minimum length' '
53 + git diff HEAD~1 HEAD --stat --stat-name-width=3 >out &&
54 + grep "... |" out &&
55 + git diff HEAD~1 HEAD --stat --stat-name-width=2 >out &&
56 + grep "... |" out &&
57 + git diff HEAD~1 HEAD --stat --stat-name-width=1 >out &&
58 + grep "... |" out
59 +'
60 +
61 +test_done