Add option to force update when posting to /contents and new_branch already exists #14984

Closed
opened 2025-11-02 11:27:17 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @robgonnella on GitHub (Sep 25, 2025).

Feature Description

I am currently posting to /api/v1/repos/{owner}/{repo}/contents to update multiple files at once for a new branch; however, this call fails if new_branch already exists. I would love to have an option that would allow the branch to be force updated if it already exists.

Screenshots

No response

Originally created by @robgonnella on GitHub (Sep 25, 2025). ### Feature Description I am currently posting to `/api/v1/repos/{owner}/{repo}/contents` to update multiple files at once for a new branch; however, this call fails if `new_branch` already exists. I would love to have an option that would allow the branch to be force updated if it already exists. ### Screenshots _No response_
GiteaMirror added the type/proposal label 2025-11-02 11:27:17 -06:00
Author
Owner

@robgonnella commented on GitHub (Sep 28, 2025):

@lunny @unknwon @wxiaoguang gentle ping

I did a bit of digging and was able to implement this with just a few minor changes. If you are open to accepting this feature / enhancement, I will work on adding some tests and post a PR.

Also I think this is probably more of an enhancement than a feature, but when I clicked New Issue it only gave me the option for New Feature.

@robgonnella commented on GitHub (Sep 28, 2025): @lunny @unknwon @wxiaoguang gentle ping I did a bit of digging and was able to implement this with just a few minor changes. If you are open to accepting this feature / enhancement, I will work on adding some tests and post a PR. Also I think this is probably more of an `enhancement` than a `feature`, but when I clicked New Issue it only gave me the option for New Feature.
Author
Owner

@robgonnella commented on GitHub (Oct 6, 2025):

@lunny @unknwon @wxiaoguang just checking in again to see if you would be open to this enhancement to the /contents routes. If so I will post a PR. I know you are all very busy so no pressure. I really appreciate all the great work you've put into gitea!

A little context, I'm working on an automated release tool that integrates with multiple forges and this enhancement would unblock an issue in integrating with Gitea.

https://github.com/robgonnella/releasaurus

@robgonnella commented on GitHub (Oct 6, 2025): @lunny @unknwon @wxiaoguang just checking in again to see if you would be open to this enhancement to the `/contents` routes. If so I will post a PR. I know you are all very busy so no pressure. I really appreciate all the great work you've put into `gitea`! A little context, I'm working on an automated release tool that integrates with multiple forges and this enhancement would unblock an issue in integrating with Gitea. https://github.com/robgonnella/releasaurus
Author
Owner

@wxiaoguang commented on GitHub (Oct 6, 2025):

https://github.com/robgonnella/gitea/commits/i-35538/ ?

I haven't fully understood the problem, maybe you can open a PR and explain a bit more about its background (for example: why new_branch already exists and it is out of the caller's control).

By the way, variable "force" looks unclear, usually "force" means every check is skipped, but it isn't in this case.

And unknwon isn't in Gitea's project. He is the owner of gogs project, but Gitea has hard-forked from gogs since 2016 and these two projects are totally different.

@wxiaoguang commented on GitHub (Oct 6, 2025): https://github.com/robgonnella/gitea/commits/i-35538/ ? I haven't fully understood the problem, maybe you can open a PR and explain a bit more about its background (for example: why `new_branch` already exists and it is out of the caller's control). By the way, variable "force" looks unclear, usually "force" means every check is skipped, but it isn't in this case. And unknwon isn't in Gitea's project. He is the owner of gogs project, but Gitea has hard-forked from gogs since 2016 and these two projects are totally different.
Author
Owner

@robgonnella commented on GitHub (Oct 6, 2025):

@wxiaoguang thank you for response! I have opened a PR and added some context in my commit message. The reason new_branch already exists is because the branch is being managed remotely by an automated release tool. Every time commits are merged to the default branch, the automated tool analyzes commits and creates / updates new_branch with changelog updates as well as version updates for various other files. These operations are all performed completely remotely through the API without ever cloning or performing any local git operations. The naming of the variable as "force" is simply to mirror the language and option used when force pushing a branch via git operations i.e. git push --force <branch>. In my PR you'll see that I just tied into an existing "Push" method that already had the "Force" option available.

Also apologies for including unknwon, this is my first contribution to the gitea project and I wasn't sure who to tag so I naively included the top 3 contributors 😅

@robgonnella commented on GitHub (Oct 6, 2025): @wxiaoguang thank you for response! I have opened a PR and added some context in my commit message. The reason `new_branch` already exists is because the branch is being managed remotely by an automated release tool. Every time commits are merged to the default branch, the automated tool analyzes commits and creates / updates `new_branch` with changelog updates as well as version updates for various other files. These operations are all performed completely remotely through the API without ever cloning or performing any local git operations. The naming of the variable as "force" is simply to mirror the language and option used when force pushing a branch via git operations i.e. `git push --force <branch>`. In my PR you'll see that I just tied into an existing "Push" method that already had the "Force" option available. Also apologies for including unknwon, this is my first contribution to the gitea project and I wasn't sure who to tag so I naively included the top 3 contributors 😅
Author
Owner

@wxiaoguang commented on GitHub (Oct 7, 2025):

Thank you very much.

The feature is in nightly build now (and of course you can also build your own binary from main branch)

@wxiaoguang commented on GitHub (Oct 7, 2025): Thank you very much. The feature is in nightly build now (and of course you can also build your own binary from main branch) * https://dl.gitea.com/gitea/main-nightly/ * https://hub.docker.com/r/gitea/gitea/tags?name=main-nightly
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#14984