API - Repositories/Compare outputs an incorrectly formatted raw diff result
Summary
Using the Repositories/Compare API has caused a regression in the output of the diff
value in the response. This has changed going from 10.8.x to 11.3.4. I haven't tested this further with other version numbers to determine when this happened. Both use v4 of the API.
In Gitlab 11.3.4, please see the output below of the API request given:
URL: GET /projects/31/repository/compare?from=25e7dbca&to=2885c17f
Response:
[
{
"old_path"=>"Gemfile",
"new_path"=>"Gemfile",
"a_mode"=>"100644",
"b_mode"=>"100644",
"new_file"=>false,
"renamed_file"=>false,
"deleted_file"=>false,
"diff"=>"@@ -103,11 +103,11 @@ gem 'google-cloud-pubsub', '~> 0.23.2'\n \n gem 'redis-semaphore', '0.3.1'\n \n-gem 'referrals', git: <TRUNCATED>"
}
]
As you can see under diff
, that value isn't the traditional diff format or what is given in the documentation here: https://docs.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits
The diff format should include the filenames that change and a/b mode as the first line of each "diff". I'm not familiar enough with the inner workings of git itself to know what this is called, but hopefully this is visible above.
Steps to reproduce
- Use Gitlab version 11.3.4 (I assume versions higher and some versions lower are also affected)
- In a repository with two existing commits (with some sort of difference between the two), use the Gitlab API to hit the following endpoint:
GET /projects/31/repository/compare?from=<OLD_COMMIT>&to=<NEW_COMMIT>
- Notice for each new "diff" in the response, the actual raw
diff
value doesn't include a traditional header line in the output (that is shown when running "git diff" on the command line)
Example Project
This was done internally on an EE instance, but also reproducable on the Gitlab CE repository here.
url: https://gitlab.com/api/v4/projects/13083/repository/compare?from=7aeab58f&to=79ec24da&private_token=INSERT_TOKEN
Under the "diffs" JSON value, you'll see the exact same behavior.
What is the current bug behavior?
The raw_diff (the diff
value in the diffs array) isn't an actual git diff output. It doesn't return the top line with the filenames of the diff. The issue now is that looking at a raw diff doesn't actually have the proper information for someone viewing it (you have no idea what file it is from or the type of diff itself)
What is the expected correct behavior?
The heading line of each "diff" in the raw output has the filename (before/after) of the proceeding diff.
Relevant logs and/or screenshots
N/A but can be provided.
Output of checks
N/A
Results of GitLab environment info
N/A, this happens on the current version of gitlab.com as well as our internal EE instance.
Results of GitLab application Check
N/A, see above.
Possible fixes
I'm not sure where this happens. It seems API-specific