Is there a way to apply a git patch to a repository using REST Api?

I do some commits using REST Api.
This works fine, but some of the files are large while only a small number of lines are changed.
Thus the JSON object to commit the changes gets very big. A better approach would be to submit only the diff via ‘git apply changes.patch’, but instead of using git directly I would prefer a REST Api solution. Is this possible?

Thanks a lot!
Peter

1 Like

I am looking for exactly this type of solution, and have not found any yet.

I thought I would have complaints about this, but actually the trade offs told me to shut up. This is a good feature to have.

It is not present on https://docs.gitlab.com/ee/api/commits.html#get-references-a-commit-is-pushed-to

I assume you mean -
1 user manually generates the patch using git on the local machine, then send it to server using REST API.
2 script or code generates the patch using git on the local machine, then send it to server using REST API.

Of course, option 2 is better.
And simple to implement. Unless (snipped details…)

Yes! Option 2 is what I’m looking for (in the specific case I would like to generate the patch in a CI pipeline job, save it as artifact and apply it in a later job)

Really what I am looking for ultimately is not this, but since I found no actual solution to my problem, then I thought a patch was a way to go.

What I am really trying is:

  1. There is a PR on GitHub. GitHub is a mirror of our actual GitLab repo.
  2. I want to export the GitHub PR to GitLab MR and treat the MR in Gitlab
  3. Once merged in GitLab the original GitHub PR should be automatically marked as “merged”.

I wanted to use the API for this, and since I found no way to fetch the full PR with all its commits etc from Github and create a GitLab MR of it (maybe I just did not understand how to) then I thought to transfer the commits one by one and commit to a new branch in GitLab. But then it would be nice just to use the patches.

So the scenario would be

  1. New GitHub PR
  2. Webhook in GitLab that fetches the patches of the GitHub PR and applies them in a new branch in GitLab.
  3. Merge branch in GitLab.

But, I have myself gone away from this solution.

What I did ultimately was:
Have a webhook that registers new GItHub PR.
Use python subprocess with the git commands to fetch the pull-request (having github as a remote) and create a branch of it in gitlab. Merge in gitlab. Result: commit-shas are the same on Github and Gitlab and the Github PR gets automatically marked as merged due to the mirroring.

I’ve created an Issue