From a3d080580e45696e1e5e4f1bc6cd925b18147c50 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 3 Jul 2023 18:56:54 +0900 Subject: [PATCH] cli: on git push, do not ignore conflicting branch at @ If @ is pointed by any branch, we shouldn't fall back to @-. --- src/commands/git.rs | 14 +++++++++----- tests/test_git_push.rs | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/commands/git.rs b/src/commands/git.rs index 8e459af71..113329c2e 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -671,7 +671,11 @@ fn cmd_git_push( view.branches() .iter() .filter(|(_, branch_target)| { - matches!(&branch_target.local_target, Some(RefTarget::Normal(id)) if is_target(id)) + if let Some(target) = &branch_target.local_target { + target.adds().iter().any(&mut is_target) + } else { + false + } }) .collect() } @@ -812,10 +816,10 @@ fn cmd_git_push( return Err(user_error("No current branch.")); } for (branch_name, branch_target) in 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) => return Err(user_error(message)), } } } diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 1e41a9df5..395c7bed4 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -538,10 +538,9 @@ fn test_git_push_conflicting_branches() { }; // Conflicting branch at @ - // TODO: fix error message let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push"]); insta::assert_snapshot!(stderr, @r###" - Error: No current branch. + Error: Branch branch2 is conflicted "###); // --branch should be blocked by conflicting branch