aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2019-07-22 14:03:15 +0200
committerLauris BH <lauris@nix.lv>2019-07-22 15:03:15 +0300
commitfe7689a6b28b644ef309350cf01f563201f44d10 (patch)
tree7d5d5ff94892be59e56eb7d4d59fcadf40e5ff96 /modules
parentb0cd3b8ab9b174f11fd4db8737106be5caf9cc1c (diff)
downloadgitea-fe7689a6b28b644ef309350cf01f563201f44d10.tar.gz
gitea-fe7689a6b28b644ef309350cf01f563201f44d10.zip
Fix empty commits now showing in repo overview (#7521)
* Fix empty commits now showing in repo overview * add test * make fmt
Diffstat (limited to 'modules')
-rw-r--r--modules/git/commit_info.go4
-rw-r--r--modules/git/commit_info_test.go21
-rw-r--r--modules/git/repo_stats_test.go8
-rw-r--r--modules/git/tests/repos/repo1_bare/logs/HEAD1
-rw-r--r--modules/git/tests/repos/repo1_bare/logs/refs/heads/master1
-rw-r--r--modules/git/tests/repos/repo1_bare/objects/fe/af4ba6bc635fec442f46ddd4512416ec43c2c2bin0 -> 817 bytes
-rw-r--r--modules/git/tests/repos/repo1_bare/refs/heads/master2
7 files changed, 24 insertions, 13 deletions
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 <me@silverwind.io> 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 <me@silverwind.io> 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 0000000000..95edd9a65b
--- /dev/null
+++ b/modules/git/tests/repos/repo1_bare/objects/fe/af4ba6bc635fec442f46ddd4512416ec43c2c2
Binary files differ
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