Commit d3f033d6 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-use-shell-writeref' into 'master'

Don't use rugged write-ref anymore

See merge request gitlab-org/gitlab-ce!23286
parents 124a0cab 67f2faa7
...@@ -425,7 +425,7 @@ group :ed25519 do ...@@ -425,7 +425,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.123.0', require: 'gitaly' gem 'gitaly-proto', '~> 1.1.0', require: 'gitaly'
gem 'grpc', '~> 1.15.0' gem 'grpc', '~> 1.15.0'
gem 'google-protobuf', '~> 3.6' gem 'google-protobuf', '~> 3.6'
......
...@@ -273,7 +273,7 @@ GEM ...@@ -273,7 +273,7 @@ GEM
gettext_i18n_rails (>= 0.7.1) gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gitaly-proto (0.123.0) gitaly-proto (1.1.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
gitlab-default_value_for (3.1.1) gitlab-default_value_for (3.1.1)
...@@ -1006,7 +1006,7 @@ DEPENDENCIES ...@@ -1006,7 +1006,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.123.0) gitaly-proto (~> 1.1.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
gitlab-default_value_for (~> 3.1.1) gitlab-default_value_for (~> 3.1.1)
gitlab-markup (~> 1.6.5) gitlab-markup (~> 1.6.5)
......
...@@ -272,7 +272,7 @@ GEM ...@@ -272,7 +272,7 @@ GEM
gettext_i18n_rails (>= 0.7.1) gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gitaly-proto (0.123.0) gitaly-proto (1.1.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
gitlab-markup (1.6.5) gitlab-markup (1.6.5)
...@@ -998,7 +998,7 @@ DEPENDENCIES ...@@ -998,7 +998,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.123.0) gitaly-proto (~> 1.1.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
gitlab-markup (~> 1.6.5) gitlab-markup (~> 1.6.5)
gitlab-sidekiq-fetcher gitlab-sidekiq-fetcher
......
...@@ -1394,7 +1394,7 @@ class Project < ActiveRecord::Base ...@@ -1394,7 +1394,7 @@ class Project < ActiveRecord::Base
def change_head(branch) def change_head(branch)
if repository.branch_exists?(branch) if repository.branch_exists?(branch)
repository.before_change_head 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.copy_gitattributes(branch)
repository.after_change_head repository.after_change_head
reload_default_branch reload_default_branch
......
...@@ -259,7 +259,7 @@ class Repository ...@@ -259,7 +259,7 @@ class Repository
next if kept_around?(sha) next if kept_around?(sha)
# This will still fail if the file is corrupted (e.g. 0 bytes) # 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 rescue Gitlab::Git::CommandError => ex
Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}"
end end
......
---
title: Avoid creating invalid refs using rugged, shelling out for writing refs
merge_request: 23286
author:
type: fixed
...@@ -723,11 +723,11 @@ module Gitlab ...@@ -723,11 +723,11 @@ module Gitlab
delete_refs(tmp_ref) delete_refs(tmp_ref)
end 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" ref_path = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{ref_path}" unless ref_path.start_with?("refs/") || ref_path == "HEAD"
wrapped_gitaly_errors do 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
end end
......
...@@ -251,20 +251,15 @@ module Gitlab ...@@ -251,20 +251,15 @@ module Gitlab
) )
end end
def write_ref(ref_path, ref, old_ref, shell) def write_ref(ref_path, ref, old_ref)
request = Gitaly::WriteRefRequest.new( request = Gitaly::WriteRefRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
ref: ref_path.b, ref: ref_path.b,
revision: ref.b, revision: ref.b
shell: shell
) )
request.old_revision = old_ref.b unless old_ref.nil? request.old_revision = old_ref.b unless old_ref.nil?
response = GitalyClient.call(@storage, :repository_service, :write_ref, request, timeout: GitalyClient.fast_timeout) GitalyClient.call(@storage, :repository_service, :write_ref, request, timeout: GitalyClient.fast_timeout)
raise Gitlab::Git::CommandError, encode!(response.error) if response.error.present?
true
end end
def set_config(entries) def set_config(entries)
......
...@@ -1469,6 +1469,19 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1469,6 +1469,19 @@ describe Gitlab::Git::Repository, :seed_helper do
end end
end 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 end
describe '#write_config' do describe '#write_config' do
......
...@@ -2203,12 +2203,6 @@ describe Project do ...@@ -2203,12 +2203,6 @@ describe Project do
project.change_head(project.default_branch) project.change_head(project.default_branch)
end 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 it 'copies the gitattributes' do
expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch) expect(project.repository).to receive(:copy_gitattributes).with(project.default_branch)
project.change_head(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