git-stk 0.11.1

Git-native stacked branch workflow helper
Documentation
use anyhow::Result;
use clap::ArgAction;

use crate::commands::Run;

/// Create a new child branch from the current branch.
#[derive(Debug, clap::Args)]
pub struct New {
    /// Name for the new child branch.
    branch: String,
    /// Insert above the current branch, moving its children onto the new one.
    #[arg(long, conflicts_with = "prepend")]
    insert: bool,
    /// Insert below the current branch, moving it onto the new one.
    #[arg(long, conflicts_with = "insert")]
    prepend: bool,
    /// Create the branch in a worktree of its own instead of checking it out
    /// here, under `stk.worktreeDir`. git-stk owns the worktrees it creates and
    /// removes them on cleanup once the branch lands.
    #[arg(long, conflicts_with_all = ["insert", "prepend"])]
    worktree: bool,
    /// Print what would change (the branch, and any retargeted children)
    /// without creating or moving anything.
    #[arg(long, short = 'n', action = ArgAction::SetTrue)]
    dry_run: bool,
}

impl Run for New {
    fn run(self) -> Result<()> {
        if self.worktree {
            crate::stack::create_branch_in_worktree(&self.branch, self.dry_run)
        } else if self.insert {
            crate::stack::insert_branch(&self.branch, self.dry_run)
        } else if self.prepend {
            crate::stack::prepend_branch(&self.branch, self.dry_run)
        } else {
            crate::stack::create_branch(&self.branch, self.dry_run)
        }
    }
}