Skip to content

Instantly share code, notes, and snippets.

@ph1ee
Created July 2, 2015 12:28
Show Gist options
  • Save ph1ee/64559a91bf3bf862719d to your computer and use it in GitHub Desktop.
Save ph1ee/64559a91bf3bf862719d to your computer and use it in GitHub Desktop.
Remove untrakced files from Subversion working copy
#!/usr/bin/python
import os
import re
import shutil
def removeall(path):
if os.path.islink(path):
os.unlink(path)
return
if os.path.exists(path):
if os.path.isfile(path):
os.remove(path)
return
for x in os.listdir(path):
fullpath=os.path.join(path, x)
if os.path.isfile(fullpath):
os.remove(fullpath)
elif os.path.isdir(fullpath):
removeall(fullpath)
if os.path.exists(path):
shutil.rmtree(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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment