diff --git a/src/commands/git.rs b/src/commands/git.rs index 113329c2e..a01c0de4f 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -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() { diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 395c7bed4..a0aa92955 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -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 + "###); }