Automatically remove Subversion unversioned files

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

    Might as well contribute another option

    svn status | awk '{if($2 !~ /(config|\.ini)/ && !system("test -e \"" $2 "\"")) {print $2; system("rm -Rf \"" $2 "\"");}}'
    

    The /(config|.ini)/ is for my own purposes.

    And might be a good idea to add --no-ignore to the svn command

    0 讨论(0)
  • 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();
        }
    }
    
    0 讨论(0)
  • 2020-11-28 19:16

    If you don't want to write any code, svn2.exe from svn2svn does this, also there's an article on how it's implemented. Deleted folders and files are put in the recycle bin.

    Run "svn2.exe sync [path]".

    0 讨论(0)
  • 2020-11-28 19:16

    Using TortoiseSVN: * right-click on working copy folder, while holding the shift-key down * choose "delete unversioned items"

    How can I delete all unversioned/ignored files/folders in my working copy?

    0 讨论(0)
  • 2020-11-28 19:18

    I added this to my windows powershell profile

    function svnclean {
        svn status | foreach { if($_.StartsWith("?")) { Remove-Item $_.substring(8) -Verbose } }
    }
    
    0 讨论(0)
  • 2020-11-28 19:18

    If you have TortoiseSVN on your path and you are in the right directory:

    TortoiseProc.exe /command:cleanup /path:"%CD%" /delunversioned /delignored /nodlg /noui
    

    The options are described in the TortoiseSVN help for /command:cleanup:

    Use /noui to prevent the result dialog from popping up either telling about the cleanup being finished or showing an error message). /noprogressui also disables the progress dialog. /nodlg disables showing the cleanup dialog where the user can choose what exactly should be done in the cleanup. The available actions can be specified with the options /cleanup for status cleanup, /revert, /delunversioned, /delignored, /refreshshell and /externals.

    0 讨论(0)
提交回复
热议问题