Bitbucket Data Center: 409 when creating a pull request
Bitbucket Data Center (formerly Bitbucket Server) answers a request to create a pull request with 409 Conflict when the pull request cannot exist as asked. Its REST API definition puts five cases under that one status and says to check the error message for which one it is. The one people meet most is a branch with nothing new on it: Bitbucket does not open an empty pull request, so a pull request opened before the work starts needs one commit first.
The five cases
Atlassian's REST API definition (Bitbucket 9.4) lists them for POST /rest/api/latest/projects/{project}/repos/{repo}/pull-requests. The names in brackets are the exceptions in Atlassian's API reference.
- The target branch already has every commit of the source branch (
EmptyPullRequestException: the pull request "would have no commits"). Nothing would be merged. In the web interface Bitbucket warns instead of opening the form; a 2014 request quotes the warning as Branch "master" is already up-to-date with branch "NewFeature" (BSERV-4925). - The source and the target are the same branch.
- A pull request between the two branches is already open (
DuplicatePullRequestException). Commits pushed to the source branch go into the open one; a second pull request is not needed. - The target repository is archived. Atlassian's documentation (Archive a repository) says an archived repository is read-only and pull requests cannot be created in it.
- A reviewer cannot be added (
InvalidPullRequestReviewersException): the user does not exist or does not have permission to view the pull request.
A pull request before the first commit
Some teams open the pull request as soon as the branch exists, so that reviewers follow the work as it is pushed. Bitbucket Data Center does not do this: the request to allow an empty pull request (BSERV-4300, January 2014) and the one to warn and create it anyway (BSERV-4925, July 2014) are both closed as "Answered". The way around it is a commit with no changes, which Git allows:
git commit --allow-empty -m "Start the login page" git push -u origin feature/login
The pull request then has one commit, and every later push to the branch is added to it.
What to do
- Already up-to-date: first check that the commits are on Bitbucket: commits made after the last push are only on your machine. Then check the target: if the work was merged there already, there is nothing left to review. If you want the pull request before the work, push an empty commit (above).
- The same branch: pick the branch the work should be merged into.
- Already open: find it with
GET …/pull-requests?at=refs/heads/{branch}&direction=OUTGOING(open pull requests from that branch;attakes the full branch name), and push to its source branch. To change its title or description, edit that pull request. - Archived: a repository admin can unarchive it (Repository settings, Repository details, Manage repository, Unarchive), or the pull request goes to another repository.
- A reviewer: create it without that user, then add reviewers on the pull request.
Bitbucket Cloud
Bitbucket Cloud's API definition lists no 409 for creating a pull request; its 400 covers an invalid request. Until August 2022, creating one whose source and destination were the same commit made Cloud's API hang until "504 Gateway Time-out" (BCLOUD-22009); Atlassian marked it fixed on August 3, 2022.
Bitbucket pull requests in IntelliJ IDEA
Pull Request Inbox for Bitbucket, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pull requests that wait for your review in an IDE tool window, from Bitbucket Cloud and, in beta, from Bitbucket Data Center 8.9 or later with a personal HTTP access token, sent only to that server. Its Create Pull Request checks the usual causes before it sends anything, on Cloud and Data Center: the target cannot be the source branch; a branch that was never pushed gets a Push button that opens the IDE's push dialog; commits not pushed yet are pointed out (Push, or Create Anyway); and from version 1.0.31 a branch with no commits the target lacks is not sent, and you are told why. From 1.0.37, if Bitbucket refuses one of the default reviewers, the pull request is created without them and the notification names who was refused. Other refusals, such as a pull request already open, show Bitbucket's own message. The review inbox, diffs and discussions are free; creating pull requests, approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
Bitbucket and Atlassian are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: You are attempting to modify a pull request based on out-of-date information · Default reviewers · Bitbucket pull request plugins for IntelliJ IDEA, compared · 日本語