How to pull, push with a remote branch

I am trying to automate a change process that is currently generating source code that is manually ported to Git. I am trying to wrap this code using GitPython :

from git import *

# create the local repo
repo = Repo.init("/tmp/test/repo", bare=True)
assert repo.bare == True

# check status of active branch
repo.is_dirty()

# clone the remote repo
remote_repo = repo.clone("http://user:pass@git/repo.git")

# compile source code into repository
# ... 

# track untracked files
repo.untracked_files

# commit changes locally
repo.commit("commit changes")

# push changes to master
remote_repo.push()

When I try to run this, I get

Traceback (last last call):

File "git_test2.py", line 33, in

repo.commit ("commit changes")

BadObject: 636f6d6d6974206368616e676573

The script is able to pull out the remote repository, but it fails to commit. Is there a better approach to this?

+4
source share
2 answers

, , , . , Repo git .

, :

repo = Repo.clone_from("http://user:pass@git/repo.git", "/tmp/test/repo")

, GitPython, . API.

+4

. / . , . , .

pythonic git, , , , , git , .

, repo.untracked_files , , .

, , https://pythonhosted.org/GitPython/0.3.1/tutorial.html, , , , .

,

index = repo.index
for ( path, stage ), entry in index.entries.iteritems: pass
index.add(['SOMEFILE'])
new_commit = index.commit("YOUR COMMIT MESSAGE")
#do somethign with new commit    

,

import git
repo = git.Repo( '/home/me/repodir' )
print repo.git.status()
# checkout and track a remote branch
print repo.git.checkout( 'origin/somebranch', b='somebranch' )
# add a file
print repo.git.add( 'somefile' )
# commit
print repo.git.commit( m='my commit message' )
# now we are one commit ahead
print repo.git.status()
# now push
+1

Source: https://habr.com/ru/post/1533596/


All Articles