Skip to content

Fix accidental commits collection mutation

Vasilii Iakliushin requested to merge 356094_fix_commits_mutation_problem into master

What does this MR do and why?

Contributes to #356094 (closed)

Introduced in !123950 (merged)

Sentry error: https://new-sentry.gitlab.net/organizations/gitlab/issues/268934

Problem

#prepend method executes in-place update for commits collection. That breaks code executed after it.

Solution

Use a copy of commit collection to avoid an accidental mutation.

How to set up and validate locally

  1. Enable feature flag Feature.enable(:verify_push_rules_for_first_commit)
  2. Create an empty repository
  3. Go to Settings -> Repository -> Push Rules
  4. Enable "Prevent pushing secret files" and save
  5. Clone the empty repository
  6. Create 2 commits locally
  7. Push to the repository
  8. It should work

Before the fix:

remote: GitLab: 500 Internal Server Error
To ssh://gdk.test:2222/root/empty-repo.git
 ! [remote rejected] HEAD -> main (pre-receive hook declined)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vasilii Iakliushin

Merge request reports