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    /// Print the rebase plan without rebasing anything.
24    #[arg(long, action = ArgAction::SetTrue)]
25    dry_run: bool,
26}
27
28impl Run for Restack {
29    fn run(self) -> Result<()> {
30        crate::stack::restack(
31            UpdateRefsMode::from_flags(self.update_refs, self.no_update_refs),
32            PushMode::from_flags(self.push, self.no_push),
33            self.dry_run,
34        )
35    }
36}
37
38/// Continue an interrupted restack after resolving conflicts.
39#[derive(Debug, clap::Args)]
40pub struct Continue {}
41
42impl Run for Continue {
43    fn run(self) -> Result<()> {
44        crate::stack::continue_restack()
45    }
46}
47
48/// Abort an interrupted restack.
49#[derive(Debug, clap::Args)]
50pub struct Abort {}
51
52impl Run for Abort {
53    fn run(self) -> Result<()> {
54        crate::stack::abort_restack()
55    }
56}