1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-04 16:48:37 +00:00

Do not show 500 error when default branch doesn't exist (#34096) (#34097)

Backport #34096
This commit is contained in:
wxiaoguang
2025-04-02 18:16:41 +08:00
committed by GitHub
parent 25e409e025
commit 8f75f61b64
6 changed files with 49 additions and 4 deletions

View File

@@ -4,12 +4,15 @@
package integration
import (
"context"
"net/http"
"net/url"
"strings"
"testing"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
@@ -61,5 +64,14 @@ func TestRepoActivity(t *testing.T) {
// Should be 3 new issues
list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc")
assert.Len(t, list.Nodes, 3)
// Non-existing default branch
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "repo1"})
repo1.DefaultBranch = "no-such-branch"
_, _ = db.GetEngine(context.Background()).Cols("default_branch").Update(repo1)
req = NewRequest(t, "GET", "/user2/repo1/activity")
req.Header.Add("Accept", "text/html")
resp = session.MakeRequest(t, req, http.StatusNotFound)
assert.Contains(t, resp.Body.String(), `Default branch "no-such-branch" does not exist.`)
})
}