diff options
Diffstat (limited to 'MgaRepo/vcsutil.py')
-rw-r--r-- | MgaRepo/vcsutil.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/MgaRepo/vcsutil.py b/MgaRepo/vcsutil.py new file mode 100644 index 0000000..cf0237c --- /dev/null +++ b/MgaRepo/vcsutil.py @@ -0,0 +1,27 @@ +from MgaRepo.git import GIT +from MgaRepo.svn import SVN + +def detectVCS(url): + if ':' in url: + protocol,uri = url.split(":") + if "svn" in protocol: + return SVN(url=url) + elif "git" in protocol: + return GIT(url=url) + elif "http" in protocol: + if uri.endswith(".git"): + return GIT(url=url) + elif "svn" in uri: + return SVN(url=url) + raise Error("Unknown protocol %s for %s" % (protocol, url)) + elif os.path.exists(url) and os.path.isdir(url): + while True: + url = os.path.abspath(url) + for vcs in (SVN, GIT): + vcsdir = os.path.join(url, vcs.vcs_dirname) + if os.path.exists(vcsdir) and os.path.isdir(vcsdir): + return vcs(path=url) + url = os.path.dirname(url) + if url == "/": + break + raise Error("No supported repository found at path: %s" % url) |