@@ -116,6 +116,21 @@ func DeleteBranch(ctx *context.APIContext) {
116116 // "404":
117117 // "$ref": "#/responses/notFound"
118118
119+ if ctx .Repo .Repository .IsEmpty {
120+ ctx .Error (http .StatusNotFound , "" , "Git Repository is empty." )
121+ return
122+ }
123+
124+ if ctx .Repo .Repository .IsArchived {
125+ ctx .Error (http .StatusForbidden , "" , "Git Repository is archived." )
126+ return
127+ }
128+
129+ if ctx .Repo .Repository .IsMirror {
130+ ctx .Error (http .StatusForbidden , "" , "Git Repository is a mirror." )
131+ return
132+ }
133+
119134 branchName := ctx .Params ("*" )
120135
121136 if err := repo_service .DeleteBranch (ctx , ctx .Doer , ctx .Repo .Repository , ctx .Repo .GitRepo , branchName ); err != nil {
@@ -162,17 +177,30 @@ func CreateBranch(ctx *context.APIContext) {
162177 // responses:
163178 // "201":
164179 // "$ref": "#/responses/Branch"
180+ // "403":
181+ // description: The branch is archived or a mirror.
165182 // "404":
166183 // description: The old branch does not exist.
167184 // "409":
168185 // description: The branch with the same name already exists.
169186
170- opt := web .GetForm (ctx ).(* api.CreateBranchRepoOption )
171187 if ctx .Repo .Repository .IsEmpty {
172188 ctx .Error (http .StatusNotFound , "" , "Git Repository is empty." )
173189 return
174190 }
175191
192+ if ctx .Repo .Repository .IsArchived {
193+ ctx .Error (http .StatusForbidden , "" , "Git Repository is archived." )
194+ return
195+ }
196+
197+ if ctx .Repo .Repository .IsMirror {
198+ ctx .Error (http .StatusForbidden , "" , "Git Repository is a mirror." )
199+ return
200+ }
201+
202+ opt := web .GetForm (ctx ).(* api.CreateBranchRepoOption )
203+
176204 var oldCommit * git.Commit
177205 var err error
178206
@@ -280,7 +308,12 @@ func ListBranches(ctx *context.APIContext) {
280308
281309 listOptions := utils .GetListOptions (ctx )
282310
283- if ! ctx .Repo .Repository .IsEmpty && ctx .Repo .GitRepo != nil {
311+ if ! ctx .Repo .Repository .IsEmpty {
312+ if ctx .Repo .GitRepo == nil {
313+ ctx .Error (http .StatusInternalServerError , "Load git repository failed" , nil )
314+ return
315+ }
316+
284317 rules , err := git_model .FindRepoProtectedBranchRules (ctx , ctx .Repo .Repository .ID )
285318 if err != nil {
286319 ctx .Error (http .StatusInternalServerError , "FindMatchedProtectedBranchRules" , err )
0 commit comments