Skip to content

Fix errors on pushing/editing files on empty repositories

Bob Van Landuyt requested to merge bvl-fix-maintainer-push-error into master

What does this MR do?

  • In this branch we allow admins to push to empty projects, where the default branch is protected.
  • This fixes a crash when someone is not authorized.

The crash was initially caused by calling Gitlab::UserAccess#can_push_to_branch? without a project, we would end up there because a the user can_collaborate_with_project? since they can push_code. Then we'd check if they can push to the branch, but there is none yet, and we don't allow developers to create a new default branch, this needs to be done by owners or admins. So the @project_to_commit_into in CreatesCommit would be empty.

But in the case of a developer, they wouldn't actually be allowed to push to create the new default branch. So we're hiding the buttons

This MR hides the buttons if the user cannot push to the master branch, and hides the commands the user cannot perform.

Screenshots (if relevant)

User can push

Screen_Shot_2018-04-19_at_09.19.59

User can not push

Screen_Shot_2018-04-19_at_09.21.05

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/44618 Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/42583

Edited by Michael Kozono

Merge request reports

Loading