Use client.status()
and check the text_status
attribute of the returned status object. Example:
>>> import pysvn >>> c = pysvn.Client() >>> out = c.status("versioned.cpp")[0]
This indicates that the file is versioned and unmodified.
>>> c.status("added.cpp")[0].text_status # added file <wc_status_kind.added> >>> c.status("unversioned.cpp")[0].text_status # unversioned file <wc_status_kind.unversioned>
You can explore other possible statuses using dir (pysvn.wc_status_kind)
So you can wrap this with something like:
def under_version_control(filename): "returns true if file is unversioned" c = pysvn.Client() s = c.status(filename)[0].text_status return s not in ( pysvn.wc_status_kind.added, pysvn.wc_status_kind.unversioned, pysvn.wc_status_kind.ignored)
If you also want to access files outside of the svn working directory, you need to catch and handle ClientError
. For instance.
def under_version_control(filename): "returns true if file is unversioned" c = pysvn.Client() try: s = c.status(filename)[0].text_status catch pysvn.ClientError: return False else: return s not in ( pysvn.wc_status_kind.added, pysvn.wc_status_kind.unversioned, pysvn.wc_status_kind.ignored)
source share