mirror of
https://github.com/go-gitea/gitea
synced 2025-01-19 06:04:26 +00:00
Fix tag route and empty repo (#33253)
This commit is contained in:
parent
10b6047498
commit
80cc87b3d8
@ -249,7 +249,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
|
|||||||
} else if reallyEmpty {
|
} else if reallyEmpty {
|
||||||
showEmpty = true // the repo is really empty
|
showEmpty = true // the repo is really empty
|
||||||
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
|
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
|
||||||
} else if ctx.Repo.Commit == nil {
|
} else if branches, _, _ := ctx.Repo.GitRepo.GetBranches(0, 1); len(branches) == 0 {
|
||||||
showEmpty = true // it is not really empty, but there is no branch
|
showEmpty = true // it is not really empty, but there is no branch
|
||||||
// at the moment, other repo units like "actions" are not able to handle such case,
|
// at the moment, other repo units like "actions" are not able to handle such case,
|
||||||
// so we just mark the repo as empty to prevent from displaying these units.
|
// so we just mark the repo as empty to prevent from displaying these units.
|
||||||
|
@ -1335,8 +1335,7 @@ func registerRoutes(m *web.Router) {
|
|||||||
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
|
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
|
||||||
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
|
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
|
||||||
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
|
repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
|
||||||
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
|
m.Post("/tags/delete", reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.DeleteTag)
|
||||||
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
|
|
||||||
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
|
}, optSignIn, context.RepoAssignment, reqRepoCodeReader)
|
||||||
// end "/{username}/{reponame}": repo tags
|
// end "/{username}/{reponame}": repo tags
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -24,6 +25,7 @@ import (
|
|||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testAPINewFile(t *testing.T, session *TestSession, user, repo, branch, treePath, content string) *httptest.ResponseRecorder {
|
func testAPINewFile(t *testing.T, session *TestSession, user, repo, branch, treePath, content string) *httptest.ResponseRecorder {
|
||||||
@ -60,7 +62,9 @@ func TestEmptyRepoAddFile(t *testing.T) {
|
|||||||
session := loginUser(t, "user30")
|
session := loginUser(t, "user30")
|
||||||
req := NewRequest(t, "GET", "/user30/empty")
|
req := NewRequest(t, "GET", "/user30/empty")
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.Contains(t, resp.Body.String(), "empty-repo-guide")
|
bodyString := resp.Body.String()
|
||||||
|
assert.Contains(t, bodyString, "empty-repo-guide")
|
||||||
|
assert.True(t, test.IsNormalPageCompleted(bodyString))
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
|
req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
@ -80,6 +84,21 @@ func TestEmptyRepoAddFile(t *testing.T) {
|
|||||||
req = NewRequest(t, "GET", redirect)
|
req = NewRequest(t, "GET", redirect)
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.Contains(t, resp.Body.String(), "newly-added-test-file")
|
assert.Contains(t, resp.Body.String(), "newly-added-test-file")
|
||||||
|
|
||||||
|
// the repo is not empty anymore
|
||||||
|
req = NewRequest(t, "GET", "/user30/empty")
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
assert.Contains(t, resp.Body.String(), "test-file.md")
|
||||||
|
|
||||||
|
// if the repo is in incorrect state, it should be able to self-heal (recover to correct state)
|
||||||
|
user30EmptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 30, Name: "empty"})
|
||||||
|
user30EmptyRepo.IsEmpty = true
|
||||||
|
user30EmptyRepo.DefaultBranch = "no-such"
|
||||||
|
_, err := db.GetEngine(db.DefaultContext).ID(user30EmptyRepo.ID).Update(user30EmptyRepo)
|
||||||
|
require.NoError(t, err)
|
||||||
|
req = NewRequest(t, "GET", "/user30/empty")
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
assert.Contains(t, resp.Body.String(), "test-file.md")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyRepoUploadFile(t *testing.T) {
|
func TestEmptyRepoUploadFile(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user