Shan
Shan

Reputation: 5242

Creating sub-projects of a big project in SVN

I have two big project X, Y and several sub-projects under them. I want to create a project repository structure something like this

svnroot/
       |
       |
       Project X -------sub-project Ax (/brunch, /tag, /trunk)
       |           |--- sub-project Bx (/brunch, /tag, /trunk)
       |           |
       |           |--- sub-project Nx (/brunch, /tag, /trunk)
       |           
       Project Y ------sub-project Ay (/brunch, /tag, /trunk)
                  |--- sub-project By (/brunch, /tag, /trunk)
                  |
                  |--- sub-project Ny (/brunch, /tag, /trunk)

I want the sub-projects under the project that are related to be developed independently. All the sub-projects are integrated to make project X or Y. How do I create this project structure? I am looking for a structure such that I can work on any of the hierarchy (project and sub-project level).

Upvotes: 1

Views: 3715

Answers (3)

Edwin Buck
Edwin Buck

Reputation: 70949

I am not a big fan of "embedded" projects in a single SVN repository. They create issues

  1. A check in on one sub-project increases the revision number of unrelated projects.
  2. A build of a sub-project is rarely independent. You typically need to check out the root to build.
  3. The temptation to reach from one sub-project into another without focusing on using deliverables is just too great. Eventually you have some really bad source-to-source interactions.

SVN projects are cheap. Run svnadmin create a few times and use a template to provide a unified password access scheme.

Upvotes: 1

Ben
Ben

Reputation: 8905

This looks like a job for svn:externals!

By setting the svn:externals property on a directory, you can pull in directories from anywhere else in SVN (even from different repositories) and they will show up in your working copy. You can then develop those subdirectories independently, and pull them in wherever you need them.

Example:

svn_root/
│ ProjectX/
│ │ branches/
│ │ tags/
│ │ trunk/
│ │ │ ProjectDir1/
│ │ │ ProjectDir2/
│ │ │ Subprojects/
│ │ │ project_file_1.txt
│ │ │ project_file_2.txt
│ ProjectY/
│ Subprojects/
│ │ SubprojectA/
│ │ │ branches/
│ │ │ tags/
│ │ │ trunk/
│ │ SubprojectB/
│ │ │ branches/
│ │ │ tags/
│ │ │ trunk/
│ │ SubprojectC/

Inside ProjectX and ProjectY, "Subprojects" is empty. Define a property on this directory named "svn:externals" to pull in the content from the top-level Subprojects directories:

^/Subprojects/SubprojectA/trunk@123 Ax
^/Subprojects/SubprojectB/trunk@456 Bx
^/Subprojects/SubprojectC/trunk@789 Cx

Note the "@123" portion. That sets a specific revision of SubprojectA to pull in. Without that specifier, you won't be able to see what version of SubprojectA was used to build ProjectX at a certain version. Also, using this specifier allows you to decide when to pull in updates from SubprojectA when you're working on ProjectX. You don't want to break ProjectX the day before release because somebody is working on SubprojectA for the sake of ProjectY!

Instead of specifying a particular revision of the subproject on trunk, you can also specify a branch or tag.

For more information, consult the SVN book: http://svnbook.red-bean.com/en/1.7/svn.advanced.externals.html

When developing a subproject, you can either work from the top-level Subprojects directory, or you can temporarily set svn:externals to pull in the latest trunk by removing the revision specifier, and work entirely from your ProjectX working copy. Just don't commit your externals property without a revision specifier!

Upvotes: 1

This kind of setup is not recommendable to do with Subversion IMHO. What you need in your case is a "branch-of-a-branch" structure, which I personally found to create many problems when merging to and from the main trunk. In your case I'd recommend having a look at e.g. git.

However, if the described setup is what you want/need to do, I'd do the following:

  1. Create Project X and Project Y as folders, each containing the subfolders trunk, branches, and subprojects.
  2. Whenever you need to work directly on a feature on a project, create a project branch as svn cp path/to/svn/project_x/trunk path/to/svn/project_x/branches/myfeature. Work on the myfeature branch until finished and reintegrate directly to trunk.
  3. Whenever you start working on a subproject, create a new empty folder subproject_ax, then create the subproject trunk as a copy of the main project trunk: svn cp path/to/svn/project_x/trunk path/to/svn/project_x/subproject_ax/trunk.
  4. When you need a branch for a subproject, create it from the subproject trunk as svn cp path/to/svn/project_x/subproject_ax/trunk path/to/svn/project_x/subproject_ax/branches/mysubfeature. Work on the mysubfeature branch until finished and then reintegrate to the subproject trunk.

To keep this whole charade up and running, you need to regularly update your project branches (in project_x/branches) as well as the subproject trunks (in project_x/subproject_ax/trunk) in sync with the main trunk by doing merges. The same is true for keeping the subproject branches in sync with the subproject trunk.

All in all I hope you will see the light and either a) use git for this or b) do not use this overly complicated structure and instead use a normal trunk/branches layout for your needs.

Upvotes: 0

Related Questions