Home

 

Merging

Merging of branches occurs when it is decided that code from one branch should be incorporated into another branch. This might be required for several reasons, such as if a major integration release is about to be released for testing, or if bug fixes are required from the maintenance branch to resolve certain issues.

The scenario here is that development on the main CVS branch has completed and any production fixes made to the Maintenance branch are required in the main branch as a new production build is planned.

To merge the two branches, the following information is required:

The name of the branch or version that contains your changes.

The version from which the branch was created. This is the version name that you supplied when branching.

In our case, the branch is called Maintenance, and the version from which we created the branch was called BRANCH_ROOT.

Merging requires that the target or destination branch be loaded into the workspace before merging in a branch. Because in our scenario the changes are merged to HEAD, the HEAD branch must be loaded in the workspace.

Perform the following in the cvsuser1 workspace:

In the Web perspective right-click RAD75CVSGuide and select Replace With Æ Another Branch or Version.

In the dialog, select HEAD and click OK to load the latest (HEAD) version of the RAD75CVSGuide project into the workspace.

Right-click RAD75CVSGuide and select Team Æ Merge. This displays the dialog shown in Figure | 8-41, which prompts the user for the start and end points of the merge.

Figure 28-41 Selection of the merge start point

Click Browse for the Common base version (start tag) field, expand Versions, select BRANCH_ROOT and click OK.

Click Browse for the Branch or version to be merged (end tag) field, expand Branches, select Maintenance and click OK.

The Select the Merge Points dialog (Figure | 8-41) now shows the start and end tags of the merge, which will be applied to the version in the workspace.

The options to Preview Merge in the synchronize view and Perform the merge into the local workspace provide the facility to select where to perform the merge:

Previewing it in the Synchronize view allows the user to review and make changes to each file as required.
Performing the merge into the local workspace applies the changes immediately into the workspace based on preferences selected in the workspace preferences.

For the example, select Preview Merge in the synchronize view and clear Merge non-conflicting changes and only preview conflicts.

Click Finish to start the merging.

Expand the tree in the Synchronize view to display changes. Verify that there are no conflicts. If there are, then the developer has to resolve these conflicts. In our case, the merge is simple and there are no conflicts (Figure | 8-42).

Figure 28-42 Files required to be merged

Right-click RAD75CVSGuide and select Merge.

This attempts to bring the changes from the branch into the main stream, and because there are no conflicts it completes successfully.

Right-click RAD75CVSGuide and select Team Æ Synchronize with Repository.

Expand the Synchronize view to display the changed files ServletA.java and View2.java (Figure | 8-43).

Figure 28-43 CVS updates to HEAD from the merge

This view shows that the file View2.java is a new file to be added to the repository and that the file ServletA.java has been changed. This is consistent with the changes that were made in the Maintenance branch and now have to be added to the main branch.

Right-click the project and select Commit. In the Commit dialog, add the comment Merged changes from Maintenance branch, and click OK.

The changes from the branch have now been merged into the main development branch.

This scenario, although a simple one, highlights the technique required by users to work with branches. In a real scenario there would be conflicts, and this would require resolution between developers. Be aware that branching and concurrent development is a complex process and requires communication and planning between the two teams.

RAD v7.5 provides the tools to assist developers when merging; however, equally important are procedures for handling situations such as branching and merging of code, which should be established among the team early in a project life cycle.

ibm.com/redbooks