Skip to content

Commit

Permalink
cli git push: change warning if default revset contains no branches
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ilyagr committed Feb 4, 2024
1 parent 64fa847 commit d7bbbd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"###);
}
Expand All @@ -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.
"###);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7bbbd1

Please sign in to comment.