From b6b37038003d129f0392aa9d294666acf9ad43cf Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 29 Apr 2023 08:56:31 -0700 Subject: [PATCH] cli: make `jj move nonexistent` succeed I think `jj move nonexistent` should not be an error. That matches how `jj squash` works. I added tests for both commands. --- src/commands/mod.rs | 2 +- tests/test_move_command.rs | 8 ++++++++ tests/test_squash_command.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 91c598de0..b02b0c124 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2220,7 +2220,7 @@ from the source will be moved into the destination. args.interactive, matcher.as_ref(), )?; - if &new_parent_tree_id == parent_tree.id() { + if args.interactive && &new_parent_tree_id == parent_tree.id() { return Err(user_error("No changes to move")); } let new_parent_tree = tx diff --git a/tests/test_move_command.rs b/tests/test_move_command.rs index 939e365ca..096f101db 100644 --- a/tests/test_move_command.rs +++ b/tests/test_move_command.rs @@ -317,6 +317,14 @@ fn test_move_partial() { insta::assert_snapshot!(stdout, @r###" a "###); + + // If we specify only a non-existent file, then the move still succeeds and + // creates unchanged commits. + test_env.jj_cmd_success(&repo_path, &["undo"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "nonexistent"]); + insta::assert_snapshot!(stdout, @r###" + Working copy now at: b670567d9438 (no description set) + "###); } fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { diff --git a/tests/test_squash_command.rs b/tests/test_squash_command.rs index 7b29fd0f1..9756a14b4 100644 --- a/tests/test_squash_command.rs +++ b/tests/test_squash_command.rs @@ -230,6 +230,15 @@ fn test_squash_partial() { insta::assert_snapshot!(stdout, @r###" b "###); + + // If we specify only a non-existent file, then the squash still succeeds and + // creates unchanged commits. + test_env.jj_cmd_success(&repo_path, &["undo"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "nonexistent"]); + insta::assert_snapshot!(stdout, @r###" + Rebased 1 descendant commits + Working copy now at: 5e297967f76c (no description set) + "###); } fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {