]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: fix regression with --stat and unmerged file
authorPeter Grayson <pete@jpgrayson.net>
Wed, 14 Dec 2022 17:41:51 +0000 (12:41 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Dec 2022 00:12:04 +0000 (09:12 +0900)
A regression was introduced in

  12fc4ad89e (diff.c: use utf8_strwidth() to count display width, 2022-09-14)

that causes missing newlines after "Unmerged" entries in `git diff
--cached --stat` output.

This problem affects v2.39.0-rc0 through v2.39.0.

Add the missing newline along with a new test to cover this
behavior.

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
t/t4046-diff-unmerged.sh

diff --git a/diff.c b/diff.c
index 2751cae1315a17a4de692a7a6f8a55a0ffb032f1..7e88d7e27ac0b5b2c887091d9e56a14a6d280ac9 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -2784,7 +2784,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
                else if (file->is_unmerged) {
                        strbuf_addf(&out, " %s%s%*s | %*s",
                                    prefix, name, padding, "",
-                                   number_width, "Unmerged");
+                                   number_width, "Unmerged\n");
                        emit_diff_symbol(options, DIFF_SYMBOL_STATS_LINE,
                                         out.buf, out.len, 0);
                        strbuf_reset(&out);
index 0ae0cd3a524da312d7f1cc7b1d4b0f6ed7b2b529..ffaf69335f7b224f76ece7228435a4ce057e5c83 100755 (executable)
@@ -86,4 +86,14 @@ test_expect_success 'diff-files -3' '
        test_cmp diff-files-3.expect diff-files-3.actual
 '
 
+test_expect_success 'diff --stat' '
+       for path in $paths
+       do
+               echo " $path | Unmerged" || return 1
+       done >diff-stat.expect &&
+       echo " 0 files changed" >>diff-stat.expect &&
+       git diff --cached --stat >diff-stat.actual &&
+       test_cmp diff-stat.expect diff-stat.actual
+'
+
 test_done