|
9 | 9 | "testing"
|
10 | 10 |
|
11 | 11 | auth_model "code.gitea.io/gitea/models/auth"
|
| 12 | + "code.gitea.io/gitea/models/db" |
| 13 | + git_model "code.gitea.io/gitea/models/git" |
12 | 14 | api "code.gitea.io/gitea/modules/structs"
|
13 | 15 | "code.gitea.io/gitea/tests"
|
14 | 16 |
|
@@ -217,3 +219,37 @@ func TestAPIBranchProtection(t *testing.T) {
|
217 | 219 | testAPIDeleteBranch(t, "master", http.StatusForbidden)
|
218 | 220 | testAPIDeleteBranch(t, "branch2", http.StatusNoContent)
|
219 | 221 | }
|
| 222 | + |
| 223 | +func TestAPICreateBranchWithSyncBranches(t *testing.T) { |
| 224 | + defer tests.PrepareTestEnv(t)() |
| 225 | + |
| 226 | + branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{ |
| 227 | + RepoID: 1, |
| 228 | + }) |
| 229 | + assert.NoError(t, err) |
| 230 | + assert.Len(t, branches, 4) |
| 231 | + |
| 232 | + // make a broke repository with no branch on database |
| 233 | + _, err = db.DeleteByBean(db.DefaultContext, git_model.Branch{RepoID: 1}) |
| 234 | + assert.NoError(t, err) |
| 235 | + |
| 236 | + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { |
| 237 | + ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) |
| 238 | + giteaURL.Path = ctx.GitPath() |
| 239 | + |
| 240 | + testAPICreateBranch(t, ctx.Session, "user2", "repo1", "", "new_branch", http.StatusCreated) |
| 241 | + }) |
| 242 | + |
| 243 | + branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{ |
| 244 | + RepoID: 1, |
| 245 | + }) |
| 246 | + assert.NoError(t, err) |
| 247 | + assert.Len(t, branches, 5) |
| 248 | + |
| 249 | + branches, err = db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{ |
| 250 | + RepoID: 1, |
| 251 | + Keyword: "new_branch", |
| 252 | + }) |
| 253 | + assert.NoError(t, err) |
| 254 | + assert.Len(t, branches, 1) |
| 255 | +} |
0 commit comments