Skip to content

Commit

Permalink
unsquash: deprecate in favor of squash and diffedit
Browse files Browse the repository at this point in the history
Everything that could be done with `jj unsquash` can be done with
`jj squash` or `jj diffedit --preserve-descendants`.
  • Loading branch information
samueltardieu committed Sep 24, 2024
1 parent f76ee18 commit 0b724e6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 47 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ 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` and
`jj diffedit --restore-descendants`.

**Rationale:** `jj squash` can be used in interactive mode to pull
changes from one commit to another, including from a parent commit
to a child commit. For finer-grained application, such as when
the parent and the child commits must successively modify the same
location in a file, `jj diffedit --restore-descendants` can be used to
set the parent commit to the desired content without altering the
content of the child commit.

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

Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/diffedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ use crate::ui::Ui;
/// rebased on top as usual, which may result in conflicts.
///
/// See `jj restore` if you want to move entire files from one revision to
/// another. See `jj squash -i` or `jj unsquash -i` if you instead want to move
/// changes into or out of the parent revision.
/// another. For moving changes between revisions, see `jj squash -i`.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct DiffeditArgs {
/// The revision to touch up
Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ enum Command {
Util(util::UtilCommand),
/// Undo an operation (shortcut for `jj op undo`)
Undo(operation::undo::OperationUndoArgs),
// TODO: Delete `unsquash` in jj 0.28+
#[command(hide = true)]
Unsquash(unsquash::UnsquashArgs),
// TODO: Delete `untrack` in jj 0.27+
#[command(hide = true)]
Expand Down
8 changes: 8 additions & 0 deletions cli/src/commands/unsquash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ pub(crate) fn cmd_unsquash(
command: &CommandHelper,
args: &UnsquashArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
"`jj unsquash` is deprecated; use `jj squash` or `jj diffedit` instead"
)?;
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(ui, &args.revision)?;
workspace_command.check_rewritable([commit.id()])?;
Expand Down
26 changes: 1 addition & 25 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 @@ -146,7 +145,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 @@ -657,7 +655,7 @@ With the `--from` and/or `--to` options, starts a [diff editor] comparing the "f
Edit the right side of the diff until it looks the way you want. Once you close the editor, the revision specified with `-r` or `--to` will be updated. Unless `--restore-descendants` is used, descendants will be rebased on top as usual, which may result in conflicts.
See `jj restore` if you want to move entire files from one revision to another. See `jj squash -i` or `jj unsquash -i` if you instead want to move changes into or out of the parent revision.
See `jj restore` if you want to move entire files from one revision to another. For moving changes between revisions, see `jj squash -i`.
**Usage:** `jj diffedit [OPTIONS]`
Expand Down Expand Up @@ -2113,28 +2111,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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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` or `jj diffedit` instead
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 0b724e6

Please sign in to comment.