@@ -14,6 +14,7 @@ import (
14
14
"testing"
15
15
16
16
auth_model "code.gitea.io/gitea/models/auth"
17
+ "code.gitea.io/gitea/models/db"
17
18
repo_model "code.gitea.io/gitea/models/repo"
18
19
"code.gitea.io/gitea/models/unittest"
19
20
user_model "code.gitea.io/gitea/models/user"
@@ -24,6 +25,7 @@ import (
24
25
"code.gitea.io/gitea/tests"
25
26
26
27
"github.com/stretchr/testify/assert"
28
+ "github.com/stretchr/testify/require"
27
29
)
28
30
29
31
func testAPINewFile (t * testing.T , session * TestSession , user , repo , branch , treePath , content string ) * httptest.ResponseRecorder {
@@ -60,7 +62,9 @@ func TestEmptyRepoAddFile(t *testing.T) {
60
62
session := loginUser (t , "user30" )
61
63
req := NewRequest (t , "GET" , "/user30/empty" )
62
64
resp := session .MakeRequest (t , req , http .StatusOK )
63
- assert .Contains (t , resp .Body .String (), "empty-repo-guide" )
65
+ bodyString := resp .Body .String ()
66
+ assert .Contains (t , bodyString , "empty-repo-guide" )
67
+ assert .True (t , test .IsNormalPageCompleted (bodyString ))
64
68
65
69
req = NewRequest (t , "GET" , "/user30/empty/_new/" + setting .Repository .DefaultBranch )
66
70
resp = session .MakeRequest (t , req , http .StatusOK )
@@ -80,6 +84,21 @@ func TestEmptyRepoAddFile(t *testing.T) {
80
84
req = NewRequest (t , "GET" , redirect )
81
85
resp = session .MakeRequest (t , req , http .StatusOK )
82
86
assert .Contains (t , resp .Body .String (), "newly-added-test-file" )
87
+
88
+ // the repo is not empty anymore
89
+ req = NewRequest (t , "GET" , "/user30/empty" )
90
+ resp = session .MakeRequest (t , req , http .StatusOK )
91
+ assert .Contains (t , resp .Body .String (), "test-file.md" )
92
+
93
+ // if the repo is in incorrect state, it should be able to self-heal (recover to correct state)
94
+ user30EmptyRepo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {OwnerID : 30 , Name : "empty" })
95
+ user30EmptyRepo .IsEmpty = true
96
+ user30EmptyRepo .DefaultBranch = "no-such"
97
+ _ , err := db .GetEngine (db .DefaultContext ).ID (user30EmptyRepo .ID ).Update (user30EmptyRepo )
98
+ require .NoError (t , err )
99
+ req = NewRequest (t , "GET" , "/user30/empty" )
100
+ resp = session .MakeRequest (t , req , http .StatusOK )
101
+ assert .Contains (t , resp .Body .String (), "test-file.md" )
83
102
}
84
103
85
104
func TestEmptyRepoUploadFile (t * testing.T ) {
0 commit comments