Skip to content

Commit

Permalink
Move logic to set current directory before loading other config (#1848)
Browse files Browse the repository at this point in the history
Fixes #1843
  • Loading branch information
joshbode authored Mar 31, 2024
1 parent f37f11d commit 4113012
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,31 @@ impl Settings {
if let Some(settings) = SETTINGS.read().unwrap().as_ref() {
return Ok(settings.clone());
}

// Initial pass to obtain cd option
let mut sb = Self::builder()
.preloaded(CLI_SETTINGS.lock().unwrap().clone().unwrap_or_default())
.env();
for file in Self::all_settings_files() {
sb = sb.preloaded(file);
}
let mut settings = sb.preloaded(DEFAULT_SETTINGS.clone()).load()?;
if let Some(cd) = &settings.cd {

let mut settings = sb.load()?;
if let Some(mut cd) = settings.cd {
static ORIG_PATH: Lazy<std::io::Result<PathBuf>> = Lazy::new(env::current_dir);
let mut cd = PathBuf::from(cd);
if cd.is_relative() {
cd = ORIG_PATH.as_ref()?.join(cd);
}
env::set_current_dir(cd)?;
}

// Reload settings after current directory option processed
sb = Self::builder()
.preloaded(CLI_SETTINGS.lock().unwrap().clone().unwrap_or_default())
.env();
for file in Self::all_settings_files() {
sb = sb.preloaded(file);
}
sb = sb.preloaded(DEFAULT_SETTINGS.clone());

settings = sb.load()?;
if settings.raw {
settings.jobs = 1;
}
Expand Down

0 comments on commit 4113012

Please sign in to comment.