summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-12-28 15:28:57 +0800
committerGitHub <noreply@github.com>2023-12-28 15:28:57 +0800
commit921df1cbad83dcba37ff12cba88c7d3a69f8588b (patch)
tree2f7e2ad14f2cd284a2740c8198605d5ccc132de9 /tests
parent4cd666d7dcc7531806cde65c6468f93529cc23dd (diff)
downloadgitea-921df1cbad83dcba37ff12cba88c7d3a69f8588b.tar.gz
gitea-921df1cbad83dcba37ff12cba88c7d3a69f8588b.zip
Remove unnecessary syncbranchToDB with tests (#28624)
#28361 introduced `syncBranchToDB` in `CreateNewBranchFromCommit`. This PR will revert the change because it's unnecessary. Every push will already be checked by `syncBranchToDB`. This PR also created a test to ensure it's right.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_branch_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go
index 28e690b356..103f8f707f 100644
--- a/tests/integration/api_branch_test.go
+++ b/tests/integration/api_branch_test.go
@@ -9,6 +9,8 @@ import (
"testing"
auth_model "code.gitea.io/gitea/models/auth"
+ "code.gitea.io/gitea/models/db"
+ git_model "code.gitea.io/gitea/models/git"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
@@ -217,3 +219,37 @@ func TestAPIBranchProtection(t *testing.T) {
testAPIDeleteBranch(t, "master", http.StatusForbidden)
testAPIDeleteBranch(t, "branch2", http.StatusNoContent)
}
+
+func TestAPICreateBranchWithSyncBranches(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
+ RepoID: 1,
+ })
+ assert.NoError(t, err)
+ assert.Len(t, branches, 4)
+
+ // make a broke repository with no branch on database
+ _, err = db.DeleteByBean(db.DefaultContext, git_model.Branch{RepoID: 1})
+ assert.NoError(t, err)
+
+ onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
+ ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
+ giteaURL.Path = ctx.GitPath()
+
+ testAPICreateBranch(t, ctx.Session, "user2", "repo1", "", "new_branch", http.StatusCreated)
+ })
+
+ branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
+ RepoID: 1,
+ })
+ assert.NoError(t, err)
+ assert.Len(t, branches, 5)
+
+ branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
+ RepoID: 1,
+ Keyword: "new_branch",
+ })
+ assert.NoError(t, err)
+ assert.Len(t, branches, 1)
+}