NoMethodError: Projects::BlobController#update - undefined method `repository' for nil:NilClass

Problem

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

NoMethodError: undefined method `repository' for nil:NilClass (NoMethodError)

      @branch_name ||= @project_to_commit_into.repository.next_branch('patch')
                                              ^^^^^^^^^^^
  from app/controllers/concerns/creates_commit.rb:20:in `create_commit'
  from app/controllers/projects/blob_controller.rb:94:in `update'
  from action_controller/metal/basic_implicit_render.rb:6:in `send_action'
  ...

Proposal

  • Reproduce this exception
  • Handle the exception and add a test for this case