Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "svn revert" and extension of "svn cleanup" to be able to remove unversioned and untracked files. #183

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions svn/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,40 @@ def update(self, rel_filepaths=[], revision=None):
cmd,
wd=self.path)

def cleanup(self):
self.run_command(
'cleanup',
[],
wd=self.path)
def cleanup(self, remove_unversioned=False, remove_ignored=False):
if(remove_unversioned):
for file in self.status():
if(file.type == svn.constants.ST_UNVERSIONED):
# remove folders/files manually because parameter --remove-unversioned is not available in svn before version 1.9
self.__remove_recursively(os.path.abspath(file.name))

if(remove_ignored):
for file in self.status():
if(file.type == svn.constants.ST_IGNORED):
# remove folders/files manually because parameter --remove-ignored is not available in svn before version 1.9
self.__remove_recursively(os.path.abspath(file.name))

if((remove_unversioned and remove_ignored) == False):
# remove write locks and so on only if remove_unversioned and remove_ignored are not set to achieve the same behaviour as the svn clients in version 1.9 and above
self.run_command(
'cleanup',
[],
wd=self.path)

def __remove_recursively(self, path):
# Remove files from directory
if not os.path.isdir(path):
os.remove(path)
return # recursion anchor
# Remove files and folders from subdirectory
files=os.listdir(path)
for x in files:
fullpath=os.path.join(path, x)
if os.path.isfile(fullpath):
os.remove(fullpath) # remove files from subdirectory
elif os.path.isdir(fullpath):
self.__remove_recursively(fullpath) # remove folders from subdirectory recursively
os.rmdir(path) # remove directory as soon as it is empty

def status(self, rel_path=None):
path = self.path
Expand All @@ -71,7 +100,7 @@ def status(self, rel_path=None):

raw = self.run_command(
'status',
['--xml', path],
['--no-ignore', '--xml', path],
do_combine=True)

root = xml.etree.ElementTree.fromstring(raw)
Expand Down Expand Up @@ -116,3 +145,20 @@ def remove(self, rel_path, do_keep_local=False, do_force=False):
self.run_command(
'rm',
args)

def revert(self, rel_filepaths=["."], depth="empty"):
cmd = []
if(depth in (
"empty", # only the target itself
"files", # the target and any immediate file children thereof
"immediates", # the target and any immediate children thereof
"infinity" # the target and all of its descendants — full recursion
)):
cmd += ["--depth", depth]

cmd += rel_filepaths
self.run_command(
'revert',
cmd,
wd=self.path
)
1 change: 1 addition & 0 deletions svn/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Functions currently implemented:
- update
- cleanup
- remove (i.e. rm, del, delete)
- revert

In addition, there is also an "admin" class (`svn.admin.Admin`) that provides a
`create` method with which to create repositories.
Expand Down