Commit d7e95d77 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Use with_repo_branch_commit instead of fetch_ref directly

So that we could limit the access to Repository#fetch_ref
See: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13416#note_37487433
parent d1b4770d
...@@ -940,14 +940,13 @@ class MergeRequest < ActiveRecord::Base ...@@ -940,14 +940,13 @@ class MergeRequest < ActiveRecord::Base
private private
def write_ref def write_ref
if for_fork? target_project.repository.with_repo_branch_commit(
target_project.repository.fetch_ref( source_project.repository, source_branch) do |commit|
source_project.repository.path_to_repo, if commit
"refs/heads/#{source_branch}", target_project.repository.write_ref(ref_path, commit.sha)
ref_path
)
else else
source_project.repository.write_ref(ref_path, source_branch_sha) raise Rugged::ReferenceError, 'source repository is empty'
end
end end
end end
end end
...@@ -583,8 +583,7 @@ describe API::MergeRequests do ...@@ -583,8 +583,7 @@ describe API::MergeRequests do
before do before do
fork_project.add_reporter(user2) fork_project.add_reporter(user2)
allow_any_instance_of(Repository).to receive(:fetch_ref) # for forks allow_any_instance_of(MergeRequest).to receive(:write_ref)
allow_any_instance_of(Repository).to receive(:write_ref) # for non-forks
end end
it "returns merge_request" do it "returns merge_request" do
......
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