From d7bbbd1c29317308b1fb1499f39514a3c79cfd21 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sat, 3 Feb 2024 19:58:34 -0800 Subject: [PATCH] cli `git push`: change warning if default revset contains no branches Previously, `jj git push; jj git push` would tell the user that "No branches point to the specified revisions.". I found this confusing, even though strictly speaking it is correct (as the default revset only considers revisions that haven't been pushed to the remote). Closes #2241 --- cli/src/commands/git.rs | 19 ++++++++++++++----- cli/tests/test_git_push.rs | 6 +++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cli/src/commands/git.rs b/cli/src/commands/git.rs index 235414f09..a062a483b 100644 --- a/cli/src/commands/git.rs +++ b/cli/src/commands/git.rs @@ -780,11 +780,20 @@ fn cmd_git_push( Err(reason) => reason.print(ui)?, } } - if (!args.revisions.is_empty() || use_default_revset) && branches_targeted.is_empty() { - writeln!( - ui.warning(), - "No branches point to the specified revisions." - )?; + if branches_targeted.is_empty() { + if use_default_revset { + writeln!( + ui.warning(), + "No branches found in the default push revset, \ + `remote_branches(remote={remote})..@`." + )?; + } else if !args.revisions.is_empty() { + writeln!( + ui.warning(), + "No branches point to the specified revisions." + )?; + } else { /* A plain "Nothing changed" message will suffice */ + } } tx_description = format!( diff --git a/cli/tests/test_git_push.rs b/cli/tests/test_git_push.rs index ecc1679ee..ec44760c8 100644 --- a/cli/tests/test_git_push.rs +++ b/cli/tests/test_git_push.rs @@ -135,7 +135,7 @@ fn test_git_push_no_matching_branch() { let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - No branches point to the specified revisions. + No branches found in the default push revset, `remote_branches(remote=origin)..@`. Nothing changed. "###); } @@ -147,7 +147,7 @@ fn test_git_push_matching_branch_unchanged() { let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - No branches point to the specified revisions. + No branches found in the default push revset, `remote_branches(remote=origin)..@`. Nothing changed. "###); } @@ -190,7 +190,7 @@ fn test_git_push_other_remote_has_branch() { let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" - No branches point to the specified revisions. + No branches found in the default push revset, `remote_branches(remote=origin)..@`. Nothing changed. "###); // But it will still get pushed to another remote