From fe7689a6b28b644ef309350cf01f563201f44d10 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 22 Jul 2019 14:03:15 +0200 Subject: [PATCH] Fix empty commits now showing in repo overview (#7521) * Fix empty commits now showing in repo overview * add test * make fmt --- modules/git/commit_info.go | 4 +++- modules/git/commit_info_test.go | 21 ++++++++++++------ modules/git/repo_stats_test.go | 8 +++---- modules/git/tests/repos/repo1_bare/logs/HEAD | 1 + .../repos/repo1_bare/logs/refs/heads/master | 1 + .../fe/af4ba6bc635fec442f46ddd4512416ec43c2c2 | Bin 0 -> 817 bytes .../tests/repos/repo1_bare/refs/heads/master | 2 +- 7 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 modules/git/tests/repos/repo1_bare/logs/HEAD create mode 100644 modules/git/tests/repos/repo1_bare/logs/refs/heads/master create mode 100644 modules/git/tests/repos/repo1_bare/objects/fe/af4ba6bc635fec442f46ddd4512416ec43c2c2 diff --git a/modules/git/commit_info.go b/modules/git/commit_info.go index 8417226f8bf..3fa80457ac8 100644 --- a/modules/git/commit_info.go +++ b/modules/git/commit_info.go @@ -68,7 +68,9 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom // get it for free during the tree traversal and it's used for listing // pages to display information about newest commit for a given path. var treeCommit *Commit - if rev, ok := revs[""]; ok { + if treePath == "" { + treeCommit = commit + } else if rev, ok := revs[""]; ok { treeCommit = convertCommit(rev) } return commitsInfo, treeCommit, nil diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go index d7d863b032e..71637d188aa 100644 --- a/modules/git/commit_info_test.go +++ b/modules/git/commit_info_test.go @@ -28,21 +28,27 @@ func cloneRepo(url, dir, name string) (string, error) { func testGetCommitsInfo(t *testing.T, repo1 *Repository) { // these test case are specific to the repo1 test repo testCases := []struct { - CommitID string - Path string - ExpectedIDs map[string]string + CommitID string + Path string + ExpectedIDs map[string]string + ExpectedTreeCommit string }{ {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", "", map[string]string{ "file1.txt": "95bb4d39648ee7e325106df01a621c530863a653", "file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", - }}, + }, "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2"}, {"2839944139e0de9737a044f78b0e4b40d989a9e3", "", map[string]string{ "file1.txt": "2839944139e0de9737a044f78b0e4b40d989a9e3", "branch1.txt": "9c9aef8dd84e02bc7ec12641deb4c930a7c30185", - }}, + }, "2839944139e0de9737a044f78b0e4b40d989a9e3"}, {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", "branch2", map[string]string{ "branch2.txt": "5c80b0245c1c6f8343fa418ec374b13b5d4ee658", - }}, + }, "5c80b0245c1c6f8343fa418ec374b13b5d4ee658"}, + {"feaf4ba6bc635fec442f46ddd4512416ec43c2c2", "", map[string]string{ + "file1.txt": "95bb4d39648ee7e325106df01a621c530863a653", + "file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", + "foo": "37991dec2c8e592043f47155ce4808d4580f9123", + }, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2"}, } for _, testCase := range testCases { commit, err := repo1.GetCommit(testCase.CommitID) @@ -51,7 +57,8 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) { assert.NoError(t, err) entries, err := tree.ListEntries() assert.NoError(t, err) - commitsInfo, _, err := entries.GetCommitsInfo(commit, testCase.Path, nil) + commitsInfo, treeCommit, err := entries.GetCommitsInfo(commit, testCase.Path, nil) + assert.Equal(t, testCase.ExpectedTreeCommit, treeCommit.ID.String()) assert.NoError(t, err) assert.Len(t, commitsInfo, len(testCase.ExpectedIDs)) for _, commitInfo := range commitsInfo { diff --git a/modules/git/repo_stats_test.go b/modules/git/repo_stats_test.go index 2e8565b9e28..1822af0be6c 100644 --- a/modules/git/repo_stats_test.go +++ b/modules/git/repo_stats_test.go @@ -23,12 +23,12 @@ func TestRepository_GetCodeActivityStats(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, code) - assert.EqualValues(t, 8, code.CommitCount) - assert.EqualValues(t, 2, code.AuthorCount) - assert.EqualValues(t, 8, code.CommitCountInAllBranches) + assert.EqualValues(t, 9, code.CommitCount) + assert.EqualValues(t, 3, code.AuthorCount) + assert.EqualValues(t, 9, code.CommitCountInAllBranches) assert.EqualValues(t, 10, code.Additions) assert.EqualValues(t, 1, code.Deletions) - assert.Len(t, code.Authors, 2) + assert.Len(t, code.Authors, 3) assert.Contains(t, code.Authors, "tris.git@shoddynet.org") assert.EqualValues(t, 3, code.Authors["tris.git@shoddynet.org"]) assert.EqualValues(t, 5, code.Authors[""]) diff --git a/modules/git/tests/repos/repo1_bare/logs/HEAD b/modules/git/tests/repos/repo1_bare/logs/HEAD new file mode 100644 index 00000000000..cef4ca2dcb9 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/logs/HEAD @@ -0,0 +1 @@ +37991dec2c8e592043f47155ce4808d4580f9123 feaf4ba6bc635fec442f46ddd4512416ec43c2c2 silverwind 1563741799 +0200 push diff --git a/modules/git/tests/repos/repo1_bare/logs/refs/heads/master b/modules/git/tests/repos/repo1_bare/logs/refs/heads/master new file mode 100644 index 00000000000..cef4ca2dcb9 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare/logs/refs/heads/master @@ -0,0 +1 @@ +37991dec2c8e592043f47155ce4808d4580f9123 feaf4ba6bc635fec442f46ddd4512416ec43c2c2 silverwind 1563741799 +0200 push diff --git a/modules/git/tests/repos/repo1_bare/objects/fe/af4ba6bc635fec442f46ddd4512416ec43c2c2 b/modules/git/tests/repos/repo1_bare/objects/fe/af4ba6bc635fec442f46ddd4512416ec43c2c2 new file mode 100644 index 0000000000000000000000000000000000000000..95edd9a65b2d4f855df57304beea0074786e5d19 GIT binary patch literal 817 zcmbA39r@Nhsc{XX+ zRqd;nwO7_f-Zm*=(V21~KRI4xK}zS0rA*U{EVaFa&TATIpJLKfXm3Z+s^h=L&#SE$=7yK0KWQtJ>$^3zeyy_mt*=Y( z*YD(+ktaPx<+IAUy2Eahwwj!;*k|VXL}QzO4!h>MS#d1)*S}u>HS4-tzH0XNO6~ie zTkY=_vF$lml%nsbwCbvg=j6Xv<}NvvyS+Q+-;LkD40Lsm{d@f_!!~{OeBN&tJoWg} zrtOaZRC}~xuf&{YwQ14zm3~*>-kNhS3i<<98U|k6}fMjx+=e4 zd;8+{$5|OJY%@My4g3=7)m+dw<%DkJRfni~0Zn;jl8-J|ZNA2v@7tnTWp_Jo?~lMs zQ7Nkz^+m7gV0_(X^C2bY@7F!o7ri@iZTsAJZGP{i=Wpf{eWv$Ycv3;rsi-Hc5zCS! zGnAL^i?YgmYxv+mw0NY!luZxy`8fF&t`<6eM6R3De9yeX$eUlEuQqS0I3?x7zH(21 z)#f9WkM8V~mty1DbwK~Mkk#rP4)LD7;j(ArS1pS4%&2=>{crB)$)+b>Ula2;{3vsE z`?`6m&#F$@m%M*`pepT?+__H^Ufa0eWbQpF>;9wR@6DcSk9#7%m9P6N9(($SAAVfT z^Za`A`K&E(=SH7uSf+F4bl?QPm5p-eUkBcI6F7Xs{X@%l_oBPPvfk&v6s_Bn)pY9F zJEDzW%N&yxt*Q%UZyw*3K6j#!uF<_`t}l1atv<6${NpAQiNfn% mvs2A$k`I^{+rOD1e@3G5pLWuWMK6y@{y8w|Cws`n;4c6afTF1Y literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/refs/heads/master b/modules/git/tests/repos/repo1_bare/refs/heads/master index 4804d9d8fed..c5e92eb2297 100644 --- a/modules/git/tests/repos/repo1_bare/refs/heads/master +++ b/modules/git/tests/repos/repo1_bare/refs/heads/master @@ -1 +1 @@ -37991dec2c8e592043f47155ce4808d4580f9123 +feaf4ba6bc635fec442f46ddd4512416ec43c2c2