Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions cmds/cmd_package/cmd_package_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import logging
import os
import platform
import re
import shutil
import time

Expand All @@ -42,6 +43,13 @@
find_bool_macro_in_config


def is_commit_sha(ver_sha):
"""检测 VER_SHA 是否为 commit SHA(40位十六进制)"""
if ver_sha and re.match(r'^[0-9a-f]{40}$', ver_sha):
return True
return False


def determine_support_chinese(env_root):
get_flag_file_path = os.path.join(env_root, 'tools', 'bin', 'env_above_ver_1_1')
if os.path.isfile(get_flag_file_path):
Expand Down Expand Up @@ -216,12 +224,26 @@ def install_git_package(bsp_package_path, package_name, package_info, package_ur
repo_path = repo_path + '-' + package_info['ver']
repo_name_with_version = '"' + repo_path + '"'

clone_cmd = 'git clone ' + package_url + ' ' + repo_name_with_version + ' --depth=1'
logging.info(clone_cmd)
execute_command(clone_cmd, cwd=bsp_package_path)
# 修复:根据 VER_SHA 类型选择正确的克隆方式
if ver_sha and not is_commit_sha(ver_sha):
# VER_SHA 是分支名/标签名,使用 --branch 参数
clone_cmd = 'git clone ' + package_url + ' ' + repo_name_with_version + ' --depth=1 --branch ' + ver_sha
logging.info(clone_cmd)
execute_command(clone_cmd, cwd=bsp_package_path)
# 分支名已在克隆时切换,无需额外 checkout
else:
# VER_SHA 是 SHA 或为空,使用原来的方式
clone_cmd = 'git clone ' + package_url + ' ' + repo_name_with_version + ' --depth=1'
logging.info(clone_cmd)
execute_command(clone_cmd, cwd=bsp_package_path)

# 如果是 SHA,需要 fetch 后 checkout
if ver_sha and is_commit_sha(ver_sha):
fetch_cmd = 'git fetch origin ' + ver_sha
execute_command(fetch_cmd, cwd=repo_path)
git_check_cmd = 'git checkout -q ' + ver_sha
execute_command(git_check_cmd, cwd=repo_path)

git_check_cmd = 'git checkout -q ' + ver_sha
execute_command(git_check_cmd, cwd=repo_path)
except Exception as e:
print('Error message:%s' % e)
print("\nFailed to download software package with git. Please check the network connection.")
Expand Down