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
MODIFY
builder/app.py
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'))

MODIFY
builder/detectors.py
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'))

MODIFY
builder/utils.py
builder/utils.py
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, ''):

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