2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-04-06 17:05:21 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-04-22 17:26:17 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2022-04-06 17:05:21 +00:00
|
|
|
use crate::common::TestEnvironment;
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_move() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
// F
|
|
|
|
// |
|
|
|
|
// E C
|
|
|
|
// | |
|
|
|
|
// D B
|
|
|
|
// |/
|
|
|
|
// A
|
|
|
|
//
|
|
|
|
// When moving changes between e.g. C and F, we should not get unrelated changes
|
|
|
|
// from B and D.
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
2022-08-25 22:18:14 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["edit", "a"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file2"), "e\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "f"]);
|
2022-04-06 17:05:21 +00:00
|
|
|
std::fs::write(repo_path.join("file2"), "f\n").unwrap();
|
|
|
|
// Test the setup
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 0d7353584003 f
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ e9515f21068c e
|
|
|
|
◉ bdd835cae844 d
|
|
|
|
│ ◉ caa4d0b23201 c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-06 17:05:21 +00:00
|
|
|
"###);
|
|
|
|
|
2022-04-24 18:52:04 +00:00
|
|
|
// Errors out without arguments
|
2022-11-18 20:50:39 +00:00
|
|
|
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["move"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2023-03-17 23:14:20 +00:00
|
|
|
error: the following required arguments were not provided:
|
2022-11-18 20:50:39 +00:00
|
|
|
<--from <FROM>|--to <TO>>
|
|
|
|
|
|
|
|
Usage: jj move <--from <FROM>|--to <TO>> [PATHS]...
|
|
|
|
|
2023-03-17 23:14:20 +00:00
|
|
|
For more information, try '--help'.
|
2022-11-18 20:50:39 +00:00
|
|
|
"###);
|
2022-04-24 18:52:04 +00:00
|
|
|
// Errors out if source and destination are the same
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["move", "--to", "@"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Source and destination cannot be the same.
|
|
|
|
"###);
|
2022-04-06 17:05:21 +00:00
|
|
|
|
|
|
|
// Can move from sibling, which results in the source being abandoned
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: 1c03e3d3c63f (no description set)
|
2022-04-06 17:05:21 +00:00
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
"###);
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 1c03e3d3c63f f
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ e9515f21068c e
|
|
|
|
◉ bdd835cae844 d
|
|
|
|
│ ◉ 55171e33db26 b c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-06 17:05:21 +00:00
|
|
|
"###);
|
|
|
|
// The change from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-06 17:05:21 +00:00
|
|
|
// File `file2`, which was not changed in source, is unchanged
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
f
|
|
|
|
"###);
|
2022-04-06 17:05:21 +00:00
|
|
|
|
|
|
|
// Can move from ancestor
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "@--"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: c8d83075e8c2 (no description set)
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-04-23 04:17:38 +00:00
|
|
|
// The change has been removed from the source (the change pointed to by 'd'
|
|
|
|
// became empty and was abandoned)
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ c8d83075e8c2 f
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2c50bfc59c68 e
|
|
|
|
│ ◉ caa4d0b23201 c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a d
|
|
|
|
◉ 000000000000
|
2022-04-06 17:05:21 +00:00
|
|
|
"###);
|
|
|
|
// The change from the source has been applied (the file contents were already
|
|
|
|
// "f", as is typically the case when moving changes from an ancestor)
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
f
|
|
|
|
"###);
|
2022-04-23 04:17:38 +00:00
|
|
|
|
|
|
|
// Can move from descendant
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "e", "--to", "d"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: 2b723b1d6033 (no description set)
|
2022-04-23 04:17:38 +00:00
|
|
|
"###);
|
|
|
|
// The change has been removed from the source (the change pointed to by 'e'
|
|
|
|
// became empty and was abandoned)
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 2b723b1d6033 f
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 4293930d6333 d e
|
|
|
|
│ ◉ caa4d0b23201 c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-23 04:17:38 +00:00
|
|
|
"###);
|
|
|
|
// The change from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "d"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
e
|
|
|
|
"###);
|
2022-04-06 17:05:21 +00:00
|
|
|
}
|
2022-04-06 22:56:18 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-04-09 16:58:33 +00:00
|
|
|
fn test_move_partial() {
|
2022-04-06 22:56:18 +00:00
|
|
|
let mut test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
// C
|
|
|
|
// |
|
|
|
|
// D B
|
|
|
|
// |/
|
|
|
|
// A
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
|
2022-04-06 22:56:18 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file3"), "a\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
|
2022-04-06 22:56:18 +00:00
|
|
|
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
|
2022-04-06 22:56:18 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
|
2022-08-25 22:18:14 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["edit", "a"]);
|
2022-04-06 22:56:18 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "d"]);
|
2022-04-06 22:56:18 +00:00
|
|
|
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
|
|
|
|
// Test the setup
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ bdd835cae844 d
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ 5028db694b6b c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-06 22:56:18 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_diff_editor();
|
|
|
|
|
2022-04-09 16:58:33 +00:00
|
|
|
// If we don't make any changes in the diff-editor, the whole change is moved
|
2022-04-06 22:56:18 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "-i", "--from", "c"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: 71b69e433fbc (no description set)
|
2022-04-06 22:56:18 +00:00
|
|
|
Added 0 files, modified 2 files, removed 0 files
|
|
|
|
"###);
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 71b69e433fbc d
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ 55171e33db26 b c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-06 22:56:18 +00:00
|
|
|
"###);
|
|
|
|
// The changes from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-06 22:56:18 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-06 22:56:18 +00:00
|
|
|
// File `file3`, which was not changed in source, is unchanged
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file3"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
d
|
|
|
|
"###);
|
2022-04-06 22:56:18 +00:00
|
|
|
|
2022-04-09 16:58:33 +00:00
|
|
|
// Can move only part of the change in interactive mode
|
2022-04-06 22:56:18 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
std::fs::write(&edit_script, "reset file2").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "-i", "--from", "c"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: 63f1a6e96edb (no description set)
|
2022-04-06 22:56:18 +00:00
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
"###);
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 63f1a6e96edb d
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ d027c6e3e6bc c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-06 22:56:18 +00:00
|
|
|
"###);
|
|
|
|
// The selected change from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-06 22:56:18 +00:00
|
|
|
// The unselected change from the source has not been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
2022-04-09 16:58:33 +00:00
|
|
|
// File `file3`, which was changed in source's parent, is unchanged
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file3"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
d
|
|
|
|
"###);
|
2022-04-09 16:58:33 +00:00
|
|
|
|
2022-04-23 04:17:38 +00:00
|
|
|
// Can move only part of the change from a sibling in non-interactive mode
|
2022-04-09 16:58:33 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
// Clear the script so we know it won't be used
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "file1"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: 17c2e6632cc5 (no description set)
|
2022-04-09 16:58:33 +00:00
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
"###);
|
2022-04-22 17:26:17 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 17c2e6632cc5 d
|
2023-03-15 03:37:56 +00:00
|
|
|
│ ◉ 6a3ae047a03e c
|
|
|
|
│ ◉ 55171e33db26 b
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-09 16:58:33 +00:00
|
|
|
"###);
|
|
|
|
// The selected change from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-09 16:58:33 +00:00
|
|
|
// The unselected change from the source has not been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
2022-04-09 16:58:33 +00:00
|
|
|
// File `file3`, which was changed in source's parent, is unchanged
|
2022-04-06 22:56:18 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file3"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
d
|
|
|
|
"###);
|
2022-04-23 04:17:38 +00:00
|
|
|
|
|
|
|
// Can move only part of the change from a descendant in non-interactive mode
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
// Clear the script so we know it won't be used
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let stdout =
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--from", "c", "--to", "b", "file1"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
"###);
|
2022-04-23 04:17:38 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 21253406d416 c
|
|
|
|
◉ e1cf08aae711 b
|
2023-02-09 02:53:47 +00:00
|
|
|
│ @ bdd835cae844 d
|
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 3db0a2f5b535 a
|
|
|
|
◉ 000000000000
|
2022-04-23 04:17:38 +00:00
|
|
|
"###);
|
|
|
|
// The selected change from the source has been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
2022-04-23 04:17:38 +00:00
|
|
|
// The unselected change from the source has not been applied
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
2022-04-06 22:56:18 +00:00
|
|
|
}
|
2022-04-22 17:26:17 +00:00
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
2023-02-28 11:30:57 +00:00
|
|
|
let template = r#"commit_id.short() ++ " " ++ branches"#;
|
2023-02-28 10:43:14 +00:00
|
|
|
test_env.jj_cmd_success(cwd, &["log", "-T", template])
|
2022-04-22 17:26:17 +00:00
|
|
|
}
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_move_description() {
|
|
|
|
let mut test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
2022-12-21 04:33:21 +00:00
|
|
|
std::fs::write(&edit_script, r#"fail"#).unwrap();
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
// If both descriptions are empty, the resulting description is empty
|
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["new"]);
|
|
|
|
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
2023-01-31 09:17:46 +00:00
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @"");
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
// If the destination's description is empty and the source's description is
|
|
|
|
// non-empty, the resulting description is from the source
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
source
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// If the destination's description is non-empty and the source's description is
|
|
|
|
// empty, the resulting description is from the destination
|
2022-12-21 04:33:21 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["op", "restore", "@--"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "destination"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
destination
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// 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"]);
|
2022-12-22 07:58:23 +00:00
|
|
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
2022-08-28 17:28:53 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
destination
|
2022-12-21 04:47:10 +00:00
|
|
|
|
2022-08-28 17:28:53 +00:00
|
|
|
source
|
|
|
|
"###);
|
2022-12-22 07:58:23 +00:00
|
|
|
insta::assert_snapshot!(
|
|
|
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
|
|
|
JJ: Enter a description for the combined commit.
|
|
|
|
JJ: Description from the destination commit:
|
|
|
|
destination
|
|
|
|
|
|
|
|
JJ: Description from the source commit:
|
|
|
|
source
|
|
|
|
|
|
|
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
|
|
"###);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
// 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"]);
|
|
|
|
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-", "file1"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
destination
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
source
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_description(test_env: &TestEnvironment, repo_path: &Path, rev: &str) -> String {
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
repo_path,
|
|
|
|
&["log", "--no-graph", "-T", "description", "-r", rev],
|
|
|
|
)
|
|
|
|
}
|