Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry a full clone when git server does not support shallow capabilities #7649

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions bundler/lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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)
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)
end
end
Expand Down
14 changes: 14 additions & 0 deletions bundler/spec/bundler/source/git/git_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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