From 70d7c681344f7f90ebf93dfc41ce9cbd33694243 Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Mon, 22 May 2017 15:11:48 -0700 Subject: [PATCH] Use cwd switching to do git operations Setting just --git-dir is not enough, you also need to set --work-dir. Just setting cwd is better --- builder/app.py | 2 +- builder/detectors.py | 4 ++-- builder/utils.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/app.py b/builder/app.py index e478d879..82868911 100644 --- a/builder/app.py +++ b/builder/app.py @@ -83,7 +83,7 @@ class Builder(Application): sys.exit(1) try: - for line in execute_cmd(['git', '--git-dir', os.path.join(output_path, '.git'), 'reset', '--hard', ref]): + for line in execute_cmd(['git', 'reset', '--hard', ref], output_path): self.log.info(line, extra=dict(phase='fetching')) except subprocess.CalledProcessError: self.log.error('Failed to check out ref %s', ref, extra=dict(phase='failed')) diff --git a/builder/detectors.py b/builder/detectors.py index 710d536c..199fbb15 100644 --- a/builder/detectors.py +++ b/builder/detectors.py @@ -65,12 +65,12 @@ class S2IBuildPack(BuildPack): 'build', '--exclude', '""', '--ref', ref, - workdir, + '.', build_image, output_image_spec, ] try: - for line in execute_cmd(cmd): + for line in execute_cmd(cmd, cwd=workdir): self.log.info(line, extra=dict(phase='building', builder=self.name)) except subprocess.CalledProcessError: self.log.error('Failed to build image!', extra=dict(phase='failed')) diff --git a/builder/utils.py b/builder/utils.py index d1486b3d..823e5545 100644 --- a/builder/utils.py +++ b/builder/utils.py @@ -1,10 +1,10 @@ import subprocess -def execute_cmd(cmd): +def execute_cmd(cmd, cwd=None): """ Call given command, yielding output line by line """ - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, cwd=cwd) try: for line in iter(proc.stdout.readline, ''):