mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Backport #13511 Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		| @@ -45,15 +45,12 @@ func GetBranch(ctx *context.APIContext) { | ||||
| 	// responses: | ||||
| 	//   "200": | ||||
| 	//     "$ref": "#/responses/Branch" | ||||
| 	//   "404": | ||||
| 	//     "$ref": "#/responses/notFound" | ||||
|  | ||||
| 	if ctx.Repo.TreePath != "" { | ||||
| 		// if TreePath != "", then URL contained extra slashes | ||||
| 		// (i.e. "master/subbranch" instead of "master"), so branch does | ||||
| 		// not exist | ||||
| 		ctx.NotFound() | ||||
| 		return | ||||
| 	} | ||||
| 	branch, err := repo_module.GetBranch(ctx.Repo.Repository, ctx.Repo.BranchName) | ||||
| 	branchName := ctx.Params("*") | ||||
|  | ||||
| 	branch, err := repo_module.GetBranch(ctx.Repo.Repository, branchName) | ||||
| 	if err != nil { | ||||
| 		if git.IsErrBranchNotExist(err) { | ||||
| 			ctx.NotFound(err) | ||||
| @@ -69,7 +66,7 @@ func GetBranch(ctx *context.APIContext) { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	branchProtection, err := ctx.Repo.Repository.GetBranchProtection(ctx.Repo.BranchName) | ||||
| 	branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branchName) | ||||
| 	if err != nil { | ||||
| 		ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) | ||||
| 		return | ||||
| @@ -112,21 +109,17 @@ func DeleteBranch(ctx *context.APIContext) { | ||||
| 	//     "$ref": "#/responses/empty" | ||||
| 	//   "403": | ||||
| 	//     "$ref": "#/responses/error" | ||||
| 	//   "404": | ||||
| 	//     "$ref": "#/responses/notFound" | ||||
|  | ||||
| 	if ctx.Repo.TreePath != "" { | ||||
| 		// if TreePath != "", then URL contained extra slashes | ||||
| 		// (i.e. "master/subbranch" instead of "master"), so branch does | ||||
| 		// not exist | ||||
| 		ctx.NotFound() | ||||
| 		return | ||||
| 	} | ||||
| 	branchName := ctx.Params("*") | ||||
|  | ||||
| 	if ctx.Repo.Repository.DefaultBranch == ctx.Repo.BranchName { | ||||
| 	if ctx.Repo.Repository.DefaultBranch == branchName { | ||||
| 		ctx.Error(http.StatusForbidden, "DefaultBranch", fmt.Errorf("can not delete default branch")) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	isProtected, err := ctx.Repo.Repository.IsProtectedBranch(ctx.Repo.BranchName, ctx.User) | ||||
| 	isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User) | ||||
| 	if err != nil { | ||||
| 		ctx.InternalServerError(err) | ||||
| 		return | ||||
| @@ -136,7 +129,7 @@ func DeleteBranch(ctx *context.APIContext) { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	branch, err := repo_module.GetBranch(ctx.Repo.Repository, ctx.Repo.BranchName) | ||||
| 	branch, err := repo_module.GetBranch(ctx.Repo.Repository, branchName) | ||||
| 	if err != nil { | ||||
| 		if git.IsErrBranchNotExist(err) { | ||||
| 			ctx.NotFound(err) | ||||
| @@ -152,7 +145,7 @@ func DeleteBranch(ctx *context.APIContext) { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if err := ctx.Repo.GitRepo.DeleteBranch(ctx.Repo.BranchName, git.DeleteBranchOptions{ | ||||
| 	if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ | ||||
| 		Force: true, | ||||
| 	}); err != nil { | ||||
| 		ctx.Error(http.StatusInternalServerError, "DeleteBranch", err) | ||||
| @@ -164,7 +157,7 @@ func DeleteBranch(ctx *context.APIContext) { | ||||
| 		ctx.Repo.Repository, | ||||
| 		ctx.Repo.BranchName, | ||||
| 		repofiles.PushUpdateOptions{ | ||||
| 			RefFullName:  git.BranchPrefix + ctx.Repo.BranchName, | ||||
| 			RefFullName:  git.BranchPrefix + branchName, | ||||
| 			OldCommitID:  c.ID.String(), | ||||
| 			NewCommitID:  git.EmptySHA, | ||||
| 			PusherID:     ctx.User.ID, | ||||
| @@ -175,7 +168,7 @@ func DeleteBranch(ctx *context.APIContext) { | ||||
| 		log.Error("Update: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if err := ctx.Repo.Repository.AddDeletedBranch(ctx.Repo.BranchName, c.ID.String(), ctx.User.ID); err != nil { | ||||
| 	if err := ctx.Repo.Repository.AddDeletedBranch(branchName, c.ID.String(), ctx.User.ID); err != nil { | ||||
| 		log.Warn("AddDeletedBranch: %v", err) | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user