]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t4073: add test for diffstat paths length when containing UTF-8 chars
authorLorenzoPegorari <lorenzo.pegorari2002@gmail.com>
Fri, 16 Jan 2026 00:05:38 +0000 (01:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 17 Jan 2026 17:47:27 +0000 (09:47 -0800)
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>
t/meson.build
t/t4073-diff-stat-name-width.sh [new file with mode: 0755]

index a5531df415ffe2cda8ff81fd688e9cb1e6717ab4..73edae4e3d8a6470c098dbcf2579dbbc9a6988e1 100644 (file)
@@ -496,6 +496,7 @@ integration_tests = [
   't4070-diff-pairs.sh',
   't4071-diff-minimal.sh',
   't4072-diff-max-depth.sh',
+  't4073-diff-stat-name-width.sh',
   't4100-apply-stat.sh',
   't4101-apply-nonl.sh',
   't4102-apply-rename.sh',
diff --git a/t/t4073-diff-stat-name-width.sh b/t/t4073-diff-stat-name-width.sh
new file mode 100755 (executable)
index 0000000..ec5d3c3
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+test_description='git-diff check diffstat filepaths length when containing UTF-8 chars'
+
+. ./test-lib.sh
+
+
+create_files () {
+       mkdir -p "d你好" &&
+       touch "d你好/f再见"
+}
+
+test_expect_success 'setup' '
+       git init &&
+       git config core.quotepath off &&
+       git commit -m "Initial commit" --allow-empty &&
+       create_files &&
+       git add . &&
+       git commit -m "Added files"
+'
+
+test_expect_success 'test name-width long enough for filepath' '
+       git diff HEAD~1 HEAD --stat --stat-name-width=12 >out &&
+       grep "d你好/f再见 |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=11 >out &&
+       grep "d你好/f再见 |" out
+'
+
+test_expect_success 'test name-width not long enough for dir name' '
+       git diff HEAD~1 HEAD --stat --stat-name-width=10 >out &&
+       grep ".../f再见  |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=9 >out &&
+       grep ".../f再见 |" out
+'
+
+test_expect_success 'test name-width not long enough for slash' '
+       git diff HEAD~1 HEAD --stat --stat-name-width=8 >out &&
+       grep "...f再见 |" out
+'
+
+test_expect_success 'test name-width not long enough for file name' '
+       git diff HEAD~1 HEAD --stat --stat-name-width=7 >out &&
+       grep "...再见 |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=6 >out &&
+       grep "...见  |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=5 >out &&
+       grep "...见 |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=4 >out &&
+       grep "...  |" out
+'
+
+test_expect_success 'test name-width minimum length' '
+       git diff HEAD~1 HEAD --stat --stat-name-width=3 >out &&
+       grep "... |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=2 >out &&
+       grep "... |" out &&
+       git diff HEAD~1 HEAD --stat --stat-name-width=1 >out &&
+       grep "... |" out
+'
+
+test_done