libgit2 / libgit2/pygit2

Git submodule fials if branch not present

未关闭
#1,361 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
1.7k
派生
408
平均合并
2 天 57 分钟
30 天内合并 PR
7

描述

In case if I want to check if branch was provided to submodule and it is not provided I got error

  if sm.branch:
      name = f"{sm.branch}/{sm.name}"
  else:
      name = f"{sm.name}"

File "/app/venv/lib/python3.11/site-packages/pygit2/submodules.py", line 148, in branch return ffi.string(branch).decode('utf-8') ^^^^^^^^^^^^^^^^^^ RuntimeError: cannot use string() on <cdata 'char *' NULL>

It looks like there is missing check if branch is actually set

class Submodule:
...

@property
def branch(self):
    """Branch that is to be tracked by the submodule."""
    branch = C.git_submodule_branch(self._subm)
    return ffi.string(branch).decode('utf-8')

I think it should be like this

@property
def branch(self):
    """Branch that is to be tracked by the submodule."""
    branch = C.git_submodule_branch(self._subm)
    if branch:
        return ffi.string(branch).decode('utf-8')

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 pygit2/submodules.py 中的 Submodule.branch 属性开始,检查 C.git_submodule_branch 如何返回未设置的分支。验证没有配置分支的子模块的行为,并确认访问该属性不再引发报告中的 NULL cdata RuntimeError。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, python
领域
devtools
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。