From ca003a81d1fadc387daf92038f41c30e6b0c60ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Sun, 3 May 2026 01:58:44 +0200 Subject: [PATCH] Use BUNDLE_PATH instead of rewriting bundler path config --- crates/rb-cli/src/commands/exec.rs | 7 ++++ crates/rb-core/src/bundler/mod.rs | 43 ----------------------- crates/rb-core/src/butler/mod.rs | 4 +++ spec/commands/sync_spec.sh | 10 ++++++ tests/commands/Sync.Integration.Tests.ps1 | 26 ++++++++++++++ 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/crates/rb-cli/src/commands/exec.rs b/crates/rb-cli/src/commands/exec.rs index 9c22520..26b1b44 100644 --- a/crates/rb-cli/src/commands/exec.rs +++ b/crates/rb-cli/src/commands/exec.rs @@ -127,6 +127,7 @@ mod tests { assert!(!env_vars.contains_key("BUNDLE_GEMFILE")); assert!(!env_vars.contains_key("BUNDLE_APP_CONFIG")); + assert!(!env_vars.contains_key("BUNDLE_PATH")); } #[test] @@ -177,11 +178,17 @@ mod tests { assert!(env_vars.contains_key("BUNDLE_GEMFILE")); assert!(env_vars.contains_key("BUNDLE_APP_CONFIG")); + assert!(env_vars.contains_key("BUNDLE_PATH")); let bundle_gemfile = env_vars.get("BUNDLE_GEMFILE").unwrap(); assert!(bundle_gemfile.contains("Gemfile")); let bundle_app_config = env_vars.get("BUNDLE_APP_CONFIG").unwrap(); assert!(bundle_app_config.contains(".rb")); + + let bundle_path = env_vars.get("BUNDLE_PATH").unwrap(); + assert!(bundle_path.contains(".rb")); + assert!(bundle_path.contains("vendor")); + assert!(bundle_path.contains("bundler")); } } diff --git a/crates/rb-core/src/bundler/mod.rs b/crates/rb-core/src/bundler/mod.rs index 35b0876..cdaf0d9 100644 --- a/crates/rb-core/src/bundler/mod.rs +++ b/crates/rb-core/src/bundler/mod.rs @@ -84,8 +84,6 @@ impl BundlerRuntime { ) -> std::io::Result { debug!("Checking bundle synchronization status"); - self.configure_local_path(butler_runtime)?; - let output = Command::new("bundle") .arg("check") .current_dir(&self.root) @@ -120,47 +118,6 @@ impl BundlerRuntime { } } - /// Configure bundler to use local vendor directory - pub fn configure_local_path( - &self, - butler_runtime: &crate::butler::ButlerRuntime, - ) -> std::io::Result<()> { - debug!( - "Configuring bundle path to vendor directory: {}", - self.vendor_dir().display() - ); - - let status = Command::new("bundle") - .args(["config", "set", "path", "--local"]) - .arg(self.vendor_dir().to_string_lossy().as_ref()) - .current_dir(&self.root) - .status_with_context(butler_runtime); - - match status { - Ok(status) => { - if status.success() { - debug!("Successfully configured bundle path"); - Ok(()) - } else { - Err(std::io::Error::other(format!( - "Failed to configure bundle path (exit code: {})", - status.code().unwrap_or(-1) - ))) - } - } - Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound { - Err(std::io::Error::new( - std::io::ErrorKind::NotFound, - "Bundler executable not found. Please install bundler with: gem install bundler", - )) - } else { - Err(e) - } - } - } - } - pub fn install_dependencies( &self, butler_runtime: &crate::butler::ButlerRuntime, diff --git a/crates/rb-core/src/butler/mod.rs b/crates/rb-core/src/butler/mod.rs index b18ae94..f9914a8 100644 --- a/crates/rb-core/src/butler/mod.rs +++ b/crates/rb-core/src/butler/mod.rs @@ -618,6 +618,7 @@ impl ButlerRuntime { if let Some(bundler_runtime) = &self.bundler_runtime { let gemfile_path = bundler_runtime.gemfile_path(); let app_config_dir = bundler_runtime.app_config_dir(); + let vendor_dir = bundler_runtime.vendor_dir(); debug!("Setting BUNDLE_GEMFILE: {}", gemfile_path.display()); env.insert( @@ -630,6 +631,9 @@ impl ButlerRuntime { "BUNDLE_APP_CONFIG".to_string(), app_config_dir.display().to_string(), ); + + debug!("Setting BUNDLE_PATH: {}", vendor_dir.display()); + env.insert("BUNDLE_PATH".to_string(), vendor_dir.display().to_string()); } else { debug!("No bundler runtime detected - skipping bundler environment variables"); } diff --git a/spec/commands/sync_spec.sh b/spec/commands/sync_spec.sh index 115da41..0737c47 100644 --- a/spec/commands/sync_spec.sh +++ b/spec/commands/sync_spec.sh @@ -24,6 +24,16 @@ Describe 'rb sync command' The output should include "Environment Successfully Synchronized" The stderr should not include "[DEPRECATED]" End + + It 'does not warn when checking an already synchronized bundle' + rb -R "$RUBIES_DIR" sync >/dev/null 2>&1 || fail "initial sync should succeed" + + When run rb -R "$RUBIES_DIR" x bundle check + The status should be success + The output should include "The Gemfile's dependencies are satisfied" + The output should not include "You are replacing the current local value of path" + The stderr should not include "You are replacing the current local value of path" + End End Context 'when running sync in non-bundler project' diff --git a/tests/commands/Sync.Integration.Tests.ps1 b/tests/commands/Sync.Integration.Tests.ps1 index d406c8e..a246f4c 100644 --- a/tests/commands/Sync.Integration.Tests.ps1 +++ b/tests/commands/Sync.Integration.Tests.ps1 @@ -77,6 +77,32 @@ gem 'rake' Pop-Location } } + + It "Does not warn when checking an already synchronized bundle" { + $TestSubDir = Join-Path $Script:TestDir "test-recheck-$(Get-Random)" + New-Item -ItemType Directory -Path $TestSubDir -Force | Out-Null + + @" +source 'https://rubygems.org' +gem 'rake' +"@ | Set-Content -Path (Join-Path $TestSubDir "Gemfile") + + Push-Location $TestSubDir + try { + $InitialOutput = & $Script:RbPath sync 2>&1 + if ($LASTEXITCODE -ne 0) { + throw "Initial sync failed. Exit code: $LASTEXITCODE. Output: $($InitialOutput -join "`n")" + } + + $Output = & $Script:RbPath x bundle check 2>&1 + + $LASTEXITCODE | Should -Be 0 + ($Output -join " ") | Should -Match "The Gemfile's dependencies are satisfied" + ($Output -join " ") | Should -Not -Match "You are replacing the current local value of path" + } finally { + Pop-Location + } + } } Context "Sync in Non-Bundler Project" {