From 2cd7b924036963b2f4230a3cae7c9ac63c7851a9 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 31 Oct 2024 10:53:02 -0400 Subject: [PATCH] Prevent composed bundle from failing with SSH git sources (#2810) --- lib/ruby_lsp/setup_bundler.rb | 3 +++ test/setup_bundler_test.rb | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 316820a8d..769dfe757 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -359,6 +359,9 @@ def correct_relative_remote_paths else match end + rescue URI::InvalidURIError, URI::InvalidComponentError + # If the path raises an invalid error, it might be a git ssh path, which indeed isn't a URI + match end @custom_lockfile.write(content) diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index 823c58f78..a9a3793dc 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -739,6 +739,53 @@ def test_progress_is_printed_to_stderr end end + def test_succeeds_when_using_ssh_git_sources_instead_of_https + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + File.write(File.join(dir, "Gemfile"), <<~GEMFILE) + source "https://rubygems.org" + gem "rbi", git: "git@github.com:Shopify/rbi.git", branch: "main" + GEMFILE + + File.write(File.join(dir, "Gemfile.lock"), <<~LOCKFILE) + GIT + remote: git@github.com:Shopify/rbi.git + revision: d2e59a207c0b2f07d9bbaf1eb4b6d2500a4782ea + branch: main + specs: + rbi (0.2.1) + prism (~> 1.0) + sorbet-runtime (>= 0.5.9204) + + GEM + remote: https://rubygems.org/ + specs: + prism (1.2.0) + sorbet-runtime (0.5.11630) + + PLATFORMS + arm64-darwin-23 + ruby + + DEPENDENCIES + rbi! + + BUNDLED WITH + 2.5.22 + LOCKFILE + + Bundler.with_unbundled_env do + capture_subprocess_io do + stub_bundle_with_env(bundle_env(dir, ".ruby-lsp/Gemfile")) + run_script(dir) + end + end + + assert_match("remote: git@github.com:Shopify/rbi.git", File.read(".ruby-lsp/Gemfile.lock")) + end + end + end + private def with_default_external_encoding(encoding, &block)