mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Implement update branch API (#32433)
Resolves #22526. Builds upon #23061. --------- Co-authored-by: sillyguodong <33891828+sillyguodong@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -386,6 +386,77 @@ func ListBranches(ctx *context.APIContext) { | ||||
| 	ctx.JSON(http.StatusOK, apiBranches) | ||||
| } | ||||
|  | ||||
| // UpdateBranch updates a repository's branch. | ||||
| func UpdateBranch(ctx *context.APIContext) { | ||||
| 	// swagger:operation PATCH /repos/{owner}/{repo}/branches/{branch} repository repoUpdateBranch | ||||
| 	// --- | ||||
| 	// summary: Update a branch | ||||
| 	// consumes: | ||||
| 	// - application/json | ||||
| 	// produces: | ||||
| 	// - application/json | ||||
| 	// parameters: | ||||
| 	// - name: owner | ||||
| 	//   in: path | ||||
| 	//   description: owner of the repo | ||||
| 	//   type: string | ||||
| 	//   required: true | ||||
| 	// - name: repo | ||||
| 	//   in: path | ||||
| 	//   description: name of the repo | ||||
| 	//   type: string | ||||
| 	//   required: true | ||||
| 	// - name: branch | ||||
| 	//   in: path | ||||
| 	//   description: name of the branch | ||||
| 	//   type: string | ||||
| 	//   required: true | ||||
| 	// - name: body | ||||
| 	//   in: body | ||||
| 	//   schema: | ||||
| 	//     "$ref": "#/definitions/UpdateBranchRepoOption" | ||||
| 	// responses: | ||||
| 	//   "204": | ||||
| 	//     "$ref": "#/responses/empty" | ||||
| 	//   "403": | ||||
| 	//     "$ref": "#/responses/forbidden" | ||||
| 	//   "404": | ||||
| 	//     "$ref": "#/responses/notFound" | ||||
| 	//   "422": | ||||
| 	//     "$ref": "#/responses/validationError" | ||||
|  | ||||
| 	opt := web.GetForm(ctx).(*api.UpdateBranchRepoOption) | ||||
|  | ||||
| 	oldName := ctx.PathParam("*") | ||||
| 	repo := ctx.Repo.Repository | ||||
|  | ||||
| 	if repo.IsEmpty { | ||||
| 		ctx.Error(http.StatusNotFound, "", "Git Repository is empty.") | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if repo.IsMirror { | ||||
| 		ctx.Error(http.StatusForbidden, "", "Git Repository is a mirror.") | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, oldName, opt.Name) | ||||
| 	if err != nil { | ||||
| 		ctx.Error(http.StatusInternalServerError, "RenameBranch", err) | ||||
| 		return | ||||
| 	} | ||||
| 	if msg == "target_exist" { | ||||
| 		ctx.Error(http.StatusUnprocessableEntity, "", "Cannot rename a branch using the same name or rename to a branch that already exists.") | ||||
| 		return | ||||
| 	} | ||||
| 	if msg == "from_not_exist" { | ||||
| 		ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.") | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	ctx.Status(http.StatusNoContent) | ||||
| } | ||||
|  | ||||
| // GetBranchProtection gets a branch protection | ||||
| func GetBranchProtection(ctx *context.APIContext) { | ||||
| 	// swagger:operation GET /repos/{owner}/{repo}/branch_protections/{name} repository repoGetBranchProtection | ||||
|   | ||||
		Reference in New Issue
	
	Block a user