SVN: Using another SVN repository in your project

If you're building more than one website, it's often useful to share code between the two (such as user profile information or common utility code).

An example is:

  • ProjectA
    • submoduleA
    • submoduleB
    • submoduleC
    • profiles
 
  • Project B
    • submoduleD
    • submoduleE
    • profiles

You can see that the "profiles" submodule is shared. It'd be handy to have any changes made in ProjectA to be consistent with ProjectB.

That's when you can use SVN externals.

Setup

This may look long, but it's only a couple of clicks.

  • Create a new repository for "profiles".
  • Checkout the new "profiles" repository in a new folder (outside of your project).
  • Copy the files needed for "profiles" from ProjectA into the new folder.
  • Commit code you need from ProjectA into the new "profiles" repository.
  • Make a backup of the "profiles" submodule from ProjectA (optional of course)
  • Move or delete the "profiles" code from ProjectA.
  • Using TortoiseSVN, right click on ProjectA and go to "TortoiseSVN" > "Properties".

image

  • Click "New..." and select "svn:externals" for the property name.
  • In the property value box, the syntax is "foldername repository". For this instance, we use "profiles svn://your.svnserver.com/profiles"
  • Each new line entry will be a new submodule.

image

  • For ProjectB, make a backup and move "profiles".
  • Repeat steps to set up the "svn:externals" property.
  • Update your project to get the code for profiles.
  • You now have synchronised code!
  • Do some diff checks in your code to see if there's anything in ProjectB profiles you are missing.

You can use the command line to do this also, but the syntax isn't very intuitive so it's much easier to use TortoiseSVN. If you want to use the CLI method, search for "svn propset svn:externals".

Things to Note!

When you do an update on your project, it'll automatically update the submodules to the latest version also.

In instances where you DON'T want this to happen, you should also specify a revision number in the external entry.

This can prevent lots of heartache when you do an update on the live server and pull in some unexpected changes which may break your project!

profiles -r 21 svn://your.svnserver.com/profiles

This will cap profiles to revision 21.

Gt9Tf

You have been warned!

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog