2

I am trying to automate the process of cloning, adding a few files to the local clone, and then pushing the update to the cloned repo. I expected this code to push my commit to the cloned repo in GitHub, but When I try pushing I keep getting this error.

My code

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])

Error Readout

- 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''

I've tried passing different arguments to the push method, but I still get the same error. If there is a .. being added to the commit, I'm really not sure why that is happening, nor what I can do about it.

ScottyBlades
  • 12,189
  • 5
  • 77
  • 85
  • It looks like `` was never substituted with a real username. The presence of `` without any formatting in your code snippet is suspicious also – causaSui May 17 '20 at 22:35
  • 1
    Unfortunately it’s the opposite, this is my sanitized version. I put that in there to try to signal what needs replacing. – ScottyBlades May 17 '20 at 22:52

0 Answers0