1

我正在尝试自动化克隆过程,将一些文件添加到本地克隆,然后将更新推送到克隆的存储库。我希望这段代码能够将我的提交推送到 GitHub 中的克隆存储库,但是当我尝试推送时,我不断收到此错误。

我的代码

from github import Github
from credentials import username, password
import pygit2
from git import Repo
import shutil
import subprocess

name = input("Name of iOS project: ") # repo name
description = input("github description: ") 

def createGithubRepo(name, description):
    g = Github(username, password)
    gituser = g.get_user()
    repo = gituser.create_repo(name) 
    repo.create_file("README.md", "init commit", description)
    return repo.git_url 

def clone(url, destination):
    repoClone = pygit2.clone_repository(url, destination)
    repoClone.remotes.set_url("origin", url)
    return repoClone


def basicPushToGithub(pathToRepo, commitMessage, paths):
    repo = Repo(pathToRepo)
    repo.index.add(paths)
    repo.index.commit(commitMessage)
    repo.git.push()

createGithubRepo(name, description)
url = 'https://github.com/<userpath>/'+name+'.git'
repoClone = clone(url, destination)
basicPushToGithub(destination, 'Project added', [destination + name])

错误读数

- h.basicPushToGithub(destination, 'Project added', [destination])
- repo.git.push()
- return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
- return self.execute(call, **exec_kwargs)
- raise GitCommandError(command, status, stderr_value, stdout_value)


GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push
  stderr: 'remote: error: object 609a24caa7cdc1be596d2cc4134379fe66725a4e: hasDotdot: contains '..'        
remote: fatal: fsck error in packed object        
error: remote unpack failed: index-pack abnormal exit
To https://github.com/<your-name>/erftgh9393.git
 ! [remote rejected] master -> master (failed)
error: failed to push some refs to 'https://github.com/<your-name>/erftgh9393.git''

我尝试将不同的参数传递给 push 方法,但我仍然得到同样的错误。如果有一个..被添加到提交中,我真的不确定为什么会发生这种情况,也不知道我能做些什么。

4

0 回答 0