Skip to main content

git_stk/commands/
restack.rs

1use anyhow::Result;
2use clap::ArgAction;
3
4use crate::cli::{PushMode, UpdateRefsMode};
5use crate::commands::Run;
6
7/// Rebase every branch in the current stack onto its parent, from
8/// anywhere in the stack.
9#[derive(Debug, clap::Args)]
10pub struct Restack {
11    /// Pass --update-refs to git rebase.
12    #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_update_refs")]
13    update_refs: bool,
14    /// Do not pass --update-refs to git rebase.
15    #[arg(long, action = ArgAction::SetTrue)]
16    no_update_refs: bool,
17    /// Force-push (with lease) every rebased branch afterwards.
18    #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
19    push: bool,
20    /// Do not push rebased branches, overriding stk.pushOnRestack.
21    #[arg(long, action = ArgAction::SetTrue)]
22    no_push: bool,
23}
24
25impl Run for Restack {
26    fn run(self) -> Result<()> {
27        crate::stack::restack(
28            UpdateRefsMode::from_flags(self.update_refs, self.no_update_refs),
29            PushMode::from_flags(self.push, self.no_push),
30        )
31    }
32}
33
34/// Continue an interrupted restack after resolving conflicts.
35#[derive(Debug, clap::Args)]
36pub struct Continue {}
37
38impl Run for Continue {
39    fn run(self) -> Result<()> {
40        crate::stack::continue_restack()
41    }
42}
43
44/// Abort an interrupted restack.
45#[derive(Debug, clap::Args)]
46pub struct Abort {}
47
48impl Run for Abort {
49    fn run(self) -> Result<()> {
50        crate::stack::abort_restack()
51    }
52}