Skip to content

Commit 9cf802a

Browse files
committed
fixes #9001 - dumb http git support for bundler update fixed...
...by a little code duplication; specs are somewhat improved though
1 parent ff9c659 commit 9cf802a

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

bundler/lib/bundler/source/git/git_proxy.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ def git_remote_fetch(args)
166166
if err.include?("couldn't find remote ref") || err.include?("not our ref")
167167
raise MissingGitRevisionError.new(command_with_no_credentials, path, commit || explicit_ref, credential_filtered_uri)
168168
else
169+
idx = command.index("--depth")
170+
if idx
171+
command.delete_at(idx)
172+
command.delete_at(idx)
173+
command_with_no_credentials = check_allowed(command)
174+
175+
err += "Retrying without --depth argument."
176+
end
169177
raise GitCommandError.new(command_with_no_credentials, path, err)
170178
end
171179
end

bundler/spec/bundler/source/git/git_proxy_spec.rb

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
let(:options) { { "ref" => ref, "branch" => branch, "tag" => tag }.compact }
1010
let(:revision) { nil }
1111
let(:git_source) { nil }
12-
let(:clone_result) { double(Process::Status, success?: true) }
12+
let(:success_result) { double(Process::Status, success?: true) }
1313
let(:base_clone_args) { ["clone", "--bare", "--no-hardlinks", "--quiet", "--no-tags", "--depth", "1", "--single-branch"] }
14+
let(:failure_result) { double(Process::Status, success?: false) }
15+
let(:base_fetch_args) { ["fetch", "--force", "--quiet", "--no-tags", "--depth", "1"] }
1416
subject(:git_proxy) { described_class.new(path, uri, options, revision, git_source) }
1517

18+
def args_without_depth(args)
19+
depth_arg_i = args.index("--depth")
20+
args[0..(depth_arg_i - 1)] + args[(depth_arg_i + 2)..-1]
21+
end
22+
1623
context "with explicit ref" do
1724
context "with branch only" do
1825
let(:branch) { "main" }
@@ -64,23 +71,23 @@
6471
it "adds username and password to URI" do
6572
Bundler.settings.temporary(uri => "u:p") do
6673
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
67-
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", "https://u:p@github.com/ruby/rubygems.git", path.to_s], nil).and_return(["", "", clone_result])
74+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", "https://u:p@github.com/ruby/rubygems.git", path.to_s], nil).and_return(["", "", success_result])
6875
subject.checkout
6976
end
7077
end
7178

7279
it "adds username and password to URI for host" do
7380
Bundler.settings.temporary("github.com" => "u:p") do
7481
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
75-
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", "https://u:p@github.com/ruby/rubygems.git", path.to_s], nil).and_return(["", "", clone_result])
82+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", "https://u:p@github.com/ruby/rubygems.git", path.to_s], nil).and_return(["", "", success_result])
7683
subject.checkout
7784
end
7885
end
7986

8087
it "does not add username and password to mismatched URI" do
8188
Bundler.settings.temporary("https://u:p@github.com/ruby/rubygems-mismatch.git" => "u:p") do
8289
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
83-
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", clone_result])
90+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", success_result])
8491
subject.checkout
8592
end
8693
end
@@ -90,7 +97,7 @@
9097
original = "https://orig:info@github.com/ruby/rubygems.git"
9198
git_proxy = described_class.new(Pathname("path"), original, options)
9299
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
93-
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", original, path.to_s], nil).and_return(["", "", clone_result])
100+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", original, path.to_s], nil).and_return(["", "", success_result])
94101
git_proxy.checkout
95102
end
96103
end
@@ -198,20 +205,6 @@
198205
expect(Pathname.new(bundled_app("canary"))).not_to exist
199206
end
200207

201-
context "URI is HTTP" do
202-
let(:uri) { "http://github.com/ruby/rubygems.git" }
203-
let(:without_depth_arguments) { ["clone", "--bare", "--no-hardlinks", "--quiet", "--no-tags", "--single-branch"] }
204-
let(:fail_clone_result) { double(Process::Status, success?: false) }
205-
206-
it "retries without --depth when git url is http and fails" do
207-
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
208-
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])
209-
expect(git_proxy).to receive(:capture).with([*without_depth_arguments, "--", uri, path.to_s], nil).and_return(["", "", clone_result])
210-
211-
subject.checkout
212-
end
213-
end
214-
215208
describe "#installed_to?" do
216209
let(:destination) { "install/dir" }
217210
let(:destination_dir_exists) { true }
@@ -261,9 +254,21 @@
261254

