Automatically remove Subversion unversioned files

前端 未结 30 3158
感情败类
感情败类 2020-11-28 18:54

Does anybody know a way to recursively remove all files in a working copy that are not under version control? (I need this to get more reliable results in my automatic build

30条回答
  •  囚心锁ツ
    2020-11-28 19:21

    C# code snipet above did not work for me - I have tortoise svn client, and lines are formatted slightly differently. Here is same code snipet as above, only rewritten to function and using regex.

            /// 
        /// Cleans up svn folder by removing non committed files and folders.
        /// 
        void CleanSvnFolder( string folder )
        {
            Directory.SetCurrentDirectory(folder);
    
            var psi = new ProcessStartInfo("svn.exe", "status --non-interactive");
            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;
            psi.WorkingDirectory = folder;
            psi.CreateNoWindow = true;
    
            using (var process = Process.Start(psi))
            {
                string line = process.StandardOutput.ReadLine();
                while (line != null)
                {
                    var m = Regex.Match(line, "\\? +(.*)");
    
                    if( m.Groups.Count >= 2 )
                    {
                        string relativePath = m.Groups[1].ToString();
    
                        string path = Path.Combine(folder, relativePath);
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }
                        else if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                    line = process.StandardOutput.ReadLine();
                }
            }
        } //CleanSvnFolder
    

提交回复
热议问题