From b338c916c0e0b8d617abbe6ad1a770139bca79c4 Mon Sep 17 00:00:00 2001 From: Glen Choo Date: Mon, 30 Jan 2023 11:46:29 +0800 Subject: [PATCH] cli: report no updates to current branch Fix a bug where `jj git push` would print "No current branch." when there is a current branch but it is unchanged. We were conflating the two because we print the message when no updates were performed, instead of only when no branches were found. --- src/commands/git.rs | 6 +++--- tests/test_git_push.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/git.rs b/src/commands/git.rs index f4be0ddcf..b47280411 100644 --- a/src/commands/git.rs +++ b/src/commands/git.rs @@ -659,6 +659,9 @@ fn cmd_git_push( ); } } + if branches.is_empty() { + return Err(user_error("No current branch.")); + } for (branch_name, branch_target) in branches { if !seen_branches.insert(branch_name.clone()) { continue; @@ -675,9 +678,6 @@ fn cmd_git_push( } } } - if branch_updates.is_empty() { - return Err(user_error("No current branch.")); - } tx = workspace_command.start_transaction(&format!( "push current branch(es) to git remote {}", &remote diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index 4b31c8684..9b039d79f 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -129,6 +129,16 @@ fn test_git_push_no_current_branch() { "###); } +#[test] +fn test_git_push_current_branch_unchanged() { + let (test_env, workspace_root) = set_up(); + test_env.jj_cmd_success(&workspace_root, &["co", "branch1"]); + let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push"]); + insta::assert_snapshot!(stdout, @r###" + Nothing changed. + "###); +} + #[test] fn test_git_push_multiple() { let (test_env, workspace_root) = set_up();