Move SVN working copy to new branch

This is for when you have accidentally made changes in trunk (Main Line) and you should have made a branch.

Using an SVN client with a version different to your usual one

Due to incompatabilities between working copies created with SVN <= 1.7.x (used in MX <= 7) and SVN > 1.7.x (used in MX > 7), you may need to use a different client. If you install a command line only client, you can more easily manage which version you are using without them fighting.

  • For Mendix 7, download and install SlikSVN from https://sliksvn.com/pub/Slik-Subversion-1.7.9-x64.msi.
  • For Mendix 8 and higher, install the latest version of SlikSVN from https://sliksvn.com/download/ (1.14.1 at the time of writing) and install it to the default directory.
  1. Open a PowerShell console
  2. Assign the path to the SVN executable you want to use to a variable:

    $svn = 'C:\Program Files\SlikSvn\bin\svn.exe'
    
  3. From now on, use & $svn in place of the svn command.

    If you want, you can assign your default svn command to a variable so that it will still work with the script below:

    $svn = svn
    

Moving the working copy to a new branch

  1. Make sure that your current location is your project directory and then run the following:

    # Get a name for the new branch
    $newBranchName = Read-Host "Name for new branch"
       
    # Get the URL of the repository into a variable
    $repoUrl = ( & $svn info | Select-String -Pattern "^URL:" ) -replace "^URL: ",""
       
    # Create a URL for the new branches repository
    $newRepoUrl = ( $repoUrl -replace "/branches/[^/]+$|/trunk$","" ) + "/branches/" + $newBranchName
       
    # Copy the working copy content from trunk to the new branch
    & $svn copy $repoUrl $newRepoUrl -m "Moved working copy to $newBranchName"
       
    # Switch the working copy to be the new branch
    & $svn switch $newRepoUrl
       
    # Rename your local folder so you don't get confused
    $wd = ( Get-Location ).Path
    cd ..
    Rename-Item $wd $newBranchName
    cd $newBranchName
    

All done! Your working copy is now in a new branch and trunk is unchanged.