Re: [PATCH 2/2] builtin/repo: fix table alignment for UTF-8 characters
- From
Jiang Xin <worldhello.net@gmail.com>
- Date
- Nov 16, 2025, 13:32 UTC
- Message-ID
- <CANYiYbFcap=c8xDy-=ZyaY3U4-jU9OEe18LPgTEAHi2wx2M0VQ@mail.gmail.com>
- In-Reply-To
- <xmqqtsyvfe2f.fsf@gitster.g>
On Sun, Nov 16, 2025 at 12:36 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
>
> Jiang Xin <worldhello.net@gmail.com> writes:
>
> >> > builtin/repo.c | 22 ++++++++++++++++++----
> >> > 1 file changed, 18 insertions(+), 4 deletions(-)
> >>
> >> ... it is a good idea to protect the change with a new test or two
> >> to make sure the expected alignment in the output.
> >
> > Will add test cases for strbuf_utf8_align(), a function newly
> > introduced in builtin/repo.c.
>
> Unit tests are nice to make sure that building blocks like this
> helper function works as expected. To ensure that the application
> uses the building blocks correctly, you'd also need end-to-end test,
> getting output out of the tool ("repo struct"?) and checking it.t1901 already includes test cases to safeguard the output of the "git repo structure" command. I could add a new test case to validate the output when localized in Chinese (as shown below), but such a test would be inherently unstable, because it risks breaking at the end of every release cycle whenever translations change. Therefore, I feel it's better to fix the issue by using strbuf_utf8_align() and adding dedicated unit tests for it, rather than relying on fragile end-to-end localization tests.
-------- 8< --------
diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh index 36a71a144e..fdab0a3d29 100755 --- a/t/t1901-repo-structure.sh +++ b/t/t1901-repo-structure.sh @@ -34,6 +34,37 @@ test_expect_success 'empty repository' ' ) ' +test_expect_success 'output repo structure in non-ASCII glyphs' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + cat >expect <<-\EOF && + | 仓库结构 | 值 | + | -------------- | -- | + | * 引用 | | + | * 计数 | 0 | + | * 分支 | 0 | + | * 标签 | 0 | + | * 远程 | 0 | + | * 其它 | 0 | + | | | + | * 可达的对象 | | + | * 计数 | 0 | + | * 提交 | 0 | + | * 树 | 0 | + | * 数据对象 | 0 | + | * 标签 | 0 | + EOF + + env LC_ALL=zh_CN.utf-8 \ + git repo structure >out 2>err && + + test_cmp expect out && + test_line_count = 0 err + ) +' + test_expect_success 'repository with references and objects' ' test_when_finished "rm -rf repo" && git init repo &&