Read about our upcoming Code of Conduct on this issue

Commit 106ff373 authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Don't specify `shell` for Gitaly write-ref

Use shelling out to git to write refs instead of rugged, hoping to
avoid creating invalid refs.

To update HEAD we switched to using `git symbolic-ref`.
parent 90bf54139f3b
......@@ -1394,7 +1394,7 @@ def visibility_level_field
def change_head(branch)
if repository.branch_exists?(branch)
repository.before_change_head
repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}", shell: false)
repository.raw_repository.write_ref('HEAD', "refs/heads/#{branch}")
repository.copy_gitattributes(branch)
repository.after_change_head
reload_default_branch
......
......@@ -259,7 +259,7 @@ def keep_around(*shas)
next if kept_around?(sha)
# This will still fail if the file is corrupted (e.g. 0 bytes)
raw_repository.write_ref(keep_around_ref_name(sha), sha, shell: false)
raw_repository.write_ref(keep_around_ref_name(sha), sha)
rescue Gitlab::Git::CommandError => ex
Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}"
end
......
---
title: Avoid creating invalid refs using rugged, shelling out for writing refs
merge_request: 23286
author:
type: fixed
......@@ -723,11 +723,11 @@ def compare_source_branch(target_branch_name, source_repository, source_branch_n
delete_refs(tmp_ref)
end
def write_ref(ref_path, ref, old_ref: nil, shell: true)
def write_ref(ref_path, ref, old_ref: nil)
ref_path = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{ref_path}" unless ref_path.start_with?("refs/") || ref_path == "HEAD"
wrapped_gitaly_errors do
gitaly_repository_client.write_ref(ref_path, ref, old_ref, shell)
gitaly_repository_client.write_ref(ref_path, ref, old_ref)
end
end
......
......@@ -251,12 +251,11 @@ def create_from_snapshot(http_url, http_auth)
)
end
def write_ref(ref_path, ref, old_ref, shell)
def write_ref(ref_path, ref, old_ref)
request = Gitaly::WriteRefRequest.new(
repository: @gitaly_repo,
ref: ref_path.b,
revision: ref.b,
shell: shell
revision: ref.b
)
request.old_revision = old_ref.b unless old_ref.nil?
......
......@@ -1469,6 +1469,19 @@ def commit_files(commit)
end
end
end
it 'writes the HEAD' do
repository.write_ref('HEAD', 'refs/heads/feature')
expect(repository.commit('HEAD')).to eq(repository.commit('feature'))
expect(repository.root_ref).to eq('feature')
end
it 'writes other refs' do
repository.write_ref('refs/heads/feature', SeedRepo::Commit::ID)
expect(repository.commit('feature').sha).to eq(SeedRepo::Commit::ID)
end
end
describe '#write_config' do
......
......@@ -2203,12 +2203,6 @@ def create_build(new_pipeline = pipeline, name = 'test')
project.change_head(project.default_branch)
end
it 'creates the new reference with rugged' do
expect(project.repository.raw_repository).to receive(:write_ref).with('HEAD', "refs/heads/#{project.default_branch}", shell: false)
project.change_head(project.default_branch)
end
it 'copies the gitattributes' do
expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch)
project.change_head(project.default_branch)
......
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