Skip to content

Commit ca003a8

Browse files
committed
Use BUNDLE_PATH instead of rewriting bundler path config
1 parent 1387d45 commit ca003a8

5 files changed

Lines changed: 47 additions & 43 deletions

File tree

crates/rb-cli/src/commands/exec.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ mod tests {
127127

128128
assert!(!env_vars.contains_key("BUNDLE_GEMFILE"));
129129
assert!(!env_vars.contains_key("BUNDLE_APP_CONFIG"));
130+
assert!(!env_vars.contains_key("BUNDLE_PATH"));
130131
}
131132

132133
#[test]
@@ -177,11 +178,17 @@ mod tests {
177178

178179
assert!(env_vars.contains_key("BUNDLE_GEMFILE"));
179180
assert!(env_vars.contains_key("BUNDLE_APP_CONFIG"));
181+
assert!(env_vars.contains_key("BUNDLE_PATH"));
180182

181183
let bundle_gemfile = env_vars.get("BUNDLE_GEMFILE").unwrap();
182184
assert!(bundle_gemfile.contains("Gemfile"));
183185

184186
let bundle_app_config = env_vars.get("BUNDLE_APP_CONFIG").unwrap();
185187
assert!(bundle_app_config.contains(".rb"));
188+
189+
let bundle_path = env_vars.get("BUNDLE_PATH").unwrap();
190+
assert!(bundle_path.contains(".rb"));
191+
assert!(bundle_path.contains("vendor"));
192+
assert!(bundle_path.contains("bundler"));
186193
}
187194
}

crates/rb-core/src/bundler/mod.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ impl BundlerRuntime {
8484
) -> std::io::Result<bool> {
8585
debug!("Checking bundle synchronization status");
8686

87-
self.configure_local_path(butler_runtime)?;
88-
8987
let output = Command::new("bundle")
9088
.arg("check")
9189
.current_dir(&self.root)
@@ -120,47 +118,6 @@ impl BundlerRuntime {
120118
}
121119
}
122120

123-
/// Configure bundler to use local vendor directory
124-
pub fn configure_local_path(
125-
&self,
126-
butler_runtime: &crate::butler::ButlerRuntime,
127-
) -> std::io::Result<()> {
128-
debug!(
129-
"Configuring bundle path to vendor directory: {}",
130-
self.vendor_dir().display()
131-
);
132-
133-
let status = Command::new("bundle")
134-
.args(["config", "set", "path", "--local"])
135-
.arg(self.vendor_dir().to_string_lossy().as_ref())
136-
.current_dir(&self.root)
137-
.status_with_context(butler_runtime);
138-
139-
match status {
140-
Ok(status) => {
141-
if status.success() {
142-
debug!("Successfully configured bundle path");
143-
Ok(())
144-
} else {
145-
Err(std::io::Error::other(format!(
146-
"Failed to configure bundle path (exit code: {})",
147-
status.code().unwrap_or(-1)
148-
)))
149-
}
150-
}
151-
Err(e) => {
152-
if e.kind() == std::io::ErrorKind::NotFound {
153-
Err(std::io::Error::new(
154-
std::io::ErrorKind::NotFound,
155-
"Bundler executable not found. Please install bundler with: gem install bundler",
156-
))
157-
} else {
158-
Err(e)
159-
}
160-
}
161-
}
162-
}
163-
164121
pub fn install_dependencies<F>(
165122
&self,
166123
butler_runtime: &crate::butler::ButlerRuntime,

crates/rb-core/src/butler/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ impl ButlerRuntime {
618618
if let Some(bundler_runtime) = &self.bundler_runtime {
619619
let gemfile_path = bundler_runtime.gemfile_path();
620620
let app_config_dir = bundler_runtime.app_config_dir();
621+
let vendor_dir = bundler_runtime.vendor_dir();
621622

622623
debug!("Setting BUNDLE_GEMFILE: {}", gemfile_path.display());
623624
env.insert(
@@ -630,6 +631,9 @@ impl ButlerRuntime {
630631
"BUNDLE_APP_CONFIG".to_string(),
631632
app_config_dir.display().to_string(),
632633
);
634+
635+
debug!("Setting BUNDLE_PATH: {}", vendor_dir.display());
636+
env.insert("BUNDLE_PATH".to_string(), vendor_dir.display().to_string());
633637
} else {
634638
debug!("No bundler runtime detected - skipping bundler environment variables");
635639
}

spec/commands/sync_spec.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Describe 'rb sync command'
2424
The output should include "Environment Successfully Synchronized"
2525
The stderr should not include "[DEPRECATED]"
2626
End
27+
28+
It 'does not warn when checking an already synchronized bundle'
29+
rb -R "$RUBIES_DIR" sync >/dev/null 2>&1 || fail "initial sync should succeed"
30+
31+
When run rb -R "$RUBIES_DIR" x bundle check
32+
The status should be success
33+
The output should include "The Gemfile's dependencies are satisfied"
34+
The output should not include "You are replacing the current local value of path"
35+
The stderr should not include "You are replacing the current local value of path"
36+
End
2737
End
2838

2939
Context 'when running sync in non-bundler project'

tests/commands/Sync.Integration.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ gem 'rake'
7777
Pop-Location
7878
}
7979
}
80+
81+
It "Does not warn when checking an already synchronized bundle" {
82+
$TestSubDir = Join-Path $Script:TestDir "test-recheck-$(Get-Random)"
83+
New-Item -ItemType Directory -Path $TestSubDir -Force | Out-Null
84+
85+
@"
86+
source 'https://rubygems.org'
87+
gem 'rake'
88+
"@ | Set-Content -Path (Join-Path $TestSubDir "Gemfile")
89+
90+
Push-Location $TestSubDir
91+
try {
92+
$InitialOutput = & $Script:RbPath sync 2>&1
93+
if ($LASTEXITCODE -ne 0) {
94+
throw "Initial sync failed. Exit code: $LASTEXITCODE. Output: $($InitialOutput -join "`n")"
95+
}
96+
97+
$Output = & $Script:RbPath x bundle check 2>&1
98+
99+
$LASTEXITCODE | Should -Be 0
100+
($Output -join " ") | Should -Match "The Gemfile's dependencies are satisfied"
101+
($Output -join " ") | Should -Not -Match "You are replacing the current local value of path"
102+
} finally {
103+
Pop-Location
104+
}
105+
}
80106
}
81107

82108
Context "Sync in Non-Bundler Project" {

0 commit comments

Comments
 (0)