|
|
|
|
|
|
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
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" |
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
"code.gitea.io/gitea/tests" |
|
|
"code.gitea.io/gitea/tests" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testAPIDeleteBranch(t, "master", http.StatusForbidden) |
|
|
testAPIDeleteBranch(t, "master", http.StatusForbidden) |
|
|
testAPIDeleteBranch(t, "branch2", http.StatusNoContent) |
|
|
testAPIDeleteBranch(t, "branch2", http.StatusNoContent) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAPICreateBranchWithSyncBranches(t *testing.T) { |
|
|
|
|
|
defer tests.PrepareTestEnv(t)() |
|
|
|
|
|
|
|
|
|
|
|
branches, err := git_model.FindBranches(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 = git_model.FindBranches(db.DefaultContext, git_model.FindBranchOptions{ |
|
|
|
|
|
RepoID: 1, |
|
|
|
|
|
}) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
assert.Len(t, branches, 5) |
|
|
|
|
|
|
|
|
|
|
|
branches, err = git_model.FindBranches(db.DefaultContext, git_model.FindBranchOptions{ |
|
|
|
|
|
RepoID: 1, |
|
|
|
|
|
Keyword: "new_branch", |
|
|
|
|
|
}) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
assert.Len(t, branches, 1) |
|
|
|
|
|
} |