Commit 47d00264 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Cleanup tests, remove useless arguments

The default argument, HEAD, is better than master, as it's a symbolic
reference.
parent 02c6f7ec
...@@ -18,7 +18,6 @@ module Gitlab ...@@ -18,7 +18,6 @@ module Gitlab
GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git' GITALY_INTERNAL_URL = 'ssh://gitaly/internal.git'
GITLAB_PROJECTS_TIMEOUT = Gitlab.config.gitlab_shell.git_timeout GITLAB_PROJECTS_TIMEOUT = Gitlab.config.gitlab_shell.git_timeout
EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000' EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000'
REF_REMOVAL_UPDATE_REV = '0' * 40
NoRepository = Class.new(StandardError) NoRepository = Class.new(StandardError)
InvalidRepository = Class.new(StandardError) InvalidRepository = Class.new(StandardError)
...@@ -639,7 +638,7 @@ module Gitlab ...@@ -639,7 +638,7 @@ module Gitlab
# Delete the specified branch from the repository # Delete the specified branch from the repository
# Note: No Git hooks are executed for this action # Note: No Git hooks are executed for this action
def delete_branch(branch_name) def delete_branch(branch_name)
write_ref(branch_name, REF_REMOVAL_UPDATE_REV) write_ref(branch_name, Gitlab::Git::BLANK_SHA)
rescue CommandError => e rescue CommandError => e
raise DeleteBranchError, e raise DeleteBranchError, e
end end
......
...@@ -151,40 +151,6 @@ module Gitlab ...@@ -151,40 +151,6 @@ module Gitlab
Gitlab::Git::Branch.new(@repository, encode!(branch.name.dup), branch.target_commit.id, target_commit) Gitlab::Git::Branch.new(@repository, encode!(branch.name.dup), branch.target_commit.id, target_commit)
end 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: []) def delete_refs(refs: [], except_with_prefixes: [])
request = Gitaly::DeleteRefsRequest.new( request = Gitaly::DeleteRefsRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
......
...@@ -48,14 +48,6 @@ module Gitlab ...@@ -48,14 +48,6 @@ module Gitlab
@project.repository.create_branch(@merge_request.target_branch, @merge_request.target_branch_sha) @project.repository.create_branch(@merge_request.target_branch, @merge_request.target_branch_sha)
end end
def fetch_ref
target_ref = Gitlab::Git::BRANCH_REF_PREFIX + @merge_request.source_branch
unless @project.repository.fetch_source_branch!(@project.repository, @diff_head_sha, target_ref)
Rails.logger.warn("Import/Export warning: Failed to create #{target_ref} for MR: #{@merge_request.iid}") # rubocop:disable Gitlab/RailsLogger
end
end
def branch_exists?(branch_name) def branch_exists?(branch_name)
@project.repository.raw.branch_exists?(branch_name) @project.repository.raw.branch_exists?(branch_name)
end end
......
...@@ -187,7 +187,7 @@ describe 'User creates branch and merge request on issue page', :js do ...@@ -187,7 +187,7 @@ describe 'User creates branch and merge request on issue page', :js do
let(:branch_name) { "#{issue.iid}-foo" } let(:branch_name) { "#{issue.iid}-foo" }
before do before do
project.repository.create_branch(branch_name, 'master') project.repository.create_branch(branch_name)
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
end end
......
...@@ -169,8 +169,8 @@ describe 'Merge request > User resolves conflicts', :js do ...@@ -169,8 +169,8 @@ describe 'Merge request > User resolves conflicts', :js do
context "with malicious branch name" do context "with malicious branch name" do
let(:bad_branch_name) { "malicious-branch-{{toString.constructor('alert(/xss/)')()}}" } let(:bad_branch_name) { "malicious-branch-{{toString.constructor('alert(/xss/)')()}}" }
let(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') } let!(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') }
let(:merge_request) { create_merge_request(branch.name) } let(:merge_request) { create_merge_request(bad_branch_name) }
before do before do
visit project_merge_request_path(project, merge_request) visit project_merge_request_path(project, merge_request)
......
...@@ -60,7 +60,7 @@ describe 'Project Graph', :js do ...@@ -60,7 +60,7 @@ describe 'Project Graph', :js do
let(:branch_name) { '<h1>evil</h1>' } let(:branch_name) { '<h1>evil</h1>' }
before do before do
project.repository.create_branch(branch_name, 'master') project.repository.create_branch(branch_name)
visit charts_project_graph_path(project, branch_name) visit charts_project_graph_path(project, branch_name)
end end
......
...@@ -310,8 +310,8 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -310,8 +310,8 @@ describe Gitlab::Git::Repository, :seed_helper do
with_them do with_them do
before do before do
repository.create_branch('left-branch', 'master') repository.create_branch('left-branch')
repository.create_branch('right-branch', 'master') repository.create_branch('right-branch')
left.times do left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') 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 ...@@ -350,8 +350,8 @@ describe Gitlab::Git::Repository, :seed_helper do
with_them do with_them do
before do before do
repository.create_branch('left-branch', 'master') repository.create_branch('left-branch')
repository.create_branch('right-branch', 'master') repository.create_branch('right-branch')
left.times do left.times do
new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff') new_commit_edit_new_file_on_branch(repository_rugged, 'encoding/CHANGELOG', 'left-branch', 'some more content for a', 'some stuff')
...@@ -457,8 +457,8 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -457,8 +457,8 @@ describe Gitlab::Git::Repository, :seed_helper do
let(:utf8_branch) { 'branch-é' } let(:utf8_branch) { 'branch-é' }
before do before do
repository.create_branch(new_branch, 'master') repository.create_branch(new_branch)
repository.create_branch(utf8_branch, 'master') repository.create_branch(utf8_branch)
end end
after do after do
...@@ -560,32 +560,30 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -560,32 +560,30 @@ describe Gitlab::Git::Repository, :seed_helper do
describe '#search_files_by_content' do describe '#search_files_by_content' do
let(:repository) { mutable_repository } let(:repository) { mutable_repository }
let(:repository_rugged) { mutable_repository_rugged } let(:repository_rugged) { mutable_repository_rugged }
let(:ref) { 'search-files-by-content-branch' }
let(:content) { 'foobarbazmepmep' }
before do before do
repository.create_branch('search-files-by-content-branch', 'master') repository.create_branch(ref)
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, 'encoding/CHANGELOG', ref, 'committing something', content)
new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', 'search-files-by-content-branch', 'committing something', 'search-files-by-content change') new_commit_edit_new_file_on_branch(repository_rugged, 'anotherfile', ref, 'committing something', content)
end end
after do after do
ensure_seeds ensure_seeds
end end
shared_examples 'search files by content' do subject do
it 'has 2 items' do repository.search_files_by_content(content, ref)
expect(search_results.size).to eq(2) end
end
it 'has the correct matching line' do it 'has 2 items' do
expect(search_results).to contain_exactly("search-files-by-content-branch:encoding/CHANGELOG\u00001\u0000search-files-by-content change\n", expect(subject.size).to eq(2)
"search-files-by-content-branch:anotherfile\u00001\u0000search-files-by-content change\n")
end
end end
it_should_behave_like 'search files by content' do it 'has the correct matching line' do
let(:search_results) do expect(subject).to contain_exactly("#{ref}:encoding/CHANGELOG\u00001\u0000#{content}\n",
repository.search_files_by_content('search-files-by-content', 'search-files-by-content-branch') "#{ref}:anotherfile\u00001\u0000#{content}\n")
end
end end
end end
...@@ -1067,7 +1065,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1067,7 +1065,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do before do
create_remote_branch('joe', 'remote_branch', 'master') create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master') repository.create_branch('local_branch')
end end
after do after do
...@@ -1093,7 +1091,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1093,7 +1091,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do before do
create_remote_branch('joe', 'remote_branch', 'master') create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master') repository.create_branch('local_branch')
end end
after do after do
...@@ -1143,7 +1141,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1143,7 +1141,7 @@ describe Gitlab::Git::Repository, :seed_helper do
context 'when no branch names are specified' do context 'when no branch names are specified' do
before do before do
repository.create_branch('identical', 'master') repository.create_branch('identical')
end end
after do after do
...@@ -1254,7 +1252,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1254,7 +1252,7 @@ describe Gitlab::Git::Repository, :seed_helper do
let(:branch_name) { "ʕ•ᴥ•ʔ" } let(:branch_name) { "ʕ•ᴥ•ʔ" }
before do before do
repository.create_branch(branch_name, "master") repository.create_branch(branch_name)
end end
after do after do
...@@ -1398,7 +1396,7 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1398,7 +1396,7 @@ describe Gitlab::Git::Repository, :seed_helper do
before do before do
create_remote_branch('joe', 'remote_branch', 'master') create_remote_branch('joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master') repository.create_branch('local_branch')
end end
after do after do
......
...@@ -74,7 +74,7 @@ describe PushEvent do ...@@ -74,7 +74,7 @@ describe PushEvent do
create(:push_event_payload, event: event4, ref: 'baz', action: :removed) create(:push_event_payload, event: event4, ref: 'baz', action: :removed)
create(:push_event_payload, event: event5, ref: 'baz', ref_type: :tag) create(:push_event_payload, event: event5, ref: 'baz', ref_type: :tag)
project.repository.create_branch('bar', 'master') project.repository.create_branch('bar')
create( create(
:merge_request, :merge_request,
...@@ -83,7 +83,7 @@ describe PushEvent do ...@@ -83,7 +83,7 @@ describe PushEvent do
source_branch: 'bar' source_branch: 'bar'
) )
project.repository.create_branch('qux', 'master') project.repository.create_branch('qux')
create( create(
:merge_request, :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