//通过命令行清理svn的工作空间,删除未add的文件,revert修改的文件 public static bool RevertDelUnversioned(string svnPath) { try { var svnProcess = new Process(); svnProcess.StartInfo.FileName = "svn"; svnProcess.StartInfo.Arguments = "revert --recursive " + svnPath; svnProcess.Start(); svnProcess.WaitForExit(); var ecode1 = svnProcess.ExitCode; svnProcess.StartInfo.FileName = "svn"; svnProcess.StartInfo.Arguments = "cleanup --remove-unversioned " + svnPath; svnProcess.Start(); svnProcess.WaitForExit(); var ecode2 = svnProcess.ExitCode; svnProcess.StartInfo.FileName = "svn"; svnProcess.StartInfo.Arguments = "update " + svnPath; svnProcess.Start(); svnProcess.WaitForExit(); var ecode3 = svnProcess.ExitCode; return ecode1 == 0 && ecode2 == 0 && ecode3 == 0; } catch { return false; } }
sharpsvn的方式(未尝试)
/// <summary> /// 删除未被关联的SVN文件 /// </summary> /// <param name="workingCopyPath">工作路径</param> public static void RemoveUnversionedSvnFiles(string workingCopyPath) { using (SvnClient client = new SvnClient()) { client.Authentication.UserNamePasswordHandlers += ((sender, e) => { e.UserName = "abc"; e.Password = "123"; }); client.Status(workingCopyPath, (o, e) => { if (e.LocalContentStatus == SvnStatus.NotVersioned) { try { File.Delete(e.FullPath); } catch { } } }); } }