Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitpython equivalent of git-apply

Is there a way to apply a patch (in the form of a diff file) to a repo using only the gitpython library?

In other words, is there a gitpython equivalent of the git-apply command?

like image 728
chuck1 Avatar asked Mar 24 '26 16:03

chuck1


2 Answers

Solution is to do

r = Repo('path-to-repo')
r.git.execute(['git','apply','patch.diff'])

I had tried this before but I had omitted the 'git' at the beginning of the argument list, which gave an error about the command not existing.

like image 190
chuck1 Avatar answered Mar 27 '26 06:03

chuck1


You can use git directly, like this:

 repo = git.Repo('repository_path') 

 repo.git.apply(['-3', 'patch-file'])

this will perform the git command:

git apply -3 patch-file
like image 24
tomRatzfatz Avatar answered Mar 27 '26 04:03

tomRatzfatz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!