diff --git a/src/main.rs b/src/main.rs index a43ee919..523fc342 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,6 +79,12 @@ fn main() -> Result<()> { return Ok(()); } + // TODO: Remove this when upgrading from v0.8.x is unlikely + // Only run this migration on macOS, as it's the only platform where the config needs to be moved + if cfg!(target_os = "macos") { + migrate_config()?; + } + setup_terminal()?; defer! { shutdown_terminal().expect("shutdown failed"); @@ -244,6 +250,29 @@ fn get_app_config_path() -> Result { Ok(path) } +fn migrate_config() -> Result<()> { + let mut path = dirs::preference_dir().ok_or_else(|| { + anyhow!("failed to find os preference dir.") + })?; + + path.push("gitui"); + if !path.exists() { + return Ok(()); + } + + let config_path = get_app_config_path()?; + let entries = path.read_dir()?.flatten(); + for entry in entries { + let mut config_path = config_path.clone(); + config_path.push(entry.file_name()); + fs::rename(entry.path(), config_path)?; + } + + let _ = fs::remove_dir(path); + + Ok(()) +} + fn setup_logging() -> Result<()> { let mut path = get_app_cache_path()?; path.push("gitui.log");