cli: git: split loop that collects push directions and new targets

Just a minor code cleanup.
This commit is contained in:
Yuya Nishihara 2024-06-04 16:40:04 +09:00
parent 3050685ff3
commit e9db051b84

View file

@ -916,29 +916,34 @@ fn cmd_git_push(
return Ok(()); return Ok(());
} }
let mut new_heads = vec![];
let mut branch_push_direction = HashMap::new(); let mut branch_push_direction = HashMap::new();
for (branch_name, update) in &branch_updates { for (branch_name, update) in &branch_updates {
if let Some(new_target) = &update.new_target { let BranchPushUpdate {
new_heads.push(new_target.clone()); old_target: Some(old_target),
if let Some(old_target) = &update.old_target { new_target: Some(new_target),
assert_ne!(old_target, new_target); } = update
branch_push_direction.insert( else {
branch_name.to_string(), continue;
if repo.index().is_ancestor(old_target, new_target) { };
BranchMoveDirection::Forward assert_ne!(old_target, new_target);
} else if repo.index().is_ancestor(new_target, old_target) { branch_push_direction.insert(
BranchMoveDirection::Backward branch_name.to_string(),
} else { if repo.index().is_ancestor(old_target, new_target) {
BranchMoveDirection::Sideways BranchMoveDirection::Forward
}, } else if repo.index().is_ancestor(new_target, old_target) {
); BranchMoveDirection::Backward
} } else {
} BranchMoveDirection::Sideways
},
);
} }
// Check if there are conflicts in any commits we're about to push that haven't // Check if there are conflicts in any commits we're about to push that haven't
// already been pushed. // already been pushed.
let new_heads = branch_updates
.iter()
.filter_map(|(_, update)| update.new_target.clone())
.collect_vec();
let mut old_heads = repo let mut old_heads = repo
.view() .view()
.remote_branches(&remote) .remote_branches(&remote)