Commit 6ca24bd2 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/git-env-repo-paths' into 'master'

Use relative git object paths to construct absolute ones before setting Env

See merge request gitlab-org/gitlab-ce!15376
parents a1ddfbfb 52bfd064
...@@ -36,6 +36,18 @@ module API ...@@ -36,6 +36,18 @@ module API
{} {}
end end
def fix_git_env_repository_paths(env, repository_path)
if obj_dir_relative = env['GIT_OBJECT_DIRECTORY_RELATIVE'].presence
env['GIT_OBJECT_DIRECTORY'] = File.join(repository_path, obj_dir_relative)
end
if alt_obj_dirs_relative = env['GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE'].presence
env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = alt_obj_dirs_relative.map { |dir| File.join(repository_path, dir) }
end
env
end
def log_user_activity(actor) def log_user_activity(actor)
commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS
......
...@@ -19,7 +19,9 @@ module API ...@@ -19,7 +19,9 @@ module API
status 200 status 200
# Stores some Git-specific env thread-safely # Stores some Git-specific env thread-safely
Gitlab::Git::Env.set(parse_env) env = parse_env
env = fix_git_env_repository_paths(env, repository_path) if project
Gitlab::Git::Env.set(env)
actor = actor =
if params[:key_id] if params[:key_id]
......
...@@ -203,6 +203,7 @@ describe API::Internal do ...@@ -203,6 +203,7 @@ describe API::Internal do
end end
context 'with env passed as a JSON' do context 'with env passed as a JSON' do
context 'when relative path envs are not set' do
it 'sets env in RequestStore' do it 'sets env in RequestStore' do
expect(Gitlab::Git::Env).to receive(:set).with({ expect(Gitlab::Git::Env).to receive(:set).with({
'GIT_OBJECT_DIRECTORY' => 'foo', 'GIT_OBJECT_DIRECTORY' => 'foo',
...@@ -218,6 +219,31 @@ describe API::Internal do ...@@ -218,6 +219,31 @@ describe API::Internal do
end end
end end
context 'when relative path envs are set' do
it 'sets env in RequestStore' do
obj_dir_relative = './objects'
alt_obj_dirs_relative = ['./alt-objects-1', './alt-objects-2']
repo_path = project.wiki.repository.path_to_repo
expect(Gitlab::Git::Env).to receive(:set).with({
'GIT_OBJECT_DIRECTORY' => File.join(repo_path, obj_dir_relative),
'GIT_ALTERNATE_OBJECT_DIRECTORIES' => alt_obj_dirs_relative.map { |d| File.join(repo_path, d) },
'GIT_OBJECT_DIRECTORY_RELATIVE' => obj_dir_relative,
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => alt_obj_dirs_relative
})
push(key, project.wiki, env: {
GIT_OBJECT_DIRECTORY: 'foo',
GIT_ALTERNATE_OBJECT_DIRECTORIES: 'bar',
GIT_OBJECT_DIRECTORY_RELATIVE: obj_dir_relative,
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative
}.to_json)
expect(response).to have_gitlab_http_status(200)
end
end
end
context "git push with project.wiki" do context "git push with project.wiki" do
it 'responds with success' do it 'responds with success' do
push(key, project.wiki) push(key, project.wiki)
......
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