Skip to content

--delete-branch fails, if branch is deleted already (race condition) #11187

@V0idC0de

Description

@V0idC0de

Describe the bug

When using gh pr merge --delete-branch, the command sometimes fails, if the branch was deleted already. This is unintuitive, since I want to make sure the branch is cleaned up and don't care how it happens, unless it interferes with the actual command.

#1279 already addresses this behavior, but I'm still getting an error.
I wondered, whether this is intentional or not. If intentional, where is the difference to the behavior addressed in the aforementioned PR and how I should go about ensuring the branch is gone after the merge, without risking a pipeline fail.

Affected version

GitHub CLI 2.74.2 (pipeline ran today and was using the Ubuntu 24.04 runner image, thus this is the installed version)

Steps to reproduce the behavior

  1. Write pipeline which merges a PR
  2. Set the repository to delete the branch itself (or insert a sleep into the pipeline and do it yourself)
  3. Let the pipeline run the "gh pr merge --delete-branch" command on that PR
  4. gh will error with a HTTP 404

Expected vs actual behavior

I'd expect the command to not error, but gracefully handle the error and suppressing it, since it matches the intent.
Currently it fails with failed to delete remote branch <redacted>: HTTP 404: Reference does not exist (https://api.github.com/repos/<redacted>).
#1279 already addresses this issue, but the caught error doesn't include the HTTP 404 I'm observing here.

I'd argue, that the command should not raise this error, since my intention is "branch should be cleaned up and gone after merge". If the branch is already gone, that's fine, as far as I'm concerned. The fact, that the branch was deleted by some other actor has no impact on my gh pr merge command, since the merge already happened, thus the command shouldn't care and shouldn't fail, just because it could not delete the branch by itself.

Logs

There is only one relevant log line, as gh pr merge doesn't output anything else for me.

failed to delete remote branch <redacted>: HTTP 404: Reference does not exist (https://api.github.com/repos/<redacted>)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggh-prrelating to the gh pr commandpriority-3Affects a small number of users or is largely cosmetic

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions