grim/local-pipelines

1eb9fe35d616
Parents 601bff56b3fb
Children 16aaa2b6454a
vcs: add new class that abstracts hg and git repos
--- a/pipelines/vcs.py Wed Jul 27 22:16:27 2016 -0700
+++ b/pipelines/vcs.py Thu Jul 28 00:57:57 2016 -0700
@@ -65,6 +65,32 @@
self._path)
+class repo(object):
+ def __init__(self, search_path):
+ self._repo = None
+
+ # search for .git or .hg to determine our backend class
+ prev_dir = None
+ next_dir = os.path.realpath(search_path)
+ while prev_dir != next_dir:
+ if os.path.exists(os.path.join(next_dir, '.git')):
+ self._repo = git_backend(next_dir)
+ break
+ elif os.path.exists(os.path.join(next_dir, '.hg')):
+ self._repo = hg_backend(next_dir)
+ break
+ prev_dir = next_dir
+ next_dir = os.path.dirname(prev_dir)
+
+ # sanity check
+ if self._repo is None:
+ raise IOError("Could not find .git nor .hg")
+
+ @property
+ def branch(self):
+ return self._repo.branch
+
+
def get_branch(path):
branch = None
env = os.environ.copy()