-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Low
-
None
-
Affects Version/s: 10.1.1
-
Component/s: Pull Request - Merge
-
None
-
1
-
Severity 3 - Minor
-
4
Issue Summary
When a branch is associated with at least one Pull Request, and you go to Branches (<base-url>/projects/<project-key>/repos/<repo-slug>/branches) and try to delete the branch, the branch will not be deleted, and you will correctly see an error message at the bottom left of the screen saying:
You cannot delete this branch since it has at least one open pull request associated with it
However, when the branch is associated with more than one Pull Request, and you select the "Delete <branch-name> after merging" checkbox when merging one of the Pull Requests, the branch will be deleted, even though it is still associated with other Pull Requests. This is incorrect behavior
Steps to Reproduce
- Create three branches: Branch_A, Branch_B, and Branch_C
- Commit and push changes in each branch
- Create two Pull Requests:
-
- PR #1: From Branch_C to Branch_B
- PR #2: From Branch_B to Branch_A
- Go to Branches and try to delete, for example, Branch_B
- The branch will correctly not be deleted, and you will correctly see the error message saying "You cannot delete this branch since it has at least one open pull request associated with it"
- Now, go to PR #2, from Branch_B to Branch_A, click the Merge button, mark the “Delete Branch_B after merging“ checkbox, and click the Merge button.
- The Pull Request will be merged. However, it shouldn’t have been merged because it should not allow deleting Branch_B, as this branch is also associated with the Pull Request 1 (from Branch_C to Branch_B).
- As you can see, different features exhibit varying behaviors when it comes to branch deletion, particularly when the branch is associated with multiple Pull Requests.
Expected Results
The merge should be blocked if the “Delete <branch-name> after merging“ checkbox is marked and the given <branch-name> is associated with other Pull Requests.
The behavior should be consistent between the two features. Branch deletion should be blocked if the branch is associated with multiple Pull Requests.
Actual Results
Unlike the Branches feature, which blocks branches from being deleted if the branch in question is associated with one or more Pull Requests, the Pull Request merge feature doesn't check if the branch is associated with other Pull Requests before deleting the branch marked for deletion.
Workaround
When multiple pull requests target the same branch, this automatic deletion may not always be desirable. Here are a few suggestions on how you might manage this:
- Disable automatic branch deletion: If you prefer to manage branch deletions manually, you can disable the "Delete <branch-name> after merging" option when merging Pull Requests. This way, you maintain full control over when and which branches are deleted.
- Use a naming convention or process: Implementing a naming convention or a specific workflow for branches that are critical to multiple pull requests can be helpful. This might involve using clearly defined prefixes or suffixes for branches that are not ready to be deleted automatically.
- Review target branch dependencies: Before merging a pull request, review any dependencies or other pull requests targeting the same branch to assess potential impacts.