initialize with README option doesn't work for developers when creating a repository

Summary

initialize with README option doesn't work for developers when creating a repository. The comment confirming this bug.

Steps to reproduce

  1. Create a new user and add them to a group with the Developer role.
  2. Sign out of your account.
  3. Sign in as the newly created user.
  4. Try to create a repository with the initialize with README option enabled.
  5. Go to the newly created repository.
  6. Make sure that: a) no README file is there b) the repository is not initialized - there aren't any branches

Example Project

What is the current bug behavior?

file is not created, repository is not initialized

What is the expected correct behavior?

  • The file is created, the repository is initialized successfully.

Alternatively

  • Do not allow developers to perform operations whose functionality is not guaranteed to them. Clearly indicate in the UX/UI that they will not get the expected result, or that performing the desired operation is prohibited/impossible.

Relevant logs and/or screenshots

The following error is thrown in exceptions_json.log:

 "exception.class": "Commits::CreateService::ValidationError",
  "exception.message": "You are not allowed to push into this branch",
  "exception.backtrace": [
    "app/services/commits/create_service.rb:53:in `raise_error'",
    "app/services/commits/create_service.rb:77:in `validate_permissions!'",
    "app/services/commits/create_service.rb:65:in `validate!'",
    "ee/app/services/ee/commits/create_service.rb:12:in `validate!'",
    "app/services/files/create_service.rb:16:in `validate!'",
    "app/services/commits/create_service.rb:28:in `execute'",
    "app/services/projects/create_service.rb:215:in `create_readme'",
    "app/services/projects/create_service.rb:147:in `after_create_actions'",
    "ee/app/services/ee/projects/create_service.rb:74:in `after_create_actions'",
    "app/services/projects/create_service.rb:88:in `block in execute'",
    "lib/gitlab/application_context.rb:173:in `block in use'",
    "gitlab-labkit (0.37.0) lib/labkit/context.rb:35:in `with_context'",
    "lib/gitlab/application_context.rb:173:in `use'",
    "lib/gitlab/application_context.rb:96:in `with_context'",
    "app/services/projects/create_service.rb:87:in `execute'",
    "ee/app/services/ee/projects/create_service.rb:36:in `execute'",
    "app/controllers/projects_controller.rb:110:in `create'",
    "actionpack (7.0.8.7) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'",
    "actionpack (7.0.8.7) lib/abstract_controller/base.rb:215:in `process_action'",
    "actionpack (7.0.8.7) lib/action_controller/metal/rendering.rb:165:in `process_action'",
    "actionpack (7.0.8.7) lib/abstract_controller/callbacks.rb:234:in `block in process_action'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:118:in `block in run_callbacks'",
    "lib/gitlab/ip_address_state.rb:11:in `with'",
    "ee/app/controllers/ee/application_controller.rb:45:in `set_current_ip_address'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
    "app/controllers/application_controller.rb:491:in `set_current_admin'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
    "lib/gitlab/session.rb:11:in `with_session'",
    "app/controllers/application_controller.rb:482:in `set_session_storage'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
    "lib/gitlab/i18n.rb:114:in `with_locale'",
    "lib/gitlab/i18n.rb:120:in `with_user_locale'",
    "app/controllers/application_controller.rb:473:in `set_locale'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
    "app/controllers/application_controller.rb:466:in `set_current_context'",
    "activesupport (7.0.8.7) lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
    "marginalia (1.11.1) lib/marginalia.rb:109:in `record_query_comment'",
...

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
 (For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:env:info\`)  (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\`)  

Results of GitLab application Check

Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:check SANITIZE=true`)

(For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true`)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Alex Ted