Skip to content

Commit be1e0a4

Browse files
authored
Merge pull request #111 from jiaozifs/fix/cannt_delete_def_branch
Fix/cannt delete def branch
2 parents 6b8a30c + 9cbd7ec commit be1e0a4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

controller/branch_ctl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ func (bct BranchController) DeleteBranch(ctx context.Context, w *api.JiaozifsRes
218218
return
219219
}
220220

221+
if params.RefName == repository.HEAD {
222+
w.BadRequest("can not delete HEAD branch")
223+
return
224+
}
225+
221226
workRepo, err := versionmgr.NewWorkRepositoryFromConfig(ctx, operator, repository, bct.Repo, bct.PublicStorageConfig)
222227
if err != nil {
223228
w.Error(err)

integrationtest/branch_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ func BranchSpec(ctx context.Context, urlStr string) func(c convey.C) {
256256
convey.So(err, convey.ShouldBeNil)
257257
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusForbidden)
258258
})
259-
259+
c.Convey("fail to delete default branch", func() {
260+
resp, err := client.DeleteBranch(ctx, userName, repoName, &api.DeleteBranchParams{RefName: "main"})
261+
convey.So(err, convey.ShouldBeNil)
262+
convey.So(resp.StatusCode, convey.ShouldEqual, http.StatusBadRequest)
263+
})
260264
createWip(ctx, c, client, "creat wip for delete", userName, repoName, "feat/sec_branch")
261265
c.Convey("delete branch successful", func() {
262266
resp, err := client.DeleteBranch(ctx, userName, repoName, &api.DeleteBranchParams{RefName: "feat/sec_branch"})

0 commit comments

Comments
 (0)