Commit c98a3c49 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'an/use-branch-exists-over-branch-names-include' into 'master'

Stop using `branch_names.include?` and use `branch_exists?`

See merge request gitlab-org/gitlab-ce!14778
parents 900dd7fa 47d19c2d
...@@ -4,8 +4,8 @@ module CompareHelper ...@@ -4,8 +4,8 @@ module CompareHelper
to.present? && to.present? &&
from != to && from != to &&
can?(current_user, :create_merge_request, project) && can?(current_user, :create_merge_request, project) &&
project.repository.branch_names.include?(from) && project.repository.branch_exists?(from) &&
project.repository.branch_names.include?(to) project.repository.branch_exists?(to)
end end
def create_mr_path(from = params[:from], to = params[:to], project = @project) def create_mr_path(from = params[:from], to = params[:to], project = @project)
......
...@@ -675,13 +675,13 @@ class MergeRequest < ActiveRecord::Base ...@@ -675,13 +675,13 @@ class MergeRequest < ActiveRecord::Base
def source_branch_exists? def source_branch_exists?
return false unless self.source_project return false unless self.source_project
self.source_project.repository.branch_names.include?(self.source_branch) self.source_project.repository.branch_exists?(self.source_branch)
end end
def target_branch_exists? def target_branch_exists?
return false unless self.target_project return false unless self.target_project
self.target_project.repository.branch_names.include?(self.target_branch) self.target_project.repository.branch_exists?(self.target_branch)
end end
def merge_commit_message(include_description: false) def merge_commit_message(include_description: false)
......
...@@ -458,7 +458,7 @@ module QuickActions ...@@ -458,7 +458,7 @@ module QuickActions
target_branch_param.strip target_branch_param.strip
end end
command :target_branch do |branch_name| command :target_branch do |branch_name|
@updates[:target_branch] = branch_name if project.repository.branch_names.include?(branch_name) @updates[:target_branch] = branch_name if project.repository.branch_exists?(branch_name)
end end
desc 'Move issue from one column of the board to another' desc 'Move issue from one column of the board to another'
......
---
title: Avoid fetching all branches for branch existence checks
merge_request: 14778
author:
type: changed
...@@ -62,7 +62,7 @@ describe Projects::BranchesController do ...@@ -62,7 +62,7 @@ describe Projects::BranchesController do
let(:branch) { "feature%2Ftest" } let(:branch) { "feature%2Ftest" }
let(:ref) { "<script>alert('ref');</script>" } let(:ref) { "<script>alert('ref');</script>" }
it { is_expected.to render_template('new') } it { is_expected.to render_template('new') }
it { project.repository.branch_names.include?('feature/test') } it { project.repository.branch_exists?('feature/test') }
end end
end end
......
...@@ -118,7 +118,7 @@ feature 'issuable templates', :js do ...@@ -118,7 +118,7 @@ feature 'issuable templates', :js do
context 'user creates a merge request from a forked project using templates' do context 'user creates a merge request from a forked project using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' } let(:template_content) { 'this is a test "feature-proposal" template' }
let(:fork_user) { create(:user) } let(:fork_user) { create(:user) }
let(:forked_project) { fork_project(project, fork_user) } let(:forked_project) { fork_project(project, fork_user, repository: true) }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) } let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) }
background do background do
......
...@@ -6,7 +6,7 @@ describe 'User views an open merge request' do ...@@ -6,7 +6,7 @@ describe 'User views an open merge request' do
end end
context 'when a merge request does not have repository' do context 'when a merge request does not have repository' do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public, :repository) }
before do before do
visit(merge_request_path(merge_request)) visit(merge_request_path(merge_request))
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
feature 'Task Lists' do feature 'Task Lists' do
include Warden::Test::Helpers include Warden::Test::Helpers
let(:project) { create(:project) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
......
require 'spec_helper' require 'spec_helper'
describe MergeRequestEntity do describe MergeRequestEntity do
let(:project) { create :project } let(:project) { create :project, :repository }
let(:resource) { create(:merge_request, source_project: project, target_project: project) } let(:resource) { create(:merge_request, source_project: project, target_project: project) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment