This topic describes how different types of code branches may be analyzed and managed.
Software teams often use code branches to help manage the development of applications. It is often useful to monitor the quality of branches in addition to the main trunk. The actual processes used by each team vary widely according to the type of application and the source code management system used. Semmle Core can be configured to monitor any system.
Semmle Core does not need any special functionality to handle branches. Code branches can be monitored by creating new projects or changing the configuration of existing projects. This section outlines a few common branching scenarios and how to manage them.
Branching from an existing code base
Using short-lived branches
This example assumes that you create a branch for a particular task and then remove the branch when the development is complete. The changes are merged back into the code base that the branch was created from. The branching pattern is then:
When a branch is created, you can create a new
project configuration file for the new branch by copying the original
project file and updating the checkout commands to check out the new branch (see Using createProject to copy an existing project in Creating a new project). This makes it easy to monitor the code during its development.
Development on branches with merge to an integration branch
These examples assume that you have an integration or 'stable' code base that does not itself have any development. Code is changed on the development branches and periodically these changes are merged into the integration branch. The best way to monitor development depends on how frequently changes are merged into the integration branch.
Frequent merges to the integration branch
If changes are merged from the development branches to the integration branch frequently (that is, at least weekly), then the best option may be to monitor only the integration branch and ignore the incremental changes on the development branch or branches. The branching pattern is then as shown below (the green line indicates the monitored branch):
Infrequent merges to the integration branch
If changes are not merged to the integration branch frequently, then it is usually better to monitor all branches in parallel.
You should create a Semmle project configuration for each branch (see Using createProject to copy an existing project in Creating a new project) and monitor all branches in parallel. The projects can either be shown side-by-side, or on separate dashboards.
Development on development and integration branches
This example assumes that you have an integration code base where changes to the code are carried out – in addition to the changes merged from the development branches.
In this situation, it is usually better to monitor all branches in parallel. Create a Semmle project configuration for each branch and monitor all branches in parallel (see Using createProject to copy an existing project in Creating a new project). The projects can either be shown side-by-side, or on separate dashboards.
Branch used for active development changes periodically
This example assumes that there are several branches of the code base, but only one of the branches has active development at any given time. You can choose to monitor only the active branch, and change the project configuration each time the branch for active development changes. To use this technique:
- Keep a single Semmle
projectconfiguration file, always tracking the active branch where new development is taking place
- Each time the active branch for development changes, edit the checkout commands defined in the
projectfile to point to the newly active branch (see Defining checkout commands manually). It does not matter whether new development branches are created each time or whether the same branch is reused.
Stop monitoring a branch
When development of a branch stops, you may also want to stop actively monitoring the branch but keep the data available for comparison in dashboards displayed in Project Insight. You can do this by deleting the nightly call to run addLatestSnapshot for the associated project.