cli: make jj git push -r just warn if no branches targeted

If there are branches in the revset that don't need to be pushed
because they already match the destination, we currently just print
`Nothing changed.` It seems consistent with that to also treat it as
success if there are no branches in the specified set to start
with. This patch makes the command print a warning in that case
instead.
This commit is contained in:
Martin von Zweigbergk 2023-08-21 22:34:58 -07:00 committed by Martin von Zweigbergk
parent d9bd578662
commit 14d35b0198
2 changed files with 9 additions and 3 deletions

View File

@ -791,7 +791,10 @@ fn cmd_git_push(
}
}
if !args.revisions.is_empty() && branches_targeted.is_empty() {
return Err(user_error("No branches point to the specified revisions."));
writeln!(
ui.warning(),
"No branches point to the specified revisions."
)?;
}
tx_description = format!(

View File

@ -341,9 +341,12 @@ fn test_git_push_revisions() {
Error: Empty revision set
"###);
// Push a revision with no branches
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "-r=@--"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-r=@--"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
insta::assert_snapshot!(stderr, @r###"
Error: No branches point to the specified revisions.
No branches point to the specified revisions.
"###);
// Push a revision with a single branch
let stdout = test_env.jj_cmd_success(&workspace_root, &["git", "push", "-r=@-", "--dry-run"]);