Mittwoch, 2. September 2009

Agile versioning for FEST (1): Branching



The FEST-Assert subproject recently agreed to try agile versioning. This post describes the technical details specific to the FEST variant of agile versioning and how you can branch/merge using Eclipse and IntelliJ IDEA.

Subversion repository layout


The repository is laid out as follows:


/branches/fest-assert
/branches/fest-assert/experimental
/branches/fest-assert/experimental/...
/branches/fest-assert/issues
/branches/fest-assert/issues/000/FEST-1/
...
/branches/fest-assert/issues/000/FEST-99/
/branches/fest-assert/issues/100/FEST-101/
/branches/fest-assert/issues/200/FEST-199/
...
/fest-assert
/fest-assert/pom.xml
/fest-assert/src
...


As you might have noticed, we have a bit of a mixture of two different repository layout styles: the trunk is in /fest-assert, whereas the branches are under /branches/fest-assert. One would probably expect the branches to live under /fest-assert/branches and its trunk under /fest-assert/trunk, so we'd get:


/fest-assert
/fest-assert/trunk/pom.xml
/fest-assert/trunk/src
...
/fest-assert/branches/issues/100/FEST-101
/fest-assert/branches/issues/100/FEST-101/pom.xml
/fest-assert/branches/issues/100/FEST-101/src...


I assume we might switch to this more consistent layout somewhen in the future if the rest of the team is satisfied with the day-to-day experience of this new versioning technique.


Branching with Eclipse



I'm using Eclipse 3.4 with the Subclipse plugin as the basis to describe how to branch. First, open the "SVN Repositories" view (using Window → Show view → Other → SVN).



Once opened, right-click into the new view and choose New → Repository Location. Use FEST's subversion URL, then finish. A new repository location appears in the repositories view. Expand it using the small triangle at its left. You will eventually be prompted for your SVN username and password. Expanding the whole folder tree inside the repository, you'll get something like this:



To derive a new branch from the trunk, right-click the current trunk /fest-assert and choose "Branch/Tag" from the context menu:



In the new dialog, you'll see the resource you are going to branch (https://svn.codehaus.org/fest) and the target URL, where you're going to copy/branch this resource to. Use the Select... button to modify the default target. This will open a repository browser in a separate window.




Expand FEST's repository root until you reach /branches/fest-assert/issues/<NUMBER>, where <NUMBER> is the lower bound of the 100 issue-number range where the issue you would like to implement a solution for falls into. If there is no folder with a matching <NUMBER> yet, just create one (right-click on folder issues, then select New remote folder). Select the matching <NUMBER> folder, then click OK.



You'll be returned to the previous dialog. All you still have to enter manually is the name of the new branch you want to create. Start the branch name with the issue identifier (FEST-nnn), optionally followed by a dash and a short descriptive name of what you are going to fix in this branch.



Click Next>, confirm to branch from the HEAD revision of the trunk by another Next>, finally enter a commit comment for this branching operation (like 'Created development branch for FEST-nnn') and finally use Finish to trigger the actual branch creation.

Checkout this branch into your workspace and you're ready to do development work in this new branch. Choose the regular checkout function (not: Checkout as Maven project), since this allows you to specify the project name inside the workspace manually. Append something like -FESTnnn to the prefilled project name, this will allow you to work with multiple branches of the same project simultaneously.


Branching with IntelliJ IDEA




Choose Version Control → Browse Subversion Repository from the main menu. If not done yet, add the FEST repository root to the repository browser using the [+] icon at the top. Expand the repository tree until you find the FEST Assert trunk at /fest-assert. Right click fest-assert and choose Branch or Tag... from the context menu.



Unlike Eclipse's wizard-style GUI for branching, IDEA allows you to specify all relevant information in one dialog. Expand the repository tree until you reach /branches/issues/<nnn>, where <nnn> is the lower bound of the 100 issue-number range containing the issue you want to fix. Select <nnn> and enter the name of the new branch into the appropriate text field:



Add a commit message and confirm all settings using OK. Checkout this branch using the regular checkout feature of IDEA and commit/update as usual.


Next steps: Merge early, merge often.



Okay, now you have a separate branch for development. As other developers might work in parallel on a different branch, and even merge their changes into the trunk when they're done, you need to get the latest changes from the trunk regularly to keep your development branch in sync. If your development branch deviates too much from the trunk, it can potentially become very hard to reintegrate your development branch into the trunk once you are done with your development on this branch.

The next post in this series will thus cover the topics:

  • keeping your development branch in sync with the trunk (merge down)

  • reintegrating your development branch into the trunk (copy up)


See you next time - happy coding :-)