分支v1.5.x的Git包安装时浅克隆导致非默认分支 checkout 失败
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
Start in cmds/cmd_package/cmd_package_update.py:220-225 and read install_git_package, then reproduce installation with a branch name and an older commit SHA. The work is done when Git packages using branches, tags, or non-HEAD SHAs clone and checkout successfully, while the existing HEAD case continues to work.
Written by the indexing model from the issue text.
Description
问题描述
在分支v1.5.x的代码下,在安装 Git 类型包时,install_git_package 函数使用 --depth=1 浅克隆,但未指定分支。这导致非默认分支的包无法正确 checkout。
问题代码位置
cmds/cmd_package/cmd_package_update.py:220-225
clone_cmd = 'git clone ' + package_url + ' ' + repo_name_with_version + ' --depth=1'
execute_command(clone_cmd, cwd=bsp_package_path)
git_check_cmd = 'git checkout -q ' + ver_sha
execute_command(git_check_cmd, cwd=repo_path)
问题分析
场景1:VER_SHA 为分支名
当 package.json 配置如下:
{
"version": "galactic-legacy",
"VER_SHA": "galactic-legacy"
}
- --depth=1 只克隆默认分支
- git checkout galactic-legacy 失败,因为该分支不在浅克隆中
实验验证:
$ git clone https://github.com/wuhanstudio/micro_ros.git test --depth=1
$ git checkout galactic-legacy
error: pathspec 'galactic-legacy' did not match any file(s) known to git
场景2:VER_SHA 为 commit SHA
当仓库 HEAD 更新后,指定的旧 SHA 不在浅克隆中,checkout 同样失败。
影响范围
所有使用分支名或非 HEAD SHA 作为 VER_SHA 的包都会安装失败。
受影响的典型包:micro_ros 的多个版本配置(galactic-legacy, humble-gcc-10 等)。
建议修复方案
根据 VER_SHA 类型选择正确的克隆方式:
import re
def is_commit_sha(ver_sha):
"""检测 VER_SHA 是否为 commit SHA(40位十六进制)"""
return ver_sha and re.match(r'^[0-9a-f]{40}$', ver_sha)
def install_git_package(...):
if ver_sha and not is_commit_sha(ver_sha):
# 分支名/标签名:使用 --branch 参数
clone_cmd = 'git clone ... --depth=1 --branch ' + ver_sha
else:
# SHA:fetch 后 checkout
clone_cmd = 'git clone ... --depth=1'
execute_command('git fetch origin ' + ver_sha, cwd=repo_path)
execute_command('git checkout -q ' + ver_sha, cwd=repo_path)
- Dominant language
- Python
- Stars
- 79
- Forks
- 64
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RT-Thread/env
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
【建议】能否将env的包全部离线化Open
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
改进 env 的文档Open
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
juandresrodca/AdminForge#66 ·
Maintainers usually reply within 1 day
-
backend/local comp/tools P2 tool/terminal type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NousResearch/hermes-agent#158788 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
public-apis/public-apis#9330 · 1 reaction ·
Maintainers usually reply within 12 days
-
approved author-page correction move-papers
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
acl-org/acl-anthology#11043 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day