libgit2 / libgit2/pygit2

_pygit2.GitError: reference 'refs/heads/master' not found

オープン
#981 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

support
主要言語
Python
スター
1.7k
フォーク
408
平均マージ
2日 57分
マージ済み PR(30日)
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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。