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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use clap::{ArgAction, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "git-stk")]
#[command(about = "Git-native stacked branch workflow helper, with GitHub and GitLab integration")]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Create a new child branch from the current branch.
New { branch: String },
/// Print a branch's stack parent.
Parent { branch: Option<String> },
/// Print a branch's stack children.
Children { branch: Option<String> },
/// Check out the current branch's stack parent.
Up,
/// Check out a stack child of the current branch.
Down { branch: Option<String> },
/// Print the current stack.
List,
/// Print local and remote stack status for a branch.
Status { branch: Option<String> },
/// Attach an existing branch to a parent.
Adopt {
branch: String,
#[arg(long)]
parent: String,
},
/// Remove stack parent metadata from a branch.
Detach { branch: Option<String> },
/// Rebase the current branch and descendants onto their stack parents.
Restack {
/// Pass --update-refs to git rebase.
#[arg(long, action = ArgAction::SetTrue, conflicts_with = "no_update_refs")]
update_refs: bool,
/// Do not pass --update-refs to git rebase.
#[arg(long, action = ArgAction::SetTrue)]
no_update_refs: bool,
},
/// Continue an interrupted restack after resolving conflicts.
Continue,
/// Abort an interrupted restack.
Abort,
/// Print detected review provider.
Provider,
/// Print the review request for a branch.
Review { branch: Option<String> },
/// Sync local stack metadata from remote review requests.
Sync {
branch: Option<String>,
/// Print what would change without updating local metadata.
#[arg(long, action = ArgAction::SetTrue)]
dry_run: bool,
},
/// Create or update a remote review request for a branch.
Submit {
branch: Option<String>,
/// Print what would change without creating or updating reviews.
#[arg(long, action = ArgAction::SetTrue)]
dry_run: bool,
/// Submit the branch and its descendants parent-first.
#[arg(long, conflicts_with = "branch")]
stack: bool,
},
/// Clean up local metadata for merged review requests.
Cleanup {
branch: Option<String>,
/// Print what would change without updating local metadata.
#[arg(long, action = ArgAction::SetTrue)]
dry_run: bool,
/// Delete cleaned merged branches after updating stack metadata.
#[arg(long, action = ArgAction::SetTrue)]
delete_branch: bool,
},
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum UpdateRefsMode {
Config,
Enabled,
Disabled,
}
impl UpdateRefsMode {
pub fn from_flags(update_refs: bool, no_update_refs: bool) -> Self {
match (update_refs, no_update_refs) {
(true, false) => Self::Enabled,
(false, true) => Self::Disabled,
_ => Self::Config,
}
}
}