From 592a2fcd54510b04c1fb974758e33457f92218e3 Mon Sep 17 00:00:00 2001 From: Ellen Keal Date: Fri, 10 May 2024 15:26:41 -0500 Subject: [PATCH 1/2] fix for gems not downloading from git via http --- bundler/lib/bundler/source/git/git_proxy.rb | 8 ++++++++ bundler/spec/bundler/source/git/git_proxy_spec.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/bundler/lib/bundler/source/git/git_proxy.rb b/bundler/lib/bundler/source/git/git_proxy.rb index 645851286cda..f89e465c07db 100644 --- a/bundler/lib/bundler/source/git/git_proxy.rb +++ b/bundler/lib/bundler/source/git/git_proxy.rb @@ -181,6 +181,14 @@ def clone_needs_extra_fetch? if err.include?("Could not find remote branch") raise MissingGitRevisionError.new(command_with_no_credentials, nil, explicit_ref, credential_filtered_uri) + elsif err.include?("dumb http transport does not support shallow capabilities") + idx = command.index("--depth") + if idx + command.delete_at(idx) + command.delete_at(idx) + err += "Retrying without --depth argument." + end + raise GitCommandError.new(command_with_no_credentials, path, err) else raise GitCommandError.new(command_with_no_credentials, path, err) end diff --git a/bundler/spec/bundler/source/git/git_proxy_spec.rb b/bundler/spec/bundler/source/git/git_proxy_spec.rb index 1450316d59bd..f7c883eed4b5 100644 --- a/bundler/spec/bundler/source/git/git_proxy_spec.rb +++ b/bundler/spec/bundler/source/git/git_proxy_spec.rb @@ -197,4 +197,18 @@ expect(Pathname.new(bundled_app("canary"))).not_to exist end + + context "URI is HTTP" do + let(:uri) { "http://github.com/rubygems/rubygems.git" } + let(:without_depth_arguments) { ["clone", "--bare", "--no-hardlinks", "--quiet", "--no-tags", "--single-branch"] } + let(:fail_clone_result) { double(Process::Status, success?: false) } + + it "retries without --depth when git url is http and fails" do + allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") + allow(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "dumb http transport does not support shallow capabilities", fail_clone_result]) + expect(git_proxy).to receive(:capture).with([*without_depth_arguments, "--", uri, path.to_s], nil).and_return(["", "", clone_result]) + + subject.checkout + end + end end From 022eb473f8d28ad6052afcefa7429b0c77dbd121 Mon Sep 17 00:00:00 2001 From: Ellen Keal Date: Mon, 13 May 2024 16:49:56 -0500 Subject: [PATCH 2/2] move git clone depth error handling to else branch --- bundler/lib/bundler/source/git/git_proxy.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundler/lib/bundler/source/git/git_proxy.rb b/bundler/lib/bundler/source/git/git_proxy.rb index f89e465c07db..2fc9c6535f0f 100644 --- a/bundler/lib/bundler/source/git/git_proxy.rb +++ b/bundler/lib/bundler/source/git/git_proxy.rb @@ -181,16 +181,16 @@ def clone_needs_extra_fetch? if err.include?("Could not find remote branch") raise MissingGitRevisionError.new(command_with_no_credentials, nil, explicit_ref, credential_filtered_uri) - elsif err.include?("dumb http transport does not support shallow capabilities") + else idx = command.index("--depth") if idx command.delete_at(idx) command.delete_at(idx) + command_with_no_credentials = check_allowed(command) + err += "Retrying without --depth argument." end raise GitCommandError.new(command_with_no_credentials, path, err) - else - raise GitCommandError.new(command_with_no_credentials, path, err) end end end