diff --git a/app/controllers/concerns/creates_commit.rb b/app/controllers/concerns/creates_commit.rb index 896004045f487a788d629fc06ed6ecd975b5e071..27f1d1f5528793332472b315fcba354d47ad48d9 100644 --- a/app/controllers/concerns/creates_commit.rb +++ b/app/controllers/concerns/creates_commit.rb @@ -10,18 +10,18 @@ def create_commit(service, success_path:, failure_path:, failure_view: nil, succ if user_access(target_project).can_push_to_branch?(branch_name_or_ref) @project_to_commit_into = target_project + @different_project = false @branch_name ||= @ref else @project_to_commit_into = current_user.fork_of(target_project) + @different_project = true @branch_name ||= @project_to_commit_into.repository.next_branch('patch') end @start_branch ||= @ref || @branch_name - start_project = @project_to_commit_into - commit_params = @commit_params.merge( - start_project: start_project, + start_project: @project_to_commit_into, start_branch: @start_branch, source_project: @project, target_project: target_project, @@ -74,7 +74,7 @@ def update_flash_notice(success_notice) nil else mr_message = - if different_project? + if @different_project # rubocop:disable Gitlab/ModuleWithInstanceVariables _("You can now submit a merge request to get this change into the original project.") else _("You can now submit a merge request to get this change into the original branch.") @@ -128,16 +128,12 @@ def merge_request_exists? # rubocop: enable CodeReuse/ActiveRecord # rubocop:enable Gitlab/ModuleWithInstanceVariables - def different_project? - @project_to_commit_into != @project # rubocop:disable Gitlab/ModuleWithInstanceVariables - end - def create_merge_request? # Even if the field is set, if we're checking the same branch # as the target branch in the same project, # we don't want to create a merge request. params[:create_merge_request].present? && - (different_project? || @start_branch != @branch_name) # rubocop:disable Gitlab/ModuleWithInstanceVariables + (@different_project || @start_branch != @branch_name) # rubocop:disable Gitlab/ModuleWithInstanceVariables end def branch_name_or_ref diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 56e4b22ded27883a719ffd94b21259cc20705035..18ed617e20cdf02482594c40e607057174e66541 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -101,8 +101,9 @@ def update ) rescue Files::UpdateService::FileChangedError @conflict = true - @different_project = different_project? - render :edit + render "edit", locals: { + commit_to_fork: @different_project + } end def preview diff --git a/app/views/projects/blob/edit.html.haml b/app/views/projects/blob/edit.html.haml index 195dc03632ab19a27cbfc2f536781ecb829251c3..74f1688a2db0177513f9389558b2cd841f0c32c4 100644 --- a/app/views/projects/blob/edit.html.haml +++ b/app/views/projects/blob/edit.html.haml @@ -12,7 +12,7 @@ - link_end = ''.html_safe - external_link_icon = content_tag 'span', { aria: { label: _('Opens new window') }} do - sprite_icon('external-link', css_class: 'gl-icon').html_safe - - if @different_project + - if commit_to_fork = _("Error: Can't edit this file. The fork and upstream project have diverged. %{link_start}Edit the file on the fork %{icon}%{link_end}, and create a merge request.").html_safe % {link_start: blob_link_start % { url: project_blob_path(@project_to_commit_into, @id) } , link_end: link_end, icon: external_link_icon } - else - blob_url = project_blob_path(@project, @id)