ok/jj
1
0
Fork 0
forked from mirrors/jj

cli squash: explain --into in error message for merge commits

This commit is contained in:
Ilya Grigoriev 2024-09-04 19:33:48 -07:00
parent 24c263698b
commit 6f44ed4f51
2 changed files with 9 additions and 4 deletions

View file

@ -27,6 +27,7 @@ use crate::cli_util::DiffSelector;
use crate::cli_util::RevisionArg;
use crate::cli_util::WorkspaceCommandTransaction;
use crate::command_error::user_error;
use crate::command_error::user_error_with_hint;
use crate::command_error::CommandError;
use crate::description_util::combine_messages;
use crate::description_util::join_message_paragraphs;
@ -117,7 +118,10 @@ pub(crate) fn cmd_squash(
.resolve_single_rev(args.revision.as_ref().unwrap_or(&RevisionArg::AT))?;
let mut parents: Vec<_> = source.parents().try_collect()?;
if parents.len() != 1 {
return Err(user_error("Cannot squash merge commits"));
return Err(user_error_with_hint(
"Cannot squash merge commits without a specified destination",
"Use `--into` to specify which parent to squash into",
));
}
sources = vec![source];
destination = parents.pop().unwrap();

View file

@ -100,9 +100,10 @@ fn test_squash() {
000000000000 (empty)
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["squash"]);
insta::assert_snapshot!(stderr, @r###"
Error: Cannot squash merge commits
"###);
insta::assert_snapshot!(stderr, @r#"
Error: Cannot squash merge commits without a specified destination
Hint: Use `--into` to specify which parent to squash into
"#);
// Can squash into a merge commit
test_env.jj_cmd_ok(&repo_path, &["new", "e"]);