diff --git a/crates/turborepo-lib/src/commands/mod.rs b/crates/turborepo-lib/src/commands/mod.rs index 782ae9b5117c9..a353914d19a67 100644 --- a/crates/turborepo-lib/src/commands/mod.rs +++ b/crates/turborepo-lib/src/commands/mod.rs @@ -74,18 +74,6 @@ impl CommandBase { Ok(self.repo_config.get_mut().unwrap()) } - // NOTE: This deletes the repo config file. It does *not* remove the - // `RepoConfig` struct from `CommandBase`. This is fine because we - // currently do not have any commands that delete the repo config file - // and then attempt to read from it. - pub fn delete_repo_config_file(&mut self) -> Result<()> { - let repo_config_path = get_repo_config_path(self.repo_root.borrow()); - if repo_config_path.exists() { - std::fs::remove_file(repo_config_path)?; - } - Ok(()) - } - fn user_config_init(&self) -> Result { UserConfigLoader::new(default_user_config_path()?) .with_token(self.args.token.clone()) diff --git a/crates/turborepo-lib/src/commands/unlink.rs b/crates/turborepo-lib/src/commands/unlink.rs index cfaddbf030fd2..50cfc80895e2e 100644 --- a/crates/turborepo-lib/src/commands/unlink.rs +++ b/crates/turborepo-lib/src/commands/unlink.rs @@ -11,32 +11,41 @@ enum UnlinkSpacesResult { } fn unlink_remote_caching(base: &mut CommandBase) -> Result<()> { - base.delete_repo_config_file() - .context("could not unlink. Something went wrong")?; + let repo_config: &mut crate::config::RepoConfig = base.repo_config_mut()?; + let needs_disabling = repo_config.team_id().is_some() || repo_config.team_slug().is_some(); - println!( - "{}", - base.ui.apply(GREY.apply_to("> Disabled Remote Caching")) - ); + let output = if needs_disabling { + repo_config.set_team_id(None)?; + "> Disabled Remote Caching" + } else { + "> No Remote Caching config found" + }; + + println!("{}", base.ui.apply(GREY.apply_to(output))); Ok(()) } fn unlink_spaces(base: &mut CommandBase) -> Result<()> { + let repo_config: &mut crate::config::RepoConfig = base.repo_config_mut()?; + let needs_disabling = + repo_config.space_team_id().is_some() || repo_config.space_team_slug().is_some(); + + if needs_disabling { + repo_config.set_space_team_id(None)?; + } + + // Space config is _also_ in turbo.json. let result = remove_spaces_from_turbo_json(base).context("could not unlink. Something went wrong")?; - match result { - UnlinkSpacesResult::Unlinked => { - println!("{}", base.ui.apply(GREY.apply_to("> Unlinked Spaces"))); - } - UnlinkSpacesResult::NoSpacesFound => { - println!( - "{}", - base.ui.apply(GREY.apply_to("> No Spaces config found")) - ); - } - } + let output = match (needs_disabling, result) { + (_, UnlinkSpacesResult::Unlinked) => "> Unlinked Spaces", + (true, _) => "> Unlinked Spaces", + (false, UnlinkSpacesResult::NoSpacesFound) => "> No Spaces config found", + }; + + println!("{}", base.ui.apply(GREY.apply_to(output))); Ok(()) }