Skip to main content

git_stk/commands/
restack.rs

1use anyhow::Result;
2use clap::ArgAction;
3
4use crate::cli::{FetchMode, 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    /// Fetch the trunk from the remote first, so branches rebase onto its
12    /// latest tip (overrides stk.fetchBeforeRestack).
13    #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_fetch")]
14    fetch: bool,
15    /// Do not fetch the trunk first, overriding stk.fetchBeforeRestack.
16    #[arg(long, action = ArgAction::SetTrue)]
17    no_fetch: bool,
18    /// Pass --update-refs to git rebase.
19    #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_update_refs")]
20    update_refs: bool,
21    /// Do not pass --update-refs to git rebase.
22    #[arg(long, action = ArgAction::SetTrue)]
23    no_update_refs: bool,
24    /// Force-push (with lease) every rebased branch afterwards.
25    #[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_push")]
26    push: bool,
27    /// Do not push rebased branches, overriding stk.pushOnRestack.
28    #[arg(long, action = ArgAction::SetTrue)]
29    no_push: bool,
30    /// Print the rebase plan without rebasing anything.
31    #[arg(long, short = 'n', action = ArgAction::SetTrue)]
32    dry_run: bool,
33}
34
35impl Run for Restack {
36    fn run(self) -> Result<()> {
37        crate::stack::restack(
38            FetchMode::from_flags(self.fetch, self.no_fetch),
39            UpdateRefsMode::from_flags(self.update_refs, self.no_update_refs),
40            PushMode::from_flags(self.push, self.no_push),
41            self.dry_run,
42        )
43    }
44}
45
46/// Continue an interrupted restack after resolving conflicts.
47#[derive(Debug, clap::Args)]
48pub struct Continue {}
49
50impl Run for Continue {
51    fn run(self) -> Result<()> {
52        crate::stack::continue_restack()
53    }
54}
55
56/// Abort an interrupted restack.
57#[derive(Debug, clap::Args)]
58pub struct Abort {}
59
60impl Run for Abort {
61    fn run(self) -> Result<()> {
62        crate::stack::abort_restack()
63    }
64}