29 lines
797 B
Rust
29 lines
797 B
Rust
use anyhow::Result;
|
|
|
|
use crate::git;
|
|
|
|
use super::helpers::{require_session, teardown_session};
|
|
|
|
pub async fn action(branch: &str, force: bool) -> Result<()> {
|
|
let (root, session) = require_session(branch).await;
|
|
|
|
if git::is_dirty(&session.worktree).await {
|
|
crate::fmt::die(&format!(
|
|
"Branch \"{branch}\" has unsaved changes. Run \"sandlot save {branch}\" first."
|
|
));
|
|
}
|
|
|
|
if !force && git::is_dirty(&root).await {
|
|
crate::fmt::die(
|
|
"Working tree has uncommitted changes that may conflict with checkout. Commit or stash them first, or use -f to force.",
|
|
);
|
|
}
|
|
|
|
teardown_session(&root, branch, &session.worktree).await;
|
|
|
|
git::checkout(branch, &root).await?;
|
|
|
|
println!("\u{2714} Checked out {branch}");
|
|
Ok(())
|
|
}
|