--- a/pipelines/core.py Thu Jul 28 14:21:11 2016 -0500
+++ b/pipelines/core.py Thu Jul 28 15:07:43 2016 -0500
@@ -118,7 +118,7 @@
path, config = _load_config(args.pipeline_filename)
- branch = vcs.get_branch(path)
env = _load_env(args.env_filenames)
@@ -127,6 +127,6 @@
k, v = _split_env_var(var)
- pipeline = Pipeline(config, path, branch, env)
+ pipeline = Pipeline(config, path, repo, env) --- a/pipelines/pipeline.py Thu Jul 28 14:21:11 2016 -0500
+++ b/pipelines/pipeline.py Thu Jul 28 15:07:43 2016 -0500
@@ -26,10 +26,10 @@
- def __init__(self, config, path, branch, env=None):
+ def __init__(self, config, path, repo, env=None): self.build_path = os.path.abspath(path)
@@ -39,7 +39,7 @@
branches = self.config["pipelines"]["branches"]
for pattern, steps in branches.iteritems():
- if fnmatch.fnmatch(self.branch, pattern):
+ if fnmatch.fnmatch(self.repo.branch, pattern): --- a/pipelines/vcs.py Thu Jul 28 14:21:11 2016 -0500
+++ b/pipelines/vcs.py Thu Jul 28 15:07:43 2016 -0500
@@ -22,14 +22,7 @@
- 'git': 'git rev-parse --abbrev-ref HEAD -C {}',
- 'hg': 'hg branch -R {}',
+def run_command(cmd, path): @@ -37,14 +30,56 @@
env['GIT_CONFIG_NOSYSTEM'] = '1'
- for _, cmd in _VCSS.iteritems():
- command = cmd.format(path)
- branch = subprocess.check_output(command.split(),
- stderr=open(os.devnull, 'w'),
- branch = branch.strip()
- except subprocess.CalledProcessError:
+ return subprocess.check_output(cmd.split(), + stderr=open(os.devnull, 'w'), + except subprocess.CalledProcessError: +class git_backend(object): + def __init__(self, path): + return run_command('git rev-parse --abbrev-ref HEAD', +class hg_backend(object): + def __init__(self, path):
+ return run_command('hg log -r . -T {branch}', + def __init__(self, search_path): + # search for .git or .hg to determine our backend class + 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) + elif os.path.exists(os.path.join(next_dir, '.hg')): + self._repo = hg_backend(next_dir) + next_dir = os.path.dirname(prev_dir) + raise IOError("Could not find .git nor .hg") + return self._repo.branch