Skip to content

Commits API diff is missing prefix with file paths

Summary

Commits API diff is missing prefix specifying old and new paths of a file

Steps to reproduce

Use commits API to get a diff of any commit https://docs.gitlab.com/ee/api/commits.html#get-the-diff-of-a-commit

What is the current bug behavior?

The response diff value is invalid as it does not contain file paths:

[
  {
    "diff": "@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
    "new_path": "doc/update/5.4-to-6.0.md",
    "old_path": "doc/update/5.4-to-6.0.md",
    "a_mode": null,
    "b_mode": "100644",
    "new_file": false,
    "renamed_file": false,
    "deleted_file": false
  }
]

Missing --- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n

What is the expected correct behavior?

The response diff value is valid and contains file paths:

[
  {
    "diff": "--- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
    "new_path": "doc/update/5.4-to-6.0.md",
    "old_path": "doc/update/5.4-to-6.0.md",
    "a_mode": null,
    "b_mode": "100644",
    "new_file": false,
    "renamed_file": false,
    "deleted_file": false
  }
]

Results of GitLab environment info

Gitlab API v4 11.4.4-ee and 11.5.1-ee

Possible fixes

I suspect it was introduced in some of the dependencies producing git diff (Rugged or libgit2).

Edited by Nickolay Tarbayev