libgit2 / libgit2/pygit2

Suggestion: better handling of `repo.set_head(pygit2.Commit)`

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

还没有人认领这个 Issue。

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

描述

I have tried to emulate git checkout --detach <commit> in pygit2, to create detached HEAD checkout, and I did come up with the following rough equivalent (though the following does not uses transactions as git does):

rev = repo.revparse_single(commit_name)
repo.checkout_tree(rev)
repo.set_head(rev.id)

However when I tried to use simply repo.set_head(rev), I got the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-35-9612528ec0ac> in <module>()
----> 1 repo.set_head(rev)

/usr/lib/python2.7/dist-packages/pygit2/repository.pyc in set_head(self, target)
    293
    294         # if it's a string, then it's a reference name
--> 295         err = C.git_repository_set_head(self._repo, to_bytes(target))
    296         check_error(err)
    297

TypeError: initializer for ctype 'char *' must be a cdata pointer, not _pygit2.Commit

It would be nice if pygit2.Commit object was automatically peeled, but if it is decided to be not good idea, then what it needs is more user-friendly error message than the one above.


pygit2 0.26.0

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 repository.py 的 traceback 中的 Repository.set_head 开始,并比较其中显示的 revparse_single、checkout_tree 和 C.git_repository_set_head 流程。检查现有测试或文档,确认接受的目标类型;当 Commit 输入行为已确定并得到覆盖(如果仍不受支持,还包括清晰的失败消息)时,即视为完成。

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

评估

技术栈
git, python
领域
tooling
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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