1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
}
}
}