Automatically remove Subversion unversioned files

前端 未结 30 3120
感情败类
感情败类 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:15

    My C# conversion of Thomas Watnedals Python script:

    Console.WriteLine("SVN cleaning directory {0}", directory);
    
    Directory.SetCurrentDirectory(directory);
    
    var psi = new ProcessStartInfo("svn.exe", "status --non-interactive");
    psi.UseShellExecute = false;
    psi.RedirectStandardOutput = true;
    psi.WorkingDirectory = directory;
    
    using (var process = Process.Start(psi))
    {
        string line = process.StandardOutput.ReadLine();
        while (line != null)
        {
            if (line.Length > 7)
            {
                if (line[0] == '?')
                {
                    string relativePath = line.Substring(7);
                    Console.WriteLine(relativePath);
    
                    string path = Path.Combine(directory, relativePath);
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }
                    else if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            line = process.StandardOutput.ReadLine();
        }
    }
    

提交回复
热议问题