Skip to content

Delete non-exist branch should return 404#36694

Merged
lunny merged 20 commits intogo-gitea:mainfrom
lunny:lunny/delete_branch_not_exist
Mar 2, 2026
Merged

Delete non-exist branch should return 404#36694
lunny merged 20 commits intogo-gitea:mainfrom
lunny:lunny/delete_branch_not_exist

Conversation

@lunny
Copy link
Copy Markdown
Member

@lunny lunny commented Feb 21, 2026

Fix #36682

@lunny lunny added type/bug backport/v1.25 This PR should be backported to Gitea 1.25 labels Feb 21, 2026
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 21, 2026
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Feb 21, 2026
@silverwind silverwind requested a review from Copilot February 22, 2026 08:48
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 22, 2026

panic in test is related. Next time, please run tests before you put up a PR please. It's as simple as asking "run tests" to your agent and it will only run tests that are affected by your change.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #36682 where deleting a non-existent branch through the API incorrectly returns 204 (No Content) instead of 404 (Not Found). The fix adds a check in the DeleteBranch service function to return an error when attempting to delete a branch that doesn't exist in either the database or the git repository.

Changes:

  • Added error check to return git.ErrBranchNotExist when deleting a non-existent branch
  • Added unit test to verify the correct error is returned when deleting non-existent branches

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
services/repository/branch.go Added check (lines 599-601) to return git.ErrBranchNotExist when both database and git repository indicate the branch doesn't exist
services/repository/branch_test.go Added unit test that verifies deleting a non-existent branch returns the correct error

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 24, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 24, 2026
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 24, 2026
@wxiaoguang wxiaoguang marked this pull request as draft February 25, 2026 04:21
@wxiaoguang wxiaoguang marked this pull request as ready for review February 25, 2026 07:31
@wxiaoguang wxiaoguang marked this pull request as draft February 25, 2026 14:57
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Feb 26, 2026
@wxiaoguang wxiaoguang closed this Mar 2, 2026
@wxiaoguang wxiaoguang reopened this Mar 2, 2026
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Mar 2, 2026
@wxiaoguang wxiaoguang marked this pull request as ready for review March 2, 2026 17:13
@wxiaoguang wxiaoguang removed the backport/v1.25 This PR should be backported to Gitea 1.25 label Mar 2, 2026
@wxiaoguang wxiaoguang added this to the 1.26.0 milestone Mar 2, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 2, 2026
@wxiaoguang wxiaoguang requested a review from Copilot March 2, 2026 17:23
@wxiaoguang wxiaoguang added reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Mar 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wxiaoguang wxiaoguang force-pushed the lunny/delete_branch_not_exist branch from 1c5409c to 7da60b1 Compare March 2, 2026 17:34
@wxiaoguang wxiaoguang force-pushed the lunny/delete_branch_not_exist branch from 7da60b1 to ca3da14 Compare March 2, 2026 17:35
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
@lunny lunny merged commit 0e0daa8 into go-gitea:main Mar 2, 2026
26 checks passed
@lunny lunny deleted the lunny/delete_branch_not_exist branch March 2, 2026 19:08
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 4, 2026
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  Remove API registration-token (go-gitea#36801)
  Add background and run count to actions list page (go-gitea#36707)
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 6, 2026
* origin/main: (27 commits)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
  Fix non-admins unable to automerge PRs from forks (go-gitea#36833)
  upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837)
  Fix dump release asset bug (go-gitea#36799)
  build(deps): update material-icon-theme v5.32.0 (go-gitea#36832)
  Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465)
  Fix forwarded proto handling for public URL detection (go-gitea#36810)
  Fix artifacts v4 backend upload problems (go-gitea#36805)
  Add a git grep search timeout (go-gitea#36809)
  fix(repo): unify DEFAULT_SHOW_FULL_NAME output in templates and dropdown (go-gitea#36597)
  Harden render iframe open-link handling (go-gitea#36811)
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  ...

# Conflicts:
#	routers/web/repo/issue_view.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting non-existent branch through API returns 204

6 participants