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
pull/6/head
yuvipanda 2017-05-22 15:11:48 -07:00
rodzic 1d24fdb7c3
commit 70d7c68134
3 zmienionych plików z 5 dodań i 5 usunięć

Wyświetl plik

@ -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'))

Wyświetl plik

@ -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'))

Wyświetl plik

@ -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, ''):