Search code examples
visual-studiosvntortoisesvnpatchvisualsvn

TortoiseSVN patch file is incorrectly applied


I'm trying to use SVN patch files to remove authentication from a web API while I'm developing. The patch file to remove authentication works fine and looks like this:

Index: WebApplication.Api/Global.asax.cs
===================================================================
--- WebApplication.Api/Global.asax.cs   (revision 18939)
+++ WebApplication.Api/Global.asax.cs   (working copy)
@@ -115,7 +115,7 @@
             _dependencyRegister.AddRegistration<WebApplication.Application.Aspects.AuthorisationAspect>();

             // WebApplication.Application.CurrentUser
-            _dependencyRegister.AddRegistration<WebApplication.Application.CurrentUser.ICurrentUserService, WebApplication.Application.CurrentUser.CurrentUserService>();
+            _dependencyRegister.AddRegistration<WebApplication.Application.CurrentUser.ICurrentUserService, WebApplication.Api.DummyServices.CurrentUserService>();

             // WebApplication.Application.Interface.Manager
             _dependencyRegister.AddRegistration<WebApplication.Application.Interface.Manager.IAspNetMembershipManager, WebApplication.Application.Manager.AspNetMembershipManager>();
Index: WebApplication.Api/Web.config
===================================================================
--- WebApplication.Api/Web.config   (revision 18939)
+++ WebApplication.Api/Web.config   (working copy)
@@ -64,14 +64,12 @@
     </sessionState>
       <httpModules>
           <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
-          <add name="ProtectedResourceModule" type="WebApplication.Api.Modules.ProtectionModule"/>
       </httpModules>
   </system.web>
   <system.webServer>
     <validation validateIntegratedModeConfiguration="false" />
       <modules runAllManagedModulesForAllRequests="true">
           <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
-          <add name="ProtectedResourceModule" type="WebApplication.Api.Modules.ProtectionModule"/>
       </modules>
       <httpErrors existingResponse="PassThrough" />
   </system.webServer>

As you can see, it changes the DI implementation of an interface and removes two nodes from an XML configuration file.

Since there is no way (that I have found) to reverse apply a patch (I'm using VisualSVN in Visual Studio to apply the patch), I have created a 'reverse patch' based on the original patch file:

Index: WebApplication.Api/Global.asax.cs
===================================================================
--- WebApplication.Api/Global.asax.cs   (revision 18939)
+++ WebApplication.Api/Global.asax.cs   (working copy)
@@ -115,7 +115,7 @@
             _dependencyRegister.AddRegistration<WebApplication.Application.Aspects.AuthorisationAspect>();

             // WebApplication.Application.CurrentUser
+            _dependencyRegister.AddRegistration<WebApplication.Application.CurrentUser.ICurrentUserService, WebApplication.Application.CurrentUser.CurrentUserService>();
-            _dependencyRegister.AddRegistration<WebApplication.Application.CurrentUser.ICurrentUserService, WebApplication.Api.DummyServices.CurrentUserService>();

             // WebApplication.Application.Interface.Manager
             _dependencyRegister.AddRegistration<WebApplication.Application.Interface.Manager.IAspNetMembershipManager, WebApplication.Application.Manager.AspNetMembershipManager>();
Index: WebApplication.Api/Web.config
===================================================================
--- WebApplication.Api/Web.config   (revision 18939)
+++ WebApplication.Api/Web.config   (working copy)
@@ -64,14 +64,12 @@
     </sessionState>
       <httpModules>
           <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
+          <add name="ProtectedResourceModule" type="WebApplication.Api.Modules.ProtectionModule"/>
       </httpModules>
   </system.web>
   <system.webServer>
     <validation validateIntegratedModeConfiguration="false" />
       <modules runAllManagedModulesForAllRequests="true">
           <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
+          <add name="ProtectedResourceModule" type="WebApplication.Api.Modules.ProtectionModule"/>
       </modules>
       <httpErrors existingResponse="PassThrough" />
   </system.webServer>

Rather simplistically, all I have done is change + symbols to - and vice versa. This creates a reverse patch file which makes sense to me.

The reverse patch works fine except that the final 'line add' in the XML config file, as well as adding the line, also removes several of the following lines, resulting in badly-formed XML.

Can anyone advise why this is? Do I need to do something with the magic @@ -64,14 +64,12 @@?


Solution

  • It seems the simplest way to do this is through the command line. I can't find any way to apply a patch file in reverse through the UI of either Visual SVN or Tortoise, and I've no idea why the manual modification to the patch file didn't work.

    In the command line, navigate to the working copy directory and enter the following command to apply a patch file:

    svn patch [path and name of patch file]
    

    To apply it in reverse:

    svn patch --reverse-diff [path and name of patch file]