Skip to content

Commit b546bdb

Browse files
committed
feat: add --status flag to show chain rebase state
Add `git chain rebase --status` to display the current state of an in-progress chain rebase. Shows per-branch status with emoji indicators (Completed, Skipped, Pending, Conflict, etc.), progress count, and original branch information. Reports "No chain rebase in progress" when no state file exists.
1 parent cb986f1 commit b546bdb

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

src/cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ where
138138
"squashed_merge",
139139
"abort_rebase",
140140
"skip_rebase",
141+
"status_rebase",
141142
])
142143
.takes_value(false),
143144
)
@@ -151,6 +152,7 @@ where
151152
"squashed_merge",
152153
"continue_rebase",
153154
"skip_rebase",
155+
"status_rebase",
154156
])
155157
.takes_value(false),
156158
)
@@ -164,6 +166,21 @@ where
164166
"squashed_merge",
165167
"continue_rebase",
166168
"abort_rebase",
169+
"status_rebase",
170+
])
171+
.takes_value(false),
172+
)
173+
.arg(
174+
Arg::with_name("status_rebase")
175+
.long("status")
176+
.help("Show the current chain rebase state")
177+
.conflicts_with_all(&[
178+
"step",
179+
"ignore_root",
180+
"squashed_merge",
181+
"continue_rebase",
182+
"abort_rebase",
183+
"skip_rebase",
167184
])
168185
.takes_value(false),
169186
);

src/commands.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ pub fn run(arg_matches: ArgMatches) -> Result<(), Error> {
258258
};
259259
}
260260
("rebase", Some(sub_matches)) => {
261-
if sub_matches.is_present("continue_rebase") {
261+
if sub_matches.is_present("status_rebase") {
262+
git_chain.rebase_status()?;
263+
} else if sub_matches.is_present("continue_rebase") {
262264
git_chain.rebase_continue()?;
263265
} else if sub_matches.is_present("skip_rebase") {
264266
git_chain.rebase_skip()?;

src/git_chain/operations.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,71 @@ impl GitChain {
10061006
Ok(())
10071007
}
10081008

1009+
/// Display the current chain rebase status.
1010+
pub fn rebase_status(&self) -> Result<(), Error> {
1011+
if !state_exists(&self.repo) {
1012+
println!("No chain rebase in progress.");
1013+
return Ok(());
1014+
}
1015+
1016+
let state = read_state(&self.repo)?;
1017+
1018+
println!();
1019+
println!("📊 Chain Rebase Status: {}", state.chain_name.bold());
1020+
println!(" Root: {}", state.root_branch.bold());
1021+
println!();
1022+
1023+
for (i, branch) in state.branches.iter().enumerate() {
1024+
let (icon, status_label) = match branch.status {
1025+
BranchRebaseStatus::Completed => ("✅", "Completed"),
1026+
BranchRebaseStatus::Skipped => ("⏭️ ", "Skipped"),
1027+
BranchRebaseStatus::SquashReset => ("🔄", "Reset (squash-merge)"),
1028+
BranchRebaseStatus::Conflict => ("❌", "Conflict"),
1029+
BranchRebaseStatus::InProgress => ("🔧", "In Progress"),
1030+
BranchRebaseStatus::Failed => ("💥", "Failed"),
1031+
BranchRebaseStatus::Pending => ("⏳", "Pending"),
1032+
};
1033+
1034+
let current_marker = if branch.status == BranchRebaseStatus::Conflict
1035+
|| branch.status == BranchRebaseStatus::InProgress
1036+
{
1037+
" ← current"
1038+
} else {
1039+
""
1040+
};
1041+
1042+
println!(
1043+
" {} {} ({}/{}) onto {} — {}{}",
1044+
icon,
1045+
branch.name.bold(),
1046+
i + 1,
1047+
state.total_count,
1048+
branch.parent,
1049+
status_label,
1050+
current_marker
1051+
);
1052+
}
1053+
1054+
let completed = state
1055+
.branches
1056+
.iter()
1057+
.filter(|b| {
1058+
matches!(
1059+
b.status,
1060+
BranchRebaseStatus::Completed
1061+
| BranchRebaseStatus::Skipped
1062+
| BranchRebaseStatus::SquashReset
1063+
)
1064+
})
1065+
.count();
1066+
1067+
println!();
1068+
println!(" Progress: {}/{} completed", completed, state.total_count);
1069+
println!(" Original branch: {}", state.original_branch.bold());
1070+
1071+
Ok(())
1072+
}
1073+
10091074
/// Print a summary report after rebase completion.
10101075
fn print_rebase_summary(&self, state: &ChainRebaseState, num_of_rebase_operations: usize) {
10111076
let completed = state

0 commit comments

Comments
 (0)