Skip to content

Commit 388f740

Browse files
committed
clean up restack output
1 parent a89a984 commit 388f740

File tree

1 file changed

+23
-80
lines changed

1 file changed

+23
-80
lines changed

src/main.rs

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,8 @@ fn restack(
10191019
) -> Result<(), anyhow::Error> {
10201020
let restack_branch = restack_branch.unwrap_or(orig_branch.clone());
10211021

1022-
// Track what changes occurred during restack
1023-
let mut branches_created: Vec<String> = Vec::new();
1024-
let mut branches_restacked: Vec<String> = Vec::new();
1025-
let mut branches_pushed: Vec<String> = Vec::new();
1026-
let mut branches_uptodate: Vec<String> = Vec::new();
1022+
// Track what changes occurred during restack (branch_name, status)
1023+
let mut branch_results: Vec<(String, String)> = Vec::new();
10271024

10281025
if fetch {
10291026
git_fetch()?;
@@ -1044,7 +1041,7 @@ fn restack(
10441041
let remote_ref = format!("{DEFAULT_REMOTE}/{restack_branch}");
10451042
if git_repo.ref_exists(&remote_ref) {
10461043
run_git(&["checkout", "-b", &restack_branch, &remote_ref])?;
1047-
branches_created.push(restack_branch.clone());
1044+
branch_results.push((restack_branch.clone(), "created".to_string()));
10481045
} else {
10491046
bail!(
10501047
"Branch {} does not exist locally or on remote.",
@@ -1068,7 +1065,7 @@ fn restack(
10681065
let remote_ref = format!("{DEFAULT_REMOTE}/{}", branch.name);
10691066
if git_repo.ref_exists(&remote_ref) {
10701067
run_git(&["checkout", "-b", &branch.name, &remote_ref])?;
1071-
branches_created.push(branch.name.clone());
1068+
branch_results.push((branch.name.clone(), "created".to_string()));
10721069
}
10731070
// If remote doesn't exist either, let the subsequent operations fail
10741071
// with a clear error message
@@ -1087,7 +1084,7 @@ fn restack(
10871084
branch.name,
10881085
parent
10891086
);
1090-
branches_uptodate.push(branch.name.clone());
1087+
let mut status = "no changes".to_string();
10911088
if push
10921089
&& !git_repo.shas_match(&format!("{DEFAULT_REMOTE}/{}", branch.name), &branch.name)
10931090
{
@@ -1107,8 +1104,9 @@ fn restack(
11071104
&format!("{branch_name}:{branch_name}", branch_name = branch.name),
11081105
])?;
11091106
pushed_branches.push(branch.name.clone());
1110-
branches_pushed.push(branch.name.clone());
1107+
status = "no changes, pushed".to_string();
11111108
}
1109+
branch_results.push((branch.name.clone(), status));
11121110
} else {
11131111
tracing::info!("Branch '{}' is not stacked on '{}'...", branch.name, parent);
11141112

@@ -1146,12 +1144,14 @@ fn restack(
11461144
);
11471145
std::process::exit(1);
11481146
}
1149-
branches_restacked.push(branch.name.clone());
1150-
if push {
1147+
let status = if push {
11511148
git_push(git_repo, &branch.name)?;
11521149
pushed_branches.push(branch.name.clone());
1153-
branches_pushed.push(branch.name.clone());
1154-
}
1150+
"restacked, pushed"
1151+
} else {
1152+
"restacked"
1153+
};
1154+
branch_results.push((branch.name.clone(), status.to_string()));
11551155
continue;
11561156
}
11571157

@@ -1169,20 +1169,22 @@ fn restack(
11691169
);
11701170
std::process::exit(1);
11711171
}
1172-
branches_restacked.push(branch.name.clone());
1173-
if push {
1172+
let status = if push {
11741173
git_push(git_repo, &branch.name)?;
11751174
pushed_branches.push(branch.name.clone());
1176-
branches_pushed.push(branch.name.clone());
1177-
}
1175+
"restacked, pushed"
1176+
} else {
1177+
"restacked"
1178+
};
1179+
branch_results.push((branch.name.clone(), status.to_string()));
11781180
tracing::info!("Rebase completed successfully. Continuing...");
11791181
}
11801182
StackMethod::Merge => {
11811183
run_git(&["checkout", &branch.name])
11821184
.with_context(|| format!("checking out {}", branch.name))?;
11831185
run_git(&["merge", &parent])
11841186
.with_context(|| format!("merging {parent} into {}", branch.name))?;
1185-
branches_restacked.push(branch.name.clone());
1187+
branch_results.push((branch.name.clone(), "restacked".to_string()));
11861188
}
11871189
}
11881190
}
@@ -1203,70 +1205,11 @@ fn restack(
12031205
);
12041206

12051207
// Print summary report
1206-
let total_examined =
1207-
branches_restacked.len() + branches_uptodate.len() + branches_created.len();
1208-
let has_changes = !branches_created.is_empty()
1209-
|| !branches_restacked.is_empty()
1210-
|| !branches_pushed.is_empty();
1211-
1212-
println!();
1213-
if total_examined == 0 {
1208+
if branch_results.is_empty() {
12141209
println!("No branches to restack.");
1215-
} else if !has_changes && !branches_uptodate.is_empty() {
1216-
println!(
1217-
"All {} branch{} already up-to-date: {}",
1218-
branches_uptodate.len(),
1219-
if branches_uptodate.len() == 1 {
1220-
""
1221-
} else {
1222-
"es"
1223-
},
1224-
branches_uptodate
1225-
.iter()
1226-
.map(|b| b.green().to_string())
1227-
.collect::<Vec<_>>()
1228-
.join(", ")
1229-
);
12301210
} else {
1231-
if !branches_created.is_empty() {
1232-
println!(
1233-
"Created from remote: {}",
1234-
branches_created
1235-
.iter()
1236-
.map(|b| b.yellow().to_string())
1237-
.collect::<Vec<_>>()
1238-
.join(", ")
1239-
);
1240-
}
1241-
if !branches_restacked.is_empty() {
1242-
println!(
1243-
"Restacked: {}",
1244-
branches_restacked
1245-
.iter()
1246-
.map(|b| b.yellow().to_string())
1247-
.collect::<Vec<_>>()
1248-
.join(", ")
1249-
);
1250-
}
1251-
if !branches_uptodate.is_empty() {
1252-
println!(
1253-
"Already up-to-date: {}",
1254-
branches_uptodate
1255-
.iter()
1256-
.map(|b| b.green().to_string())
1257-
.collect::<Vec<_>>()
1258-
.join(", ")
1259-
);
1260-
}
1261-
if !branches_pushed.is_empty() {
1262-
println!(
1263-
"Pushed: {}",
1264-
branches_pushed
1265-
.iter()
1266-
.map(|b| b.yellow().to_string())
1267-
.collect::<Vec<_>>()
1268-
.join(", ")
1269-
);
1211+
for (branch, status) in &branch_results {
1212+
println!("{}: {}", branch.yellow(), status);
12701213
}
12711214
}
12721215

0 commit comments

Comments
 (0)