Skip to main content

git_stk/commands/
new.rs

1use anyhow::Result;
2use clap::ArgAction;
3
4use crate::commands::Run;
5
6/// Create a new child branch from the current branch.
7#[derive(Debug, clap::Args)]
8pub struct New {
9    /// Name for the new child branch.
10    branch: String,
11    /// Insert above the current branch, moving its children onto the new one.
12    #[arg(long, conflicts_with = "prepend")]
13    insert: bool,
14    /// Insert below the current branch, moving it onto the new one.
15    #[arg(long, conflicts_with = "insert")]
16    prepend: bool,
17    /// Print what would change (the branch, and any retargeted children)
18    /// without creating or moving anything.
19    #[arg(long, short = 'n', action = ArgAction::SetTrue)]
20    dry_run: bool,
21}
22
23impl Run for New {
24    fn run(self) -> Result<()> {
25        if self.insert {
26            crate::stack::insert_branch(&self.branch, self.dry_run)
27        } else if self.prepend {
28            crate::stack::prepend_branch(&self.branch, self.dry_run)
29        } else {
30            crate::stack::create_branch(&self.branch, self.dry_run)
31        }
32    }
33}