diff --git a/CHANGELOG.md b/CHANGELOG.md index 589760825..771d32fd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `latest(x[, n])` revset function to select the latest `n` commits. +* `jj squash` AKA `jj amend` now accepts a `--message` option to set the + description of the squashed commit on the command-line. + ### Fixed bugs * Modify/delete conflicts now include context lines diff --git a/src/commands/mod.rs b/src/commands/mod.rs index f4aa3dbc3..079939ea6 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -556,6 +556,9 @@ struct MoveArgs { struct SquashArgs { #[arg(long, short, default_value = "@")] revision: RevisionArg, + /// The description to use for squashed revision (don't open editor) + #[arg(long, short)] + message: Option, /// Interactively choose which parts to squash #[arg(long, short)] interactive: bool, @@ -2302,13 +2305,17 @@ from the source will be moved into the parent. // Abandon the child if the parent now has all the content from the child // (always the case in the non-interactive case). let abandon_child = &new_parent_tree_id == commit.tree_id(); - let description = combine_messages( - tx.base_repo(), - &commit, - parent, - command.settings(), - abandon_child, - )?; + let description = if let Some(m) = &args.message { + m.into() + } else { + combine_messages( + tx.base_repo(), + &commit, + parent, + command.settings(), + abandon_child, + )? + }; let mut_repo = tx.mut_repo(); let new_parent = mut_repo .rewrite_commit(command.settings(), parent) diff --git a/tests/test_squash_command.rs b/tests/test_squash_command.rs index e1dc8e721..7b29fd0f1 100644 --- a/tests/test_squash_command.rs +++ b/tests/test_squash_command.rs @@ -273,6 +273,13 @@ fn test_squash_description() { destination "###); + // An explicit description on the command-line overrides this + test_env.jj_cmd_success(&repo_path, &["undo"]); + test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]); + insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###" + custom + "###); + // If both descriptions were non-empty, we get asked for a combined description test_env.jj_cmd_success(&repo_path, &["undo"]); test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]); @@ -295,6 +302,14 @@ fn test_squash_description() { JJ: Lines starting with "JJ: " (like this one) will be removed. "###); + // An explicit description on the command-line overrides prevents launching an + // editor + test_env.jj_cmd_success(&repo_path, &["undo"]); + test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]); + insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###" + custom + "###); + // If the source's *content* doesn't become empty, then the source remains and // both descriptions are unchanged test_env.jj_cmd_success(&repo_path, &["undo"]);