Main Content

Set Up SVN Source Control

Set Up SVN Provided with Projects

Projects provide SVN for use with Subversion® (SVN) sandboxes and repositories at version 1.9. You do not need to install SVN to use this integration because it includes an implementation of SVN.

Note

This integration ignores any existing SVN installation.

The project SVN supports secure logins.

To use the version of SVN provided with the project, do one of the following:

  • On the MATLAB® Home tab, select New > Project > From SVN.

  • Alternatively, in the start page, select Project from SVN to retrieve from source control, or when you add a project to source control, select SVN in the Source control tool list

For instructions, see

Caution

Place your project sandbox folder on a local hard disc. Using a network folder with SVN is slow and unreliable. If you use a Windows® network drive, SVN move operations can result in incorrect "not existing" status for files visible in file browsers.

When you create a new sandbox using the project SVN, the new sandbox uses the latest version of SVN provided by the project.

When your project is under source control, you can use these project features:

You can check out from a branch, but the project SVN does not support branch merging. Use an external tool such as TortoiseSVN to perform branch merging. You can use the project tools for comparing and merging by configuring TortoiseSVN to generate a comparison report when you perform a diff on model files. See Port or Restore Model Changes in Comparison Report.

Subversion is not supported in MATLAB Online™.

Register Model Files with Subversion

You must register model files if you use SVN, including the SVN integration provided by projects.

If you do not register your model file extension as binary, SVN might add annotations to conflicted Simulink® files and attempt automerge. This corrupts model files so you cannot load the models in Simulink.

To avoid this problem when using SVN, register file extensions.

  1. Locate your SVN config file. Look for the file in these locations:

    • C:\Users\myusername\AppData\Roaming\Subversion\config or C:\Documents and Settings\myusername\Application Data\Subversion\config on Windows

    • In ~/.subversion on Linux® or Mac OS X

  2. If you do not find a config file, create a new one. See Create SVN Config File.

  3. If you find an existing config file, you have previously installed SVN. Edit the config file. See Update Existing SVN Config File.

Create SVN Config File

  1. If you do not find an SVN config file, create a text file containing these lines:

    [miscellany]
    enable-auto-props = yes
    [auto-props]
    *.mlx = svn:mime-type=application/octet-stream
    *.mat = svn:mime-type=application/octet-stream
    *.fig = svn:mime-type=application/octet-stream
    *.mdl = svn:mime-type=application/octet-stream
    *.slx = svn:mime-type= application/octet-stream
    *.mlapp = svn:mime-type= application/octet-stream
    *.p = svn:mime-type=application/octet-stream
    *.mdlp = svn:mime-type=application/octet-stream
    *.slxp = svn:mime-type=application/octet-stream
    *.sldd = svn:mime-type=application/octet-stream
    *.slxc = svn:mime-type=application/octet-stream
    *.mlproj = svn:mime-type=application/octet-stream
    *.mldatx = svn:mime-type=application/octet-stream
    *.slreqx = svn:mime-type=application/octet-stream
    *.sfx = svn:mime-type=application/octet-stream
    *.sltx = svn:mime-type=application/octet-stream
  2. Check for other file types you use in your projects that you also need to register as binary to avoid corruption at check-in. Check for files such as MEX-files (.mexa64, .mexmaci64, .mexw64), .xlsx, .jpg, .pdf, .docx, etc. Add a line to the attributes file for each file type you need. Examples:

    *.mexa64 = svn:mime-type=application/octet-stream
    *.mexw64 = svn:mime-type=application/octet-stream
    *.mexmaci64 = svn:mime-type=application/octet-stream
    *.xlsx = svn:mime-type=application/octet-stream
    *.docx = svn:mime-type=application/octet-stream
    *.pdf = svn:mime-type=application/octet-stream
    *.jpg = svn:mime-type=application/octet-stream
    *.png = svn:mime-type=application/octet-stream
  3. Name the file config and save it in the appropriate location:

    • C:\Users\myusername\AppData\Roaming\Subversion\config or C:\Documents and Settings\myusername\Application Data\Subversion\config on Windows

    • ~/.subversion on Linux or Mac OS X

After you create the SVN config file, SVN treats new model files as binary.

If you already have models in repositories, see Register Models Already in Repositories.

Update Existing SVN Config File

