Skip to content

Commit

Permalink
unsquash: deprecate in favor of squash
Browse files Browse the repository at this point in the history
Everything can be done with `jj squash` that could be done with `jj
unsquash`.
  • Loading branch information
samueltardieu committed Sep 15, 2024
1 parent 56dbbb8 commit 70caa3e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 45 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
that describes them better, and they also behave similar to Mercurial's
bookmarks.

* `jj unsquash` has been deprecated in favor of `jj squash`.

**Rationale:** `jj squash` can do everything `jj unsquash` does, and more.
For example, `jj squash` can select the paths to be pulled from the source
commit to the target commit. To do this with `jj unsquash` requires the use
of the interactive mode.

* The `git.push-branch-prefix` config has been deprecated in favor of
`git.push-bookmark-prefix`.

Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ enum Command {
Util(util::UtilCommand),
/// Undo an operation (shortcut for `jj op undo`)
Undo(operation::undo::OperationUndoArgs),
#[command(hide = true)]
Unsquash(unsquash::UnsquashArgs),
// TODO: Delete `untrack` in jj 0.27+
#[command(hide = true)]
Expand Down
11 changes: 10 additions & 1 deletion cli/src/commands/unsquash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::command_error::CommandError;
use crate::description_util::combine_messages;
use crate::ui::Ui;

/// Move changes from a revision's parent into the revision
/// Move changes from a revision's parent into the revision (DEPRECATED, use `jj
/// squash`)
///
/// After moving the changes out of the parent, the child revision will have the
/// same content state as before. If moving the change out of the parent change
Expand Down Expand Up @@ -56,6 +57,14 @@ pub(crate) fn cmd_unsquash(
command: &CommandHelper,
args: &UnsquashArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
"`jj unsquash` is deprecated; use `jj squash` instead, which is more powerful"
)?;
writeln!(
ui.warning_default(),
"`jj unsquash` will be removed in a future version, and this will be a hard error"
)?;
let mut workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision)?;
workspace_command.check_rewritable([commit.id()])?;
Expand Down
24 changes: 0 additions & 24 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ This document contains the help content for the `jj` command-line program.
* [`jj util markdown-help`↴](#jj-util-markdown-help)
* [`jj util config-schema`↴](#jj-util-config-schema)
* [`jj undo`↴](#jj-undo)
* [`jj unsquash`↴](#jj-unsquash)
* [`jj version`↴](#jj-version)
* [`jj workspace`↴](#jj-workspace)
* [`jj workspace add`↴](#jj-workspace-add)
Expand Down Expand Up @@ -145,7 +144,6 @@ To get started, see the tutorial at https://martinvonz.github.io/jj/latest/tutor
* `tag`Manage tags
* `util`Infrequently used commands such as for generating shell completions
* `undo`Undo an operation (shortcut for `jj op undo`)
* `unsquash`Move changes from a revision's parent into the revision
* `version`Display version information
* `workspace`Commands for working with workspaces

Expand Down Expand Up @@ -2097,28 +2095,6 @@ Undo an operation (shortcut for `jj op undo`)
## `jj unsquash`
Move changes from a revision's parent into the revision
After moving the changes out of the parent, the child revision will have the same content state as before. If moving the change out of the parent change made it empty compared to its parent, it will be abandoned. Without `--interactive`, the parent change will always become empty.
If the source became empty and both the source and destination had a non-empty description, you will be asked for the combined description. If either was empty, then the other one will be used.
If a working-copy commit gets abandoned, it will be given a new, empty commit. This is true in general; it is not specific to this command.
**Usage:** `jj unsquash [OPTIONS]`
###### **Options:**
* `-r`, `--revision <REVISION>`
Default value: `@`
* `-i`, `--interactive` — Interactively choose which parts to unsquash
* `--tool <NAME>` — Specify diff editor to be used (implies --interactive)
## `jj version`
Display version information
Expand Down
6 changes: 4 additions & 2 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ fn test_rewrite_immutable_commands() {
"###);
// unsquash
let stderr = test_env.jj_cmd_failure(&repo_path, &["unsquash", "-r=main"]);
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Error: Commit 1d5af877b8bb is immutable
Hint: Pass `--ignore-immutable` or configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
"#);
}
42 changes: 28 additions & 14 deletions cli/tests/test_unsquash_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ fn test_unsquash() {
// Unsquashes into the working copy from its parent by default
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Working copy now at: mzvwutvl 9177132c c | (no description set)
Parent commit : qpvuntsm 184ddbcc a b | (no description set)
"###);
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 9177132cfbb9 c
○ 184ddbcce5a9 a b
Expand All @@ -60,11 +62,13 @@ fn test_unsquash() {
test_env.jj_cmd_ok(&repo_path, &["undo"]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-r", "b"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Rebased 1 descendant commits
Working copy now at: mzvwutvl b353b29c c | (no description set)
Parent commit : kkmpptxz 27772b15 b | (no description set)
"###);
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ b353b29c423d c
○ 27772b156771 b
Expand Down Expand Up @@ -99,20 +103,24 @@ fn test_unsquash() {
◆ 000000000000
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["unsquash"]);
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Error: Cannot unsquash merge commits
"###);
"#);

// Can unsquash from a merge commit
test_env.jj_cmd_ok(&repo_path, &["new", "e"]);
std::fs::write(repo_path.join("file1"), "e\n").unwrap();
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Working copy now at: pzsxstzt bd05eb69 merge
Parent commit : mzvwutvl 382c9bad c e?? | (no description set)
Parent commit : xznxytkn f86e2b3a d e?? | (no description set)
"###);
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bd05eb698d1e
├─╮
Expand Down Expand Up @@ -160,11 +168,13 @@ fn test_unsquash_partial() {
std::fs::write(&edit_script, "dump JJ-INSTRUCTIONS instrs").unwrap();
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-r", "b", "-i"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Rebased 1 descendant commits
Working copy now at: mzvwutvl 8802263d c | (no description set)
Parent commit : kkmpptxz 5bd83140 b | (no description set)
"###);
"#);

insta::assert_snapshot!(
std::fs::read_to_string(test_env.env_root().join("instrs")).unwrap(), @r###"
Expand Down Expand Up @@ -195,10 +205,12 @@ fn test_unsquash_partial() {
std::fs::write(edit_script, "reset file1").unwrap();
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["unsquash", "-i"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Working copy now at: mzvwutvl a896ffde c | (no description set)
Parent commit : kkmpptxz 904111b4 b | (no description set)
"###);
"#);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ a896ffdebb85 c
○ 904111b4d3c4 b
Expand Down Expand Up @@ -233,10 +245,12 @@ fn test_unsquash_partial() {
],
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Warning: `jj unsquash` is deprecated; use `jj squash` instead, which is more powerful
Warning: `jj unsquash` will be removed in a future version, and this will be a hard error
Working copy now at: mzvwutvl aaca9268 c | (no description set)
Parent commit : kkmpptxz fe8eb117 b | (no description set)
"###);
"#);
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "b"]);
insta::assert_snapshot!(stdout, @r###"
a
Expand Down
7 changes: 3 additions & 4 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ line. Unlike `jj squash -i`, which left the content state of the commit
unchanged, `jj diffedit` (typically) results in a different state, which means
that descendant commits may have conflicts.
Other commands for rewriting contents of existing commits are `jj split`, `jj
unsquash -i`. Now that you've seen how `jj squash -i` and `jj diffedit` work,
you can hopefully figure out how those work (with the help of the instructions
in the diff).
Another command for rewriting contents of existing commits is `jj split`. Now that
you've seen how `jj squash -i` and `jj diffedit` work, you can hopefully figure out
how it works (with the help of the instructions in the diff).

0 comments on commit 70caa3e

Please sign in to comment.