cli: split "git push --all"/"--deleted" handling

It's easier to follow than dispatching inside loop, and the match arms will
be deduplicated later.
This commit is contained in:
Yuya Nishihara 2023-07-03 17:01:58 +09:00
parent 16bf861e3b
commit 7af45819b9

View file

@ -669,7 +669,7 @@ fn cmd_git_push(
let mut tx = workspace_command.start_transaction(""); let mut tx = workspace_command.start_transaction("");
let tx_description; let tx_description;
let mut branch_updates = vec![]; let mut branch_updates = vec![];
if args.all || args.deleted { if args.all {
// TODO: Is it useful to warn about conflicted branches? // TODO: Is it useful to warn about conflicted branches?
for (branch_name, branch_target) in repo.view().branches() { for (branch_name, branch_target) in repo.view().branches() {
let push_action = classify_branch_push_action(branch_target, &remote); let push_action = classify_branch_push_action(branch_target, &remote);
@ -678,17 +678,28 @@ fn cmd_git_push(
| BranchPushAction::LocalConflicted | BranchPushAction::LocalConflicted
| BranchPushAction::RemoteConflicted => {} | BranchPushAction::RemoteConflicted => {}
BranchPushAction::Update(update) => { BranchPushAction::Update(update) => {
if args.all || branch_target.local_target.is_none() { branch_updates.push((branch_name.clone(), update));
branch_updates.push((branch_name.clone(), update));
}
} }
} }
} }
tx_description = format!( tx_description = format!("push all branches to git remote {remote}");
"push all {}branches to git remote {}", } else if args.deleted {
if args.deleted { "deleted " } else { "" }, // TODO: Is it useful to warn about conflicted branches?
&remote for (branch_name, branch_target) in repo.view().branches() {
); if branch_target.local_target.is_some() {
continue;
}
let push_action = classify_branch_push_action(branch_target, &remote);
match push_action {
BranchPushAction::AlreadyMatches
| BranchPushAction::LocalConflicted
| BranchPushAction::RemoteConflicted => {}
BranchPushAction::Update(update) => {
branch_updates.push((branch_name.clone(), update));
}
}
}
tx_description = format!("push all deleted branches to git remote {remote}");
} else if !args.branch.is_empty() || !args.change.is_empty() || !args.revisions.is_empty() { } else if !args.branch.is_empty() || !args.change.is_empty() || !args.revisions.is_empty() {
let mut seen_branches = hashset! {}; let mut seen_branches = hashset! {};
for branch_name in &args.branch { for branch_name in &args.branch {