libgit2 / libgit2/pygit2

Repository.resolve_refish does not return a commit if given annotated tag SHA

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

还没有人认领这个 Issue。

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

描述

The repository.resolve_refish function is meant to return a commit object as the first element of the tuple ( source ).

However, if given a SHA of an annotated tag, it returns a tag object instead, which causes problems downstream.

The SHA of the target commit is available under result.target (see below)

How to reproduce:

Execute the following (clone the pygit2 repo into a temporary dir, create an annotated tag):

import pygit2
from pathlib import Path
import tempfile

repo_dir = tempfile.TemporaryDirectory()
repo_path = Path(repo_dir.name)

repo = pygit2.clone_repository("https://github.com/libgit2/pygit2.git", repo_path)
head_sha = repo.head.peel().id

old = repo.create_tag(
    'test_annotated_tag',
    head_sha,
    pygit2.GIT_OBJ_COMMIT,
    pygit2.Signature('John Doe', 'jdoe@example.com', 12347, 0),
    'message'
)

commit, ref = repo.resolve_refish(str(old))

Then we can investigate the results:

In [2]: commit  # not really a commit!
Out[2]: <pygit2.Object{tag:66986bf4eb1e47c3049f5a146609f0aa7b64757d}>

In [3]: commit.target
Out[3]: e2c0fdbfbd7f84374f8c7a3df256547b7ea99192

In [4]: head_sha
Out[4]: e2c0fdbfbd7f84374f8c7a3df256547b7ea99192

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 pygit2/repository.py 中 issue 所引用的 resolve_refish 实现开始。使用提供的脚本复现 annotated tag SHA 的情况,然后跟踪返回的对象及其 target。对于此情况,第一个 tuple 元素是 commit 对象,并且其他 refish 输入的现有行为保持不变,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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