Skip to main content

git_same/commands/support/
workspace.rs

1use crate::config::WorkspaceConfig;
2use crate::errors::{AppError, Result};
3use crate::output::Output;
4
5/// Ensure the workspace root path exists.
6///
7/// If the configured path is missing, returns an error advising the user
8/// to re-run `gisa setup`.
9pub(crate) fn ensure_base_path(workspace: &WorkspaceConfig, output: &Output) -> Result<()> {
10    let base_path = workspace.expanded_base_path();
11    if base_path.is_dir() {
12        return Ok(());
13    }
14    if base_path.exists() {
15        return Err(AppError::config(format!(
16            "Base path '{}' exists but is not a directory.",
17            base_path.display()
18        )));
19    }
20
21    output.warn(&format!(
22        "Base path '{}' does not exist. Run 'gisa setup' to reconfigure.",
23        base_path.display()
24    ));
25    Err(AppError::config(format!(
26        "Base path '{}' does not exist.",
27        base_path.display()
28    )))
29}
30
31#[cfg(test)]
32#[path = "workspace_tests.rs"]
33mod tests;