API v4: GET repository/commits/.../diff cuts off long diffs and does not provide way to get full diff
Summary
I am filing this ticket as a follow-up to https://gitlab.com/gitlab-org/gitlab-ce/issues/50014. I will re-iterate the summary:
If I have a commit in my repository, where the UI shows the following message:
This source diff could not be displayed because it is too large. You can view the blob instead.
then the API call
GET /api/v4/projects/<project>/repository/commits/<SHA>/diff
will give the following result:
[
{
"old_path": "npm-shrinkwrap.json",
"new_path": "npm-shrinkwrap.json",
"a_mode": "100644",
"b_mode": "100644",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"diff": ""
}
]
@oswaldo stated on the original ticket:
As of
11.3
we started cutting-off 'too large' diffs (this case) in the source (Gitaly). The only way of accessing these right now is by fetching the blob content.
This appears to be the case, but there is no field in the API response telling me that the diff has been cut-off. There should be a boolean called pruned
that lets me know if I cannot rely on the diff field.
Also, Oswaldo's response that we should use the blob
endpoint does not address the problem: the blob
endpoint gives us the file content, not the diff content. Thus, if the response from GET /api/v4/projects/<project>/repository/commits/<SHA>/diff
is cut-off I know of no good way for us to get the full diff from the API.
Steps to reproduce
- Clone the repository from https://gitlab.com/rothkamp/testrepo to a GitLab CE server
- Make the API call: GET /api/v4/projects/rothkamp%2Ftestrepo/repository/commits/469d79cb3f70c7c51dc673d78df7ea98e2e1f84f/diff
Example Project
https://gitlab.com/rothkamp/testrepo
What is the current bug behavior?
- There is no field in the API response indicating that the file diff has been cut-off.
- There is no known way to get the full diff for a file if the
commits/.../diff
is cut-off
What is the expected correct behavior?
- The API response indicates per-file whether the
diff
field is cut-off or not. - The v4 API provides a way to get the full diff for a file in a commit.
Results of GitLab environment info
Expand for output related to GitLab environment info
GitLab Enterprise Edition 11.4.8-ee