diff options
author | Kerri Miller <kerrizor@kerrizor.com> | 2019-07-03 21:46:31 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2019-07-26 15:06:29 +0300 |
commit | 3394c14bc8acc00b475963827f100341f9a58e9f (patch) | |
tree | 06e0fcb6b0593e20ea4a279a77952984a01e62df | |
parent | 3af6f5daf3c0681d486a004b634758680b39f4b0 (diff) |
Add http.followRedirects directive to `git fetch` command
WIP
-rw-r--r-- | ruby/lib/gitlab/git/gitlab_projects.rb | 8 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/gitlab_projects_spec.rb | 22 |
2 files changed, 21 insertions, 9 deletions
diff --git a/ruby/lib/gitlab/git/gitlab_projects.rb b/ruby/lib/gitlab/git/gitlab_projects.rb index b02cdc5ec..f56c7b1d7 100644 --- a/ruby/lib/gitlab/git/gitlab_projects.rb +++ b/ruby/lib/gitlab/git/gitlab_projects.rb @@ -57,9 +57,9 @@ module Gitlab end end - def fetch_remote(name, timeout, force:, tags:, env: {}, prune: true) + def fetch_remote(name, timeout, force:, tags:, env: {}, prune: true, follow_redirects: false) logger.info "Fetching remote #{name} for repository #{repository_absolute_path}." - cmd = fetch_remote_command(name, tags, prune, force) + cmd = fetch_remote_command(name, tags, prune, force, follow_redirects) run_with_timeout(cmd, timeout, repository_absolute_path, env).tap do |success| logger.error "Fetching remote #{name} for repository #{repository_absolute_path} failed." unless success @@ -119,8 +119,8 @@ module Gitlab private - def fetch_remote_command(name, tags, prune, force) - %W(#{Gitlab.config.git.bin_path} fetch #{name} --quiet).tap do |cmd| + def fetch_remote_command(name, tags, prune, force, follow_redirects) + %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=#{follow_redirects} fetch #{name} --quiet).tap do |cmd| cmd << '--prune' if prune cmd << '--force' if force cmd << (tags ? '--tags' : '--no-tags') diff --git a/ruby/spec/lib/gitlab/git/gitlab_projects_spec.rb b/ruby/spec/lib/gitlab/git/gitlab_projects_spec.rb index 391a4b76a..211e6533a 100644 --- a/ruby/spec/lib/gitlab/git/gitlab_projects_spec.rb +++ b/ruby/spec/lib/gitlab/git/gitlab_projects_spec.rb @@ -94,8 +94,9 @@ describe Gitlab::Git::GitlabProjects do let(:tags) { true } let(:env) { { 'GIT_SSH_COMMAND' => 'foo-command bar' } } let(:prune) { true } - let(:args) { { force: force, tags: tags, env: env, prune: prune } } - let(:cmd) { %W(#{Gitlab.config.git.bin_path} fetch #{remote_name} --quiet --prune --tags) } + let(:follow_redirects) { false } + let(:args) { { force: force, tags: tags, env: env, prune: prune, follow_redirects: follow_redirects } } + let(:cmd) { %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=false fetch #{remote_name} --quiet --prune --tags) } subject { gl_projects.fetch_remote(remote_name, 600, args) } @@ -115,7 +116,7 @@ describe Gitlab::Git::GitlabProjects do context 'with --force' do let(:force) { true } - let(:cmd) { %W(#{Gitlab.config.git.bin_path} fetch #{remote_name} --quiet --prune --force --tags) } + let(:cmd) { %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=false fetch #{remote_name} --quiet --prune --force --tags) } it 'executes the command with forced option' do stub_spawn(cmd, 600, tmp_repo_path, env, success: true) @@ -126,7 +127,7 @@ describe Gitlab::Git::GitlabProjects do context 'with --no-tags' do let(:tags) { false } - let(:cmd) { %W(#{Gitlab.config.git.bin_path} fetch #{remote_name} --quiet --prune --no-tags) } + let(:cmd) { %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=false fetch #{remote_name} --quiet --prune --no-tags) } it 'executes the command' do stub_spawn(cmd, 600, tmp_repo_path, env, success: true) @@ -137,7 +138,18 @@ describe Gitlab::Git::GitlabProjects do context 'with no prune' do let(:prune) { false } - let(:cmd) { %W(#{Gitlab.config.git.bin_path} fetch #{remote_name} --quiet --tags) } + let(:cmd) { %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=false fetch #{remote_name} --quiet --tags) } + + it 'executes the command' do + stub_spawn(cmd, 600, tmp_repo_path, env, success: true) + + is_expected.to be_truthy + end + end + + context 'with follow_redirects = true' do + let(:follow_redirects) { true } + let(:cmd) { %W(#{Gitlab.config.git.bin_path} -c http.followRedirects=true fetch #{remote_name} --quiet --prune --tags) } it 'executes the command' do stub_spawn(cmd, 600, tmp_repo_path, env, success: true) |