If you find an existing config file, you have previously installed SVN. Edit the config file to register files as binary.

  1. Edit the config file in a text editor.

  2. Locate the [miscellany] section, and verify the following line enables auto-props with yes:

    enable-auto-props = yes 
    Ensure that this line is not commented (that is, that it does not start with a #). Config files can contain example lines that are commented out. If there is a # character at the beginning of the line, delete it.

  3. Locate the [auto-props] section. Ensure that [auto-props] is not commented. If there is a # character at the beginning, delete it.

  4. Add the following lines at the end of the [auto-props] section:

    *.mlx = svn:mime-type=application/octet-stream
    *.mat = svn:mime-type=application/octet-stream
    *.fig = svn:mime-type=application/octet-stream
    *.mdl = svn:mime-type=application/octet-stream
    *.slx = svn:mime-type= application/octet-stream
    *.mlapp = svn:mime-type= application/octet-stream
    *.p = svn:mime-type=application/octet-stream
    *.mdlp = svn:mime-type=application/octet-stream
    *.slxp = svn:mime-type=application/octet-stream
    *.sldd = svn:mime-type=application/octet-stream
    *.slxc = svn:mime-type=application/octet-stream
    *.mlproj = svn:mime-type=application/octet-stream
    *.mldatx = svn:mime-type=application/octet-stream
    *.slreqx = svn:mime-type=application/octet-stream
    *.sfx = svn:mime-type=application/octet-stream
    *.sltx = svn:mime-type=application/octet-stream
    These lines prevent SVN from adding annotations to MATLAB and Simulink files on conflict and from automerging.

  5. Check for other file types you use in your projects that you also need to register as binary to avoid corruption at check-in. Check for files such as MEX-files (.mexa64, .mexmaci64, .mexw64), .xlsx, .jpg, .pdf, .docx, etc. Add a line to the config file for each file type you need.

    Examples:

    *.mexa64 = svn:mime-type=application/octet-stream
    *.mexw64 = svn:mime-type=application/octet-stream
    *.mexmaci64 = svn:mime-type=application/octet-stream
    *.xlsx = svn:mime-type=application/octet-stream
    *.docx = svn:mime-type=application/octet-stream
    *.pdf = svn:mime-type=application/octet-stream
    *.jpg = svn:mime-type=application/octet-stream
    *.png = svn:mime-type=application/octet-stream
  6. Save the config file.

After you create or update the SVN config file, SVN treats new model files as binary.

If you already have models in repositories, register them as described next.

Register Models Already in Repositories

Caution

Changing your SVN config file does not affect model files already committed to an SVN repository. If a model is not registered as binary, use svn propset to manually register models as binary.

To manually register a file in a repository as binary, use the following command with command-line SVN:

svn propset svn:mime-type application/octet-stream modelfilename

Enforce SVN Locking Model Files Before Editing

To ensure users remember to get a lock on model files before editing, you can configure SVN to make specified file extensions read only. To locate your SVN config file, see Register Model Files with Subversion.

After this setup, SVN sets model files to read only when you open the project, so you need to select Source Control > Get File Lock before you can edit them. Doing so helps prevent editing of models without getting the file lock. When the file has a lock, other users know the file is being edited, and you can avoid merge issues.

  1. To make SLX files read only, add a property to your SVN config file. Find this line in the [auto-props] section that registers SLX files as binary:

    *.slx = svn:mime-type= application/octet-stream
    

  2. Add the needs-lock property to the end of the existing slx line, separated by a semicolon, so the line looks like this:

    *.slx = svn:mime-type=application/octet-stream;svn:needs-lock=yes 
    You can combine properties in any order, but multiple entries (e.g., for slx) must be on a single line separated by semicolons.

  3. Recreate the sandbox for the config to take effect.

  4. You need to select Get File Lock before you can edit model files. See Get SVN File Locks.

If you need to resolve merge issues, see Resolve Conflicts.

Share a Subversion Repository

When you want to share a repository, you need to set up a server. You can use svnserve or the Apache™ SVN module. See the Web page references:

Standard Repository Structure

Create your repository with the standard tags, trunk, and branches folders, and check out files from trunk. The Subversion project recommends this structure. See the Web page:

Note

In a production environment, do not rely on remote repositories via the file system using the file:/// protocol. The file protocol is not safe. Concurrent access might corrupt repositories.

After you create a repository with this structure, to add tags to all your project files, on the Project tab, in the Source Control section, click Tag. See Tag and Retrieve Versions of Project Files.

Manage SVN Externals

To get files into your project from another repository or from a different part of the same repository, use SVN externals.

  1. In a project, right-click a project folder and select Source Control > Manage Externals.

  2. In the Manage Externals dialog box, click Add entry. You can browse to and validate a repository location, specify the relative reference format, specify the subfolder, choose the revision, e.g., the HEAD node, etc.

  3. After specifying the externals, click OK. The project displays the externals definition in the Manage Externals dialog box.

    Alternatively, enter or paste an svn:external definition in the Manage Externals dialog box. The project applies an SVN version 1.6 compliant externals definition.

  4. Click Set to validate and apply your changes.

  5. To retrieve the external files, click Update to update the sandbox.

If two users modify the svn:external for a folder, you can get a conflict. To resolve the conflict, in the All Files View, locate the .prej file and examine the conflict details. Open the Manage Externals dialog box and specify the desired svn:external, mark the folder conflict resolved, and then commit the changes.

Related Examples

More About