Search code examples
c#svnsharpsvn

How do you recursively revert changes in a working copy using SharpSVN?


I have a project that will automatically merge and commit from a list of user-selected revisions from one branch to another. If a merge conflict occurs, the process is aborted and the working copy is reverted.

However, when I go to try again and select a revision that would normally not cause a conflict on a pristine working copy, I get the following error:

Merge failed: SharpSvn.SvnWorkingCopyException: Can't merge into conflicted node 'C:\SVN\MyProject\MyBranch\ProjectDirectory\SubDirectory\conflicted-file.cs'

Even if I do a revert on the working copy, it only appears to revert the svn:mergeinfo property, but not the files within (conflicted or not, the old files are still there). Is it not reverting recursively? I'm not seeing an option to do so otherwise.

Here's what I've tried so far:

using (var client = new SvnClient())
{
    // [Authentication code goes here...]
    var targetPath = $@"{_svnLocalRoot}\{project}\{branch}\";

    // Clean Up
    var cleanupArgs = new SvnCleanUpArgs()
    {
        BreakLocks = true,
        ClearDavCache = true,
        VacuumPristines = true,
        FixTimestamps = true
    };
    client.CleanUp(targetPath, cleanupArgs);

    // Revert
    var revertArgs = new SvnRevertArgs()
    {
        Depth = SvnDepth.Infinity,
        ClearChangelists = true
    };
    client.Revert(targetPath);

    // Update
    var updateArgs = new SvnUpdateArgs()
    {
        Depth = SvnDepth.Infinity
    };
    client.Update(targetPath, updateArgs);

    // [Merge and commit code goes here...]
}

Short of deleting the entire working directory and doing a check-out (which takes a very long time), what do I need to do to get my working copy to a pristine state with no conflicts and the latest code?

I'm currently using SharpSvn.1.9-x64 version 1.9005.3940.224


Solution

  • It was as simple as a typo.

    client.Revert(targetPath);
    

    should have been:

    client.Revert(targetPath, revertArgs);