解决后台git拉取bug
This commit is contained in:
+11
-1
@@ -50,7 +50,7 @@ def _venv_pip():
|
|||||||
return [sys.executable, '-m', 'pip']
|
return [sys.executable, '-m', 'pip']
|
||||||
|
|
||||||
|
|
||||||
def _run_step(log_lines, cmd, timeout=STEP_TIMEOUT):
|
def _run_step(log_lines, cmd, timeout=STEP_TIMEOUT, env=None):
|
||||||
"""执行一条命令,将输出追加到 log_lines,返回是否成功。"""
|
"""执行一条命令,将输出追加到 log_lines,返回是否成功。"""
|
||||||
if isinstance(cmd, str):
|
if isinstance(cmd, str):
|
||||||
display = cmd
|
display = cmd
|
||||||
@@ -59,11 +59,21 @@ def _run_step(log_lines, cmd, timeout=STEP_TIMEOUT):
|
|||||||
display = ' '.join(str(c) for c in cmd)
|
display = ' '.join(str(c) for c in cmd)
|
||||||
args = [str(c) for c in cmd]
|
args = [str(c) for c in cmd]
|
||||||
|
|
||||||
|
# 为 git 命令自动加上 safe.directory 配置,避免 "dubious ownership" 报错
|
||||||
|
# (Django 通常以 www-data 运行,但项目目录所有者可能是 root)
|
||||||
|
if args and args[0] == 'git':
|
||||||
|
args = ['git', '-c', f'safe.directory={BASE_DIR}'] + args[1:]
|
||||||
|
display = ' '.join(args)
|
||||||
|
|
||||||
log_lines.append(f'\n$ {display}')
|
log_lines.append(f'\n$ {display}')
|
||||||
try:
|
try:
|
||||||
|
run_env = None
|
||||||
|
if env:
|
||||||
|
run_env = {**os.environ, **env}
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
args, cwd=str(BASE_DIR),
|
args, cwd=str(BASE_DIR),
|
||||||
capture_output=True, text=True, timeout=timeout,
|
capture_output=True, text=True, timeout=timeout,
|
||||||
|
env=run_env,
|
||||||
)
|
)
|
||||||
if result.stdout:
|
if result.stdout:
|
||||||
log_lines.append(result.stdout.rstrip())
|
log_lines.append(result.stdout.rstrip())
|
||||||
|
|||||||
Reference in New Issue
Block a user