Svn2: deleting not-versioned files in SVN (at your own risk)

Back | subversion | 11/2/2010 |

Svn2

I often need to delete not-versioned files in SVN. Although I am supposed to create projects that place all output outside of the SVN client structure, it’s not always practical. So all those pesky generated files are hard to get rid of and pollute my svn status. I frequently dump the output of svn status | findstr “^?” into a .cmd file and edit it replacing all ? with del /Q.

We can do better. I added a new tool, svn2 to the Svn2Svn project. Svn2 has a sync command that sends all non-versioned files to the recycle bin. Use at your own risk – this will delete files that haven’t been svn-added.

Download

Implementation

Svn2 uses SharpSVN which can run a status command. For each file that is not-versioned, we call a Microsoft.VisualBasic.FileIO function to recycle it.

  1. SvnStatusArgs statusArgs = new SvnStatusArgs();
  2. statusArgs.Depth = SvnDepth.Infinity;
  3. statusArgs.ThrowOnError = true;
  4. client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(
  5.     delegate(object sender, SvnStatusEventArgs e)
  6. {
  7.     switch (e.LocalContentStatus)
  8.     {
  9.         case SvnStatus.NotVersioned:
  10.             Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath);
  11.             if (File.Exists(e.FullPath))
  12.             {
  13.                 FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs,
  14.                     RecycleOption.SendToRecycleBin);
  15.             }
  16.             else if (Directory.Exists(e.FullPath))
  17.             {
  18.                 FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs,
  19.                     RecycleOption.SendToRecycleBin);
  20.             }
  21.             break;
  22.     }
  23. }));