Counterpart of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18461.
Discussion on https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18461#note_70074439.