cli: warn if loosely selected push targets include conflicted branches

This commit is contained in:
Yuya Nishihara 2023-07-03 17:52:31 +09:00
parent a3d080580e
commit 85d87e2658
2 changed files with 20 additions and 10 deletions

View File

@ -684,21 +684,23 @@ fn cmd_git_push(
let tx_description;
let mut branch_updates = vec![];
if args.all {
// TODO: Is it useful to warn about conflicted branches?
for (branch_name, branch_target) in repo.view().branches() {
if let Ok(Some(update)) = classify_branch_update(branch_name, branch_target, &remote) {
branch_updates.push((branch_name.clone(), update));
match classify_branch_update(branch_name, branch_target, &remote) {
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
Ok(None) => {}
Err(message) => writeln!(ui.warning(), "{message}")?,
}
}
tx_description = format!("push all branches to git remote {remote}");
} else if args.deleted {
// TODO: Is it useful to warn about conflicted branches?
for (branch_name, branch_target) in repo.view().branches() {
if branch_target.local_target.is_some() {
continue;
}
if let Ok(Some(update)) = classify_branch_update(branch_name, branch_target, &remote) {
branch_updates.push((branch_name.clone(), update));
match classify_branch_update(branch_name, branch_target, &remote) {
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
Ok(None) => {}
Err(message) => writeln!(ui.warning(), "{message}")?,
}
}
tx_description = format!("push all deleted branches to git remote {remote}");
@ -776,8 +778,10 @@ fn cmd_git_push(
if !seen_branches.insert(branch_name.clone()) {
continue;
}
if let Ok(Some(update)) = classify_branch_update(branch_name, branch_target, &remote) {
branch_updates.push((branch_name.clone(), update));
match classify_branch_update(branch_name, branch_target, &remote) {
Ok(Some(update)) => branch_updates.push((branch_name.clone(), update)),
Ok(None) => {}
Err(message) => writeln!(ui.warning(), "{message}")?,
}
}
if !args.revisions.is_empty() && branches_targeted.is_empty() {

View File

@ -551,17 +551,23 @@ fn test_git_push_conflicting_branches() {
// --all shouldn't be blocked by conflicting branch
bump_branch1();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "--all"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "--all"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Move branch branch1 from 45a3aa29e907 to fd1d63e031ea
"###);
insta::assert_snapshot!(stderr, @r###"
Branch branch2 is conflicted
"###);
// --revisions shouldn't be blocked by conflicting branch
bump_branch1();
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-rall()"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-rall()"]);
insta::assert_snapshot!(stdout, @r###"
Branch changes to push to origin:
Move branch branch1 from fd1d63e031ea to 8263cf992d33
"###);
insta::assert_snapshot!(stderr, @r###"
Branch branch2 is conflicted
"###);
}