fix: already-exists pull使用_resolve_workdir实际目录

This commit is contained in:
yumoqing 2026-08-06 14:55:11 +08:00
parent 11cab45129
commit a84e96491d

View File

@ -906,17 +906,20 @@ if action == 'send_message':
result = await shell_exec(cmd, workdir=workdir, timeout=120 if 'git clone' in cmd else 60)
# git clone already exists → git pull
if result['rc'] != 0 and 'already exists' in result.get('stderr', '') and repo_target and cmd.startswith('git clone'):
pull_dir = os.path.join(workdir, repo_target) if not os.path.isabs(repo_target) else repo_target
# 用 shell_exec 解析后的实际 workdir
from pipeline_service.init import _resolve_workdir
real_workdir = _resolve_workdir()
pull_dir = os.path.join(real_workdir, repo_target)
debug(f'devops: clone already exists, pulling {pull_dir}')
result = await shell_exec(f'git -C {pull_dir} pull', workdir=workdir, timeout=60)
result = await shell_exec(f'git -C {pull_dir} pull', workdir=real_workdir, timeout=60)
if result['rc'] == 0:
out = result['stdout'].strip()
agent_reply = f"执行成功。{'输出:' + out[:500] if out else '(无输出)'}"
else:
agent_reply = f"执行失败rc={result['rc']}{result['stderr'][:500] or result['stdout'][:500]}"
# 多步任务:如果 git clone 成功且消息中含有"技能""skill""安装",自动触发 skill_import
# 多步任务:如果 git clone/pull 成功且消息中含有"技能""skill""安装",自动扫描
if result['rc'] == 0 and repo_target and re.search(r'(技能|skill|安装技能|导入技能)', message_text):
clone_dir = os.path.join(workdir, repo_target) if not os.path.isabs(repo_target) else repo_target
clone_dir = os.path.join(_resolve_workdir(), repo_target)
if os.path.isdir(clone_dir):
try:
import_result = await skill_import_git('', skills_dir='skills')