3

I'm trying to push a new git repo upstream using gitpython module. Below are the steps that I'm doing and get an error 128.

# Initialize a local git repo
init_repo = Repo.init(gitlocalrepodir+"%s" %(gitinitrepo))

# Add a file to this new local git repo
init_repo.index.add([filename])

# Initial commit
init_repo.index.commit('Initial Commit - %s' %(timestr))

# Create remote
init_repo.create_remote('origin', giturl+gitinitrepo+'.git')

# Push upstream (Origin)
init_repo.remotes.origin.push()

While executing the push(), gitpython throws an exception:

'git push --porcelain origin' returned with exit code 128

Access to github is via SSH.

Do you see anything wrong that I'm doing?

2 Answers 2

1

I tracked it down with a similar approach:

class ProgressPrinter(git.RemoteProgress):

    def line_dropped(self, line):
        print("line dropped : " + str(line))

Which you can then call in your code:

init_repo.remotes.origin.push(progress=ProgressPrinter())
Sign up to request clarification or add additional context in comments.

Comments

0

You need to capture the output from the git command.

Given this Progress class:

class Progress(git.RemoteProgress):
    def __init__( self ):
        super().__init__()

        self.__all_dropped_lines = []

    def update( self, op_code, cur_count, max_count=None, message='' ):
        pass

    def line_dropped( self, line ):
        if line.startswith( 'POST git-upload-pack' ):
            return

        self.__all_dropped_lines.append( line )

    def allErrorLines( self ):
        return self.error_lines() + self.__all_dropped_lines

    def allDroppedLines( self ):
        return self.__all_dropped_lines

You can write code like this:

progress = Progress()

try:
    for info in remote.push( progress=progress ):
        # call info_callback with the push commands info
        info_callback( info )

    for line in progress.allDroppedLines():
        log.info( line )

except GitCommandError:
    for line in progress.allErrorLines():
        log.error( line )

    raise

When you run with this you will still get the 128 error, but you will also have the output og git to explain the problem.

1 Comment

Couple of items that are not clear from your code snippet. 1. You didn't supply any arguments when you instantiated Progress() 2. What is info_callback(info) supposed to do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.