|
9 | 9 | let(:options) { { "ref" => ref, "branch" => branch, "tag" => tag }.compact } |
10 | 10 | let(:revision) { nil } |
11 | 11 | let(:git_source) { nil } |
12 | | - let(:clone_result) { double(Process::Status, success?: true) } |
| 12 | + let(:success_result) { double(Process::Status, success?: true) } |
13 | 13 | 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"] } |
14 | 16 | subject(:git_proxy) { described_class.new(path, uri, options, revision, git_source) } |
15 | 17 |
|
| 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 | + |
16 | 23 | context "with explicit ref" do |
17 | 24 | context "with branch only" do |
18 | 25 | let(:branch) { "main" } |
|
64 | 71 | it "adds username and password to URI" do |
65 | 72 | Bundler.settings.temporary(uri => "u:p") do |
66 | 73 | 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]) |
68 | 75 | subject.checkout |
69 | 76 | end |
70 | 77 | end |
71 | 78 |
|
72 | 79 | it "adds username and password to URI for host" do |
73 | 80 | Bundler.settings.temporary("github.com" => "u:p") do |
74 | 81 | 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]) |
76 | 83 | subject.checkout |
77 | 84 | end |
78 | 85 | end |
79 | 86 |
|
80 | 87 | it "does not add username and password to mismatched URI" do |
81 | 88 | Bundler.settings.temporary("https://u:p@github.com/ruby/rubygems-mismatch.git" => "u:p") do |
82 | 89 | 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]) |
84 | 91 | subject.checkout |
85 | 92 | end |
86 | 93 | end |
|
90 | 97 | original = "https://orig:info@github.com/ruby/rubygems.git" |
91 | 98 | git_proxy = described_class.new(Pathname("path"), original, options) |
92 | 99 | 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]) |
94 | 101 | git_proxy.checkout |
95 | 102 | end |
96 | 103 | end |
|
198 | 205 | expect(Pathname.new(bundled_app("canary"))).not_to exist |
199 | 206 | end |
200 | 207 |
|
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 | | - |
215 | 208 | describe "#installed_to?" do |
216 | 209 | let(:destination) { "install/dir" } |
217 | 210 | let(:destination_dir_exists) { true } |
|
261 | 254 |
|
262 | 255 | it "clones the repository" do |
263 | 256 | 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]) |
265 | 258 | subject.checkout |
266 | 259 | 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 |
267 | 272 | end |
268 | 273 |
|
269 | 274 | context "when the repository is cloned" do |
|
286 | 291 | it "fetches the specific revision" do |
287 | 292 | allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
288 | 293 | 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]) |
290 | 295 | subject.checkout |
291 | 296 | end |
292 | 297 | end |
|
297 | 302 | parsed_revision = Digest::SHA1.hexdigest("ruby") |
298 | 303 | allow(git_proxy).to receive(:git_local).with("rev-parse", "--abbrev-ref", "HEAD", dir: path).and_return(parsed_revision) |
299 | 304 | 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]) |
301 | 306 | subject.checkout |
302 | 307 | end |
303 | 308 | end |
|
317 | 322 | it "fetches the specific revision" do |
318 | 323 | allow(git_proxy).to receive(:git_local).with("--version").and_return("git version 2.14.0") |
319 | 324 | 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]) |
321 | 326 | subject.checkout |
322 | 327 | end |
323 | 328 | end |
|
328 | 333 |
|
329 | 334 | it "fetches all revisions" do |
330 | 335 | 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 | + |
332 | 351 | subject.checkout |
333 | 352 | end |
334 | 353 | end |
|
0 commit comments