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?
2 Answers 2
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.
Sign up to request clarification or add additional context in comments.
2 Comments
Nishant
Is there no API in gitpython to do this directly? I am asking this because, most of the time we have a string which contains diff. In that case we will have to first write the diff to a file - then run
r.git.execute and then clean up the file.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
1 Comment
m33n
Don't use links directly, try to paste some of the content to your answer!
lang-py