Skip to content

Commit 426fd2a

Browse files
silverwindlafriks
authored andcommitted
Fix empty commits now showing in repo overview (#7521) (#7563)
* Fix empty commits now showing in repo overview * add test * make fmt
1 parent 337f262 commit 426fd2a

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

modules/git/commit_info.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
6868
// get it for free during the tree traversal and it's used for listing
6969
// pages to display information about newest commit for a given path.
7070
var treeCommit *Commit
71-
if rev, ok := revs[""]; ok {
71+
if treePath == "" {
72+
treeCommit = commit
73+
} else if rev, ok := revs[""]; ok {
7274
treeCommit = convertCommit(rev)
7375
}
7476
return commitsInfo, treeCommit, nil

modules/git/commit_info_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ func cloneRepo(url, dir, name string) (string, error) {
2828
func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
2929
// these test case are specific to the repo1 test repo
3030
testCases := []struct {
31-
CommitID string
32-
Path string
33-
ExpectedIDs map[string]string
31+
CommitID string
32+
Path string
33+
ExpectedIDs map[string]string
34+
ExpectedTreeCommit string
3435
}{
3536
{"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", "", map[string]string{
3637
"file1.txt": "95bb4d39648ee7e325106df01a621c530863a653",
3738
"file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
38-
}},
39+
}, "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2"},
3940
{"2839944139e0de9737a044f78b0e4b40d989a9e3", "", map[string]string{
4041
"file1.txt": "2839944139e0de9737a044f78b0e4b40d989a9e3",
4142
"branch1.txt": "9c9aef8dd84e02bc7ec12641deb4c930a7c30185",
42-
}},
43+
}, "2839944139e0de9737a044f78b0e4b40d989a9e3"},
4344
{"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", "branch2", map[string]string{
4445
"branch2.txt": "5c80b0245c1c6f8343fa418ec374b13b5d4ee658",
45-
}},
46+
}, "5c80b0245c1c6f8343fa418ec374b13b5d4ee658"},
47+
{"feaf4ba6bc635fec442f46ddd4512416ec43c2c2", "", map[string]string{
48+
"file1.txt": "95bb4d39648ee7e325106df01a621c530863a653",
49+
"file2.txt": "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
50+
"foo": "37991dec2c8e592043f47155ce4808d4580f9123",
51+
}, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2"},
4652
}
4753
for _, testCase := range testCases {
4854
commit, err := repo1.GetCommit(testCase.CommitID)
@@ -51,7 +57,8 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
5157
assert.NoError(t, err)
5258
entries, err := tree.ListEntries()
5359
assert.NoError(t, err)
54-
commitsInfo, _, err := entries.GetCommitsInfo(commit, testCase.Path, nil)
60+
commitsInfo, treeCommit, err := entries.GetCommitsInfo(commit, testCase.Path, nil)
61+
assert.Equal(t, testCase.ExpectedTreeCommit, treeCommit.ID.String())
5562
assert.NoError(t, err)
5663
assert.Len(t, commitsInfo, len(testCase.ExpectedIDs))
5764
for _, commitInfo := range commitsInfo {

modules/git/repo_stats_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ func TestRepository_GetCodeActivityStats(t *testing.T) {
2323
assert.NoError(t, err)
2424
assert.NotNil(t, code)
2525

26-
assert.EqualValues(t, 8, code.CommitCount)
27-
assert.EqualValues(t, 2, code.AuthorCount)
28-
assert.EqualValues(t, 8, code.CommitCountInAllBranches)
26+
assert.EqualValues(t, 9, code.CommitCount)
27+
assert.EqualValues(t, 3, code.AuthorCount)
28+
assert.EqualValues(t, 9, code.CommitCountInAllBranches)
2929
assert.EqualValues(t, 10, code.Additions)
3030
assert.EqualValues(t, 1, code.Deletions)
31-
assert.Len(t, code.Authors, 2)
31+
assert.Len(t, code.Authors, 3)
3232
assert.Contains(t, code.Authors, "[email protected]")
3333
assert.EqualValues(t, 3, code.Authors["[email protected]"])
3434
assert.EqualValues(t, 5, code.Authors[""])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
37991dec2c8e592043f47155ce4808d4580f9123 feaf4ba6bc635fec442f46ddd4512416ec43c2c2 silverwind <[email protected]> 1563741799 +0200 push
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
37991dec2c8e592043f47155ce4808d4580f9123 feaf4ba6bc635fec442f46ddd4512416ec43c2c2 silverwind <[email protected]> 1563741799 +0200 push
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
37991dec2c8e592043f47155ce4808d4580f9123
1+
feaf4ba6bc635fec442f46ddd4512416ec43c2c2

0 commit comments

Comments
 (0)