Automatically remove Subversion unversioned files

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

    I stumbled on svn-clean on my RH5 machine. Its located at /usr/bin/svn-clean

    http://svn.apache.org/repos/asf/subversion/trunk/contrib/client-side/svn-clean

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

    Edit:

    Subversion 1.9.0 introduced an option to do this:

    svn cleanup --remove-unversioned
    

    Before that, I use this python script to do that:

    import os
    import re
    
    def removeall(path):
        if not os.path.isdir(path):
            os.remove(path)
            return
        files=os.listdir(path)
        for x in files:
            fullpath=os.path.join(path, x)
            if os.path.isfile(fullpath):
                os.remove(fullpath)
            elif os.path.isdir(fullpath):
                removeall(fullpath)
        os.rmdir(path)
    
    unversionedRex = re.compile('^ ?[\?ID] *[1-9 ]*[a-zA-Z]* +(.*)')
    for l in  os.popen('svn status --no-ignore -v').readlines():
        match = unversionedRex.match(l)
        if match: removeall(match.group(1))
    

    It seems to do the job pretty well.

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

    Since everyone else is doing it...

    svn status | grep ^? | awk '{print $2}' | sed 's/^/.\//g' | xargs rm -R
    
    0 讨论(0)
  • 2020-11-28 19:10

    If you are on windows command line,

    for /f "tokens=2*" %i in ('svn status ^| find "?"') do del %i
    

    Improved version:

    for /f "usebackq tokens=2*" %i in (`svn status ^| findstr /r "^\?"`) do svn delete --force "%i %j"
    

    If you use this in a batch file you need to double the %:

    for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn delete --force "%%i %%j"
    
    0 讨论(0)
  • 2020-11-28 19:11

    Just do it on unix-shell with:

    rm -rf `svn st . | grep "^?" | cut -f2-9 -d' '`
    
    0 讨论(0)
  • 2020-11-28 19:12

    Can you not just do an export to a new location and build from there?

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