Retrieve Git-specific env in Gitlab::Git::Repository#rugged
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
710cd82cc1
commit
cb20cfa244
2 changed files with 39 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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' }
|
||||
|
|
Loading…
Reference in a new issue