summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-04-05 09:30:20 +0200
committerRémy Coutable <remy@rymai.me>2017-04-10 16:10:18 +0200
commitcb20cfa244db896b87d2fb8b6ccad5b9f0713298 (patch)
tree3aedf108aff72587bb6e70206dfe0adade3a0783
parent710cd82cc16a9c67458c72ea6b2c4b676234ef79 (diff)
downloadgitlab-ce-cb20cfa244db896b87d2fb8b6ccad5b9f0713298.tar.gz
Retrieve Git-specific env in Gitlab::Git::Repository#rugged
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--lib/gitlab/git/repository.rb10
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb30
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index fc473b2c21e..41ab73abb56 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -8,6 +8,10 @@ module Gitlab
class Repository
include Gitlab::Git::Popen
+ ALLOWED_OBJECT_DIRECTORIES_VARIABLES = %w[
+ GIT_OBJECT_DIRECTORY
+ GIT_ALTERNATE_OBJECT_DIRECTORIES
+ ].freeze
SEARCH_CONTEXT_LINES = 3
NoRepository = Class.new(StandardError)
@@ -58,7 +62,7 @@ module Gitlab
end
def rugged
- @rugged ||= Rugged::Repository.new(path)
+ @rugged ||= Rugged::Repository.new(path, alternates: alternate_object_directories)
rescue Rugged::RepositoryError, Rugged::OSError
raise NoRepository.new('no repository for such path')
end
@@ -978,6 +982,10 @@ module Gitlab
private
+ def alternate_object_directories
+ Gitlab::Git::Env.all.values_at(*ALLOWED_OBJECT_DIRECTORIES_VARIABLES).compact
+ end
+
# Get the content of a blob for a given commit. If the blob is a commit
# (for submodules) then return the blob's OID.
def blob_content(commit, blob_name)
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 7e8bb796e03..690f604db5e 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -40,6 +40,36 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
+ describe "#rugged" do
+ context 'with no Git env stored' do
+ before do
+ expect(Gitlab::Git::Env).to receive(:all).and_return({})
+ end
+
+ it "whitelist some variables and pass them via the alternates keyword argument" do
+ expect(Rugged::Repository).to receive(:new).with(repository.path, alternates: [])
+
+ repository.rugged
+ end
+ end
+
+ context 'with some Git env stored' do
+ before do
+ expect(Gitlab::Git::Env).to receive(:all).and_return({
+ 'GIT_OBJECT_DIRECTORY' => 'foo',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES' => 'bar',
+ 'GIT_OTHER' => 'another_env'
+ })
+ end
+
+ it "whitelist some variables and pass them via the alternates keyword argument" do
+ expect(Rugged::Repository).to receive(:new).with(repository.path, alternates: %w[foo bar])
+
+ repository.rugged
+ end
+ end
+ end
+
describe "#discover_default_branch" do
let(:master) { 'master' }
let(:feature) { 'feature' }