Diff stats can be misleading when renaming a file
At https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/32282/diffs we have a file being renamed from spec/javascripts/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js
to spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js
and it also receives extra additions.
The diff file header doesn't show it's a rename, which is being fixed by https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31888.
Though, we can notice the diff stats just presents the new file as having additions (+55
- note it's the number of lines of the whole file). And that's mainly because at Gitaly we do the following:
› git diff --numstat 27c222d16ccb666878c7ac558f484efa56f77f37..6bbba7017b2f7b995aa972903b8686f9408112da
5 0 changelogs/unreleased/ce-xanf-move-auto-merge-failed-to-jest.yml
55 0 spec/frontend/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js
0 47 spec/javascripts/vue_mr_widget/components/states/mr_widget_auto_merge_failed_spec.js
Note that the output doesn't take into account it's a rename, it sees it as a new file and the old file as deleted (-47
).
We could solve that in the current MR diff by falling back to the diff_lines
parsing if we detect it's a rename in the Diff::File
. Though, it's not the best solution given we're willing to separate the diff_stats
endpoint in order to make two separate calls to build a separate UI (for https://gitlab.com/gitlab-org/gitlab-ce/issues/62536).
Important: It doesn't happen for every file rename with additions/deletions. It seems to happen only when doing more complicated renames (changing folders, etc). I.e. git can't guess in these scenarios apparently.
@kerrizor Given you've been working with that lately, do you see further options?