Skip to content

Instantly share code, notes, and snippets.

@cpelley
Created October 22, 2015 08:27
Show Gist options
  • Save cpelley/97c80b0d8827174dab89 to your computer and use it in GitHub Desktop.
Save cpelley/97c80b0d8827174dab89 to your computer and use it in GitHub Desktop.
svn wrapper
#!/usr/bin/env python2.7
import subprocess
import sys
DEBUG = False
SVN_EXEC = '/usr/bin/svn'
class SVNError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg
def exceptionHandler(exception_type, exception, traceback,
debug_hook=sys.excepthook):
# Control the format of the exception, not displaying a traceback or the
# exception module origin.
if DEBUG:
debug_hook(exception_type, exception, traceback)
else:
print "%s: %s" % (exception_type.__name__, exception)
sys.excepthook = exceptionHandler
def main():
arguments = []
if len(sys.argv) > 1:
arguments = sys.argv[1:]
output = None
if len(arguments) > 0 and arguments[0].startswith('switch'):
output = subprocess.check_output([SVN_EXEC, "status", "--quiet"])
if output:
override = '--ignore-local-changes'
if override in arguments:
arguments.remove(override)
subprocess.call([SVN_EXEC] + arguments)
else:
msg = ('Your local changes would carry over to the checkout:'
'\n{}\nPlease, commit your '
'changes or stash them before you switch between '
'checkouts\nsupply the {} argument to continue '
'anyway.\nAborting'.format(output, override))
raise SVNError(msg)
else:
subprocess.call([SVN_EXEC] + arguments)
else:
subprocess.call([SVN_EXEC] + arguments)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment