Commit ca9af13f authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'zj-branch-crud-no-hook' into 'master'

Remove client need for no hook branch CRUD methods.

See merge request gitlab-org/gitlab!19815
parents 7bb350ec 47d00264
......@@ -636,10 +636,9 @@ module Gitlab
end
# Delete the specified branch from the repository
# Note: No Git hooks are executed for this action
def delete_branch(branch_name)
wrapped_gitaly_errors do
gitaly_ref_client.delete_branch(branch_name)
end
write_ref(branch_name, Gitlab::Git::BLANK_SHA)
rescue CommandError => e
raise DeleteBranchError, e
end
......@@ -651,14 +650,13 @@ module Gitlab
end
# Create a new branch named **ref+ based on **stat_point+, HEAD by default
# Note: No Git hooks are executed for this action
#
# Examples:
# create_branch("feature")
# create_branch("other-feature", "master")
def create_branch(ref, start_point = "HEAD")
wrapped_gitaly_errors do
gitaly_ref_client.create_branch(ref, start_point)
end
write_ref(ref, start_point)
end
# If `mirror_refmap` is present the remote is set as mirror with that mapping
......
......@@ -151,40 +151,6 @@ module Gitlab
Gitlab::Git::Branch.new(@repository, encode!(branch.name.dup), branch.target_commit.id, target_commit)
end
def create_branch(ref, start_point)
request = Gitaly::CreateBranchRequest.new(
repository: @gitaly_repo,
name: encode_binary(ref),
start_point: encode_binary(start_point)
)
response = GitalyClient.call(@repository.storage, :ref_service, :create_branch, request, timeout: GitalyClient.medium_timeout)
case response.status
when :OK
branch = response.branch
target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit)
Gitlab::Git::Branch.new(@repository, branch.name, branch.target_commit.id, target_commit)
when :ERR_INVALID
invalid_ref!("Invalid ref name")
when :ERR_EXISTS
invalid_ref!("Branch #{ref} already exists")
when :ERR_INVALID_START_POINT
invalid_ref!("Invalid reference #{start_point}")
else
raise "Unknown response status: #{response.status}"
end
end
def delete_branch(branch_name)
request = Gitaly::DeleteBranchRequest.new(
repository: @gitaly_repo,
name: encode_binary(branch_name)
)
GitalyClient.call(@repository.storage, :ref_service, :delete_branch, request, timeout: GitalyClient.medium_timeout)
end
def delete_refs(refs: [], except_with_prefixes: [])
request = Gitaly::DeleteRefsRequest.new(
repository: @gitaly_repo,
......
......@@ -187,7 +187,7 @@ describe 'User creates branch and merge request on issue page', :js do
let(:branch_name) { "#{issue.iid}-foo" }
before do
project.repository.create_branch(branch_name, 'master')
project.repository.create_branch(branch_name)
visit project_issue_path(project, issue)
end
......
......@@ -169,8 +169,8 @@ describe 'Merge request > User resolves conflicts', :js do
context "with malicious branch name" do
let(:bad_branch_name) { "malicious-branch-{{toString.constructor('alert(/xss/)')()}}" }
let(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') }
let(:merge_request) { create_merge_request(branch.name) }
let!(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') }
let(:merge_request) { create_merge_request(bad_branch_name) }
before do
visit project_merge_request_path(project, merge_request)
......
......@@ -60,7 +60,7 @@ describe 'Project Graph', :js do
let(:branch_name) { '<h1>evil</h1>' }
before do
project.repository.create_branch(branch_name, 'master')
project.repository.create_branch(branch_name)
visit charts_project_graph_path(project, branch_name)
end
......
......@@ -310,8 +310,8 @@ describe Gitlab::Git::Repository, :seed_helper do
with_them do
before do
repository.create_branch('left-branch', 'master')
repository.create_branch('right-branch', 'master')
repository.create_branch('left-branch')
repository.create_branch('right-branch')
left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff')
......@@ -350,8 +350,8 @@ describe Gitlab::Git::Repository, :seed_helper do
with_them do
before do
repository.create_branch('left-branch', 'master')
repository.create_branch('right-branch', 'master')
repository.create_branch('left-branch')
repository.create_branch('right-branch')
left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff')
......@@ -420,55 +420,6 @@ describe Gitlab::Git::Repository, :seed_helper do
end
end
describe "#delete_branch" do
let(:repository) { mutable_repository }
after do
ensure_seeds
end
it "removes the branch from the repo" do
branch_name = "to-be-deleted-soon"
repository.create_branch(branch_name)
expect(repository_rugged.branches[branch_name]).not_to be_nil
repository.delete_branch(branch_name)
expect(repository_rugged.branches[branch_name]).to be_nil
end
context "when branch does not exist" do
it "raises a DeleteBranchError exception" do
expect { repository.delete_branch("this-branch-does-not-exist") }.to raise_error(Gitlab::Git::Repository::DeleteBranchError)
end
end
end
describe "#create_branch" do
let(:repository) { mutable_repository }
after do
ensure_seeds
end
it "creates a new branch" do
expect(repository.create_branch('new_branch', 'master')).not_to be_nil
end
it "creates a new branch with the right name" do
expect(repository.create_branch('another_branch', 'master').name).to eq('another_branch')
end
it "fails if we create an existing branch" do
repository.create_branch('duplicated_branch', 'master')
expect {repository.create_branch('duplicated_branch', 'master')}.to raise_error("Branch duplicated_branch already exists")
end
it "fails if we create a branch from a non existing ref" do
expect {repository.create_branch('branch_based_in_wrong_ref', 'master_2_the_revenge')}.to raise_error("Invalid reference master_2_the_revenge")
end
end
describe '#delete_refs' do
let(:repository) { mutable_repository }
......@@ -506,8 +457,8 @@ describe Gitlab::Git::Repository, :seed_helper do
let(:utf8_branch) { 'branch-é' }
before do
repository.create_branch(new_branch, 'master')
repository.create_branch(utf8_branch, 'master')
repository.create_branch(new_branch)
repository.create_branch(utf8_branch)
end
after do
......@@ -609,32 +560,30 @@ describe Gitlab::Git::Repository, :seed_helper do
describe '#search_files_by_content' do
let(:repository) { mutable_repository }
let(:repository_rugged) { mutable_repository_rugged }
let(:ref) { 'search-files-by-content-branch' }
let(:content) { 'foobarbazmepmep' }
before do
repository.create_branch('search-files-by-content-branch', 'master')
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'search-files-by-content-branch', 'committing something', 'search-files-by-content change')
new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', 'search-files-by-content-branch', 'committing something', 'search-files-by-content change')
repository.create_branch(ref)
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', ref, 'committing something', content)
new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', ref, 'committing something', content)
end
after do
ensure_seeds
end
shared_examples 'search files by content' do
it 'has 2 items' do
expect(search_results.size).to eq(2)
end
subject do
repository.search_files_by_content(content, ref)
end
it 'has the correct matching line' do
expect(search_results).to contain_exactly("search-files-by-content-branch:encoding/CHANGELOG\u00001\u0000search-files-by-content change\n",
"search-files-by-content-branch:anotherfile\u00001\u0000search-files-by-content change\n")
end
it 'has 2 items' do
expect(subject.size).to eq(2)
end
it_should_behave_like 'search files by content' do
let(:search_results) do
repository.search_files_by_content('search-files-by-content', 'search-files-by-content-branch')
end
it 'has the correct matching line' do
expect(subject).to contain_exactly("#{ref}:encoding/CHANGELOG\u00001\u0000#{content}\n",
"#{ref}:anotherfile\u00001\u0000#{content}\n")
end
end
......@@ -1116,7 +1065,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do
create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master')
repository.create_branch('local_branch')
end
after do
......@@ -1142,7 +1091,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do
create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master')
repository.create_branch('local_branch')
end
after do
......@@ -1192,7 +1141,7 @@ describe Gitlab::Git::Repository, :seed_helper do
context 'when no branch names are specified' do
before do
repository.create_branch('identical', 'master')
repository.create_branch('identical')
end
after do
......@@ -1303,7 +1252,7 @@ describe Gitlab::Git::Repository, :seed_helper do
let(:branch_name) { "ʕ•ᴥ•ʔ" }
before do
repository.create_branch(branch_name, "master")
repository.create_branch(branch_name)
end
after do
......@@ -1447,7 +1396,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do
create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master')
repository.create_branch('local_branch')
end
after do
......
......@@ -74,7 +74,7 @@ describe PushEvent do
create(:push_event_payload, event: event4, ref: 'baz', action: :removed)
create(:push_event_payload, event: event5, ref: 'baz', ref_type: :tag)
project.repository.create_branch('bar', 'master')
project.repository.create_branch('bar')
create(
:merge_request,
......@@ -83,7 +83,7 @@ describe PushEvent do
source_branch: 'bar'
)
project.repository.create_branch('qux', 'master')
project.repository.create_branch('qux')
create(
:merge_request,
......
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