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 8417226f8b..3fa80457ac 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 d7d863b032..71637d188a 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 2e8565b9e2..1822af0be6 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 0000000000..cef4ca2dcb --- /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 0000000000..cef4ca2dcb --- /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 zcmV-11J3+-0hN)b8A*NHUflnW2M#@~~ zlDgF^)zd4fep%ZzbObDv&~Ia36rf~@n56=jayctX63;0xE6M^XB!{AmQUMZFDm-L5 z(iis;@RFjid699MTnGvW5nm#S6@;unGL&;9$goscj%UboytF+S=#y}{*G6w8YqxnT-$}JU-Es!J&T?cgK_aTv zBuSI~)SaZtZMTbD{@DBaFfA>{{_FN=J!h+*4ffDUE)HgvyI=Bs#elsSoP#EoTR(YD z)$Q7x-emS^cvuB!3Gm|uH)p)ujK^kIJrv(LWvXwFE4QPE<7#L`2AJ{HQS?geiJH+it!1QPNsutD=rutcU^YhCJ|OZ2k4T*P`yo z*0-JRhEDGrpR*1X<}Ujal5m2`TI2;-reYarBc;AtI%(}O;J{lKSum8c;V%ve4xy_O z$HX3s2{*i+aaq~*=c_k@c*+_~2dTVJIpVx<1C7ZYNBDsK z*^GNg-V{xF>yLQjNl#b9<9iI}*MrY$wC$Z+%7CUU%*#=bPN{(&&+Ad&Mi9f;NAQIA zM{?a09ZS#ja<05;g39LJDd*#tKiJh#td%wWWay?rV<9?waUI#mx@Vn{5-l>`=0)kb voqNo>7xA(*7;)E1n`JkAW573aKkS$v%ou_GD`J?U>BbrSz>@g~RMAuP6o8_s 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 4804d9d8fe..c5e92eb229 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