_pygit2.GitError: reference 'refs/heads/master' not found
未关闭
还没有人认领这个 Issue。
support
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 408
- 平均合并
- 2 天 57 分钟
- 30 天内合并 PR
- 7
描述
import pygit2
from github import Github
github_username = "user"
github_password = "password"
github_email = "email"
# login to github and
authenticated_github_user = Github(github_username, github_password)
user = authenticated_github_user.get_user()
is_org: bool = False
# create the new repository
if is_org:
org = authenticated_github_user.get_organization('someorg')
repo = org.create_repo('projectname', description='somedescription')
else:
repo = user.create_repo('testrepo_github_api', description='this is a test')
# clone the repository
repoClone = pygit2.clone_repository(repo.git_url, '/tmp/test_clone')
#create some new files in the repo
repo.create_file("README.md", "init commit", 'readmeText')
# Commit it
repoClone.remotes.set_url("origin", repo.clone_url)
index = repoClone.index
index.add_all()
index.write()
author = pygit2.Signature("Jesus Christ", github_email)
commiter = pygit2.Signature("Jesus Christ", github_email)
tree = index.write_tree()
oid = repoClone.create_commit('refs/heads/master', author, commiter, "init commit", tree, [repoClone.head.get_object().hex])
remote = repoClone.remotes["origin"]
credentials = pygit2.UserPass(github_username, github_password)
remote.credentials = credentials
callbacks = pygit2.RemoteCallbacks(credentials=credentials)
remote.push(['refs/heads/master'], callbacks=callbacks)
This results in
oid = repoClone.create_commit('HEAD', author, commiter, "init commit", tree, [repoClone.head.get_object().hex])
_pygit2.GitError: reference 'refs/heads/master' not found
git show-ref is empty, but this is pretty much expected, no?
This commit and push still go through, but the error is nevertheless thrown.
Am I doing something wrong?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 pygit2.clone_repository、repoClone.create_commit 和 remote.push 周围开始复现;检查 git show-ref 的空状态以及传递给 create_commit 的引用。确认为什么尽管报告了异常,commit 和 push 似乎仍然成功,然后验证同一个脚本可以在没有该错误的情况下完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- git, python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100