262255
it "clones the repository" do
263256
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
264-
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", clone_result])
257+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "", success_result])
265258
subject.checkout
266259
end
260+
261+
context "URI is HTTP" do
262+
let(:uri) { "http://git/rubygems/.git" }
263+
264+
it "retries without --depth when git url is http and fails" do
265+
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
266+
expect(git_proxy).to receive(:capture).with([*base_clone_args, "--", uri, path.to_s], nil).and_return(["", "dumb http transport does not support shallow capabilities", failure_result])
267+
expect(git_proxy).to receive(:capture).with([*args_without_depth(base_clone_args), "--", uri, path.to_s], nil).and_return(["", "", success_result])
268+
269+
subject.checkout
270+
end
271+
end
267272
end
268273

269274
context "when the repository is cloned" do
@@ -286,7 +291,7 @@
286291
it "fetches the specific revision" do
287292
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
288293
expect(git_proxy).to receive(:git).with("cat-file", "-e", revision, dir: path).and_raise(Bundler::GitError)
289-
expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--depth", "1", "--", uri, "#{revision}:refs/#{revision}-sha"], path).and_return(["", "", clone_result])
294+
expect(git_proxy).to receive(:capture).with([*base_fetch_args, "--", uri, "#{revision}:refs/#{revision}-sha"], path).and_return(["", "", success_result])
290295
subject.checkout
291296
end
292297
end
@@ -297,7 +302,7 @@
297302
parsed_revision = Digest::SHA1.hexdigest("ruby")
298303
allow(git_proxy).to receive(:git_local).with("rev-parse", "--abbrev-ref", "HEAD", dir: path).and_return(parsed_revision)
299304
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
300-
expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--depth", "1", "--", uri, "refs/heads/#{parsed_revision}:refs/heads/#{parsed_revision}"], path).and_return(["", "", clone_result])
305+
expect(git_proxy).to receive(:capture).with([*base_fetch_args, "--", uri, "refs/heads/#{parsed_revision}:refs/heads/#{parsed_revision}"], path).and_return(["", "", success_result])
301306
subject.checkout
302307
end
303308
end
@@ -317,7 +322,7 @@
317322
it "fetches the specific revision" do
318323
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
319324
expect(git_proxy).to receive(:git).with("cat-file", "-e", ref, dir: path).and_raise(Bundler::GitError)
320-
expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--depth", "1", "--", uri, "#{ref}:refs/#{ref}-sha"], path).and_return(["", "", clone_result])
325+
expect(git_proxy).to receive(:capture).with([*base_fetch_args, "--", uri, "#{ref}:refs/#{ref}-sha"], path).and_return(["", "", success_result])
321326
subject.checkout
322327
end
323328
end
@@ -328,7 +333,21 @@
328333

329334
it "fetches all revisions" do
330335
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
331-
expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--", uri, "refs/*:refs/*"], path).and_return(["", "", clone_result])
336+
expect(git_proxy).to receive(:capture).with(["fetch", "--force", "--quiet", "--no-tags", "--", uri, "refs/*:refs/*"], path).and_return(["", "", success_result])
337+
subject.checkout
338+
end
339+
end
340+
341+
context "URI is HTTP" do
342+
let(:uri) { "http://git/rubygems/.git" }
343+
344+
it "retries without --depth when git url is http and fails" do
345+
allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0")
346+
parsed_revision = Digest::SHA1.hexdigest("ruby")
347+
allow(git_proxy).to receive(:git_local).with("rev-parse", "--abbrev-ref", "HEAD", dir: path).and_return(parsed_revision)
348+
expect(git_proxy).to receive(:capture).with([*base_fetch_args, "--", uri, "refs/heads/#{parsed_revision}:refs/heads/#{parsed_revision}"], path).and_return(["", "dumb http transport does not support shallow capabilities", failure_result])
349+
expect(git_proxy).to receive(:capture).with([*args_without_depth(base_fetch_args), "--", uri, "refs/heads/#{parsed_revision}:refs/heads/#{parsed_revision}"], path).and_return(["", "", success_result])
350+
332351
subject.checkout
333352
end
334353
end

0 commit comments

Comments
 (0)