Specs - Pull request created plan branch on wrong plan
Asked by joshuayhloCW:

**Background**

I've got a repository in Stash / Bitbucket Server. Let's say it's in a project called FOO, and the repository is named bar. It has a **develop** and **master** branch.

In Bamboo Server, I've got a linked repository corresponding to each branch:

```
FOO / bar / develop
FOO / bar / master
```

I created a Specs (a .java) such that it contains definitions for two plans - one for the develop branch and one for the master branch. I pass the string corresponding to the linked repository to each Plan generator:

```
public Plan createMasterPlan() {
    .linkedRepositories("FOO / bar / master")
    
    ...
}

public Plan createDevelopPlan() {
    .linkedRepositories("FOO / bar / develop")

    ...
}
```

**Problem**

Later on, I decided to add plan branch management to each. However, on the master plan, I specified **createForPullRequest** and on the develop plan I specified **createForVcsBranch**.

I also have Stash configured to retrieve Bamboo build statuses and attach them to commits. While creating a branch in Stash creates a plan branch on the **develop** plan as expected, ***pull requests to*** **develop*create a plan branch on the* master *plan.***

I'm not particularly sure how to explain this behaviour. I'd like for pull requests to develop to *not* create a plan branch for master. I assume this happens because of the mismatched plan branch management definitions. Can anyone confirm? Anyone else seen behaviour like this before?

**EDIT**

I just changed the plan branch management definitions in my Specs to use **createForPullRequest** for both.

Apparently this has the same problem: the pull request I create causes two plan branches to be created - one for develop, one for master.


Answers:
author: Daniel Santos
body: Hi [@joshuayhloCW](/t5/user/viewprofilepage/user-id/1880923)

Firstly, thank you for your detailed issue description of this question.

Moving to the answer part, I have to say that this is the expected behavior. The *createForPullRequest* configuration will create a new plan branch for any pull request submitted to a plan that references the source repository affected. In other words, if you create a pull request to develop or any other branch, all plans referencing the affected repository will get a new plan branch.

**Linked repository clarification**

The branch you use for a linked repository will only define what will be the default branch for that plan. It will not restrict the plan branch creation to that branch. This is the same behavior you see when you configure both plans to *createForVcsBranch*and create a new branch, which will create the new branch in both of them.

**Feature requested**

We have a couple of users that see this as a limitation in the pull request feature and therefore created a feature request to add a regex expression to this feature so you can decide in which conditions the pull request would be created. A similar feature already exists to *createForVcsBranch* option. This is the one:

* [\[BAM-19825\] Branch regular expression filter for automatic PR detection](https://jira.atlassian.com/browse/BAM-19825)

There is no workaround for this at the moment. If you cannot have pull requests from other branches created in that same plan, the only option I see is disabling the *createForPullRequest* feature.

I hope I was able to clarify this scenario.


Tags: spec

branch

plan

pull-request