diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Draw no diffstat table for a change to no files
The padding the table gained left an empty commit with a hollow frame
where the file rows would be.
Diffstat (limited to '')
| -rw-r--r-- | source/ui-diff.c | 11 | |
| -rwxr-xr-x | tests/t0106-commit.sh | 10 |
2 files changed, 17 insertions, 4 deletions
diff --git a/source/ui-diff.c b/source/ui-diff.c index 8d8e680..33d1751 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -468,12 +468,15 @@ static void print_diffstat(const struct object_id *old_oid, const struct object_ html("')"); } html("</div>\n"); - html("<table class='diffstat'>\n"); max_changes = 0; cgit_diff_tree(old_oid, new_oid, inspect_filepair, prefix, ctx.qry.ignorews); - for (i = 0; i < files; i++) - print_fileinfo(&items[i]); - html("</table>\n"); + // A change to no files would leave the table an empty frame. + if (files) { + html("<table class='diffstat'>\n"); + for (i = 0; i < files; i++) + print_fileinfo(&items[i]); + html("</table>\n"); + } html("<div class='diffstat-summary'>"); htmlf("%d file%s changed, %d insertion%s, %d deletion%s", files, files == 1 ? "" : "s", diff --git a/tests/t0106-commit.sh b/tests/t0106-commit.sh index 3b50c2b..7de0a76 100755 --- a/tests/t0106-commit.sh +++ b/tests/t0106-commit.sh @@ -28,6 +28,16 @@ test_expect_success 'the diffstat bar is an SVG sized by its attributes' ' grep "<td class=.graph.><svg viewBox=.0 0 1000 1. preserveAspectRatio=.none. aria-hidden=.true.><rect class=.add. width=.1000. height=.1./></svg></td>" tmp ' +test_expect_success 'a commit that changes no files draws no diffstat table' ' + ( + cd repos/foo && + git update-ref refs/heads/empty $(git commit-tree HEAD^{tree} -p HEAD -m empty) + ) && + cgit_url "foo/commit/&h=empty" >tmp && + grep "0 files changed, 0 insertions, 0 deletions" tmp && + ! grep "<table class=.diffstat.>" tmp +' + test_expect_success 'get root commit' ' root=$(cd repos/foo && git rev-list --reverse HEAD | head -1) && cgit_url "foo/commit&id=$root" >tmp && |
