2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-05-29 06:05:30 +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.
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use crate::common::TestEnvironment;
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unsquash() {
|
|
|
|
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");
|
|
|
|
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "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-05-29 06:05:30 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "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-05-29 06:05:30 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
// Test the setup
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ 90fe0a96fc90 c
|
|
|
|
o fa5efbdf533c b
|
|
|
|
o 90aeefd03044 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Unsquashes into the working copy from its parent by default
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: 1b10d78f6136 (no description set)
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ 1b10d78f6136 c
|
|
|
|
o 90aeefd03044 a b
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Can unsquash into a given commit from its parent
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-r", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
Working copy now at: 45b8b3ddc25a (no description set)
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ 45b8b3ddc25a c
|
|
|
|
o 9146bcc8d996 b
|
|
|
|
o 000000000000 a
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
b
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Cannot unsquash into a merge commit (because it's unclear which parent it
|
|
|
|
// should come from)
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
2022-08-25 22:18:14 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["edit", "b"]);
|
2022-05-29 06:05:30 +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-05-29 06:05:30 +00:00
|
|
|
std::fs::write(repo_path.join("file2"), "d\n").unwrap();
|
2022-08-31 05:39:32 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "merge", "c", "d"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 1f8f152ff48e e
|
2022-05-29 06:05:30 +00:00
|
|
|
|\
|
2022-08-31 05:39:32 +00:00
|
|
|
o | 5658521e0f8b d
|
2022-05-29 06:05:30 +00:00
|
|
|
| o 90fe0a96fc90 c
|
|
|
|
|/
|
|
|
|
o fa5efbdf533c b
|
|
|
|
o 90aeefd03044 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
2022-08-31 05:39:32 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["unsquash"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Cannot unsquash merge commits
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Can unsquash from a merge commit
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["co", "e"]);
|
|
|
|
std::fs::write(repo_path.join("file1"), "e\n").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
Working copy now at: 3217340cb761 merge
|
2022-05-29 06:05:30 +00:00
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2022-12-21 04:47:10 +00:00
|
|
|
@ 3217340cb761
|
2022-05-29 06:05:30 +00:00
|
|
|
|\
|
2022-07-15 18:09:11 +00:00
|
|
|
o | 5658521e0f8b d e?
|
2022-05-29 06:05:30 +00:00
|
|
|
| o 90fe0a96fc90 c e?
|
|
|
|
|/
|
|
|
|
o fa5efbdf533c b
|
|
|
|
o 90aeefd03044 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
e
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unsquash_partial() {
|
|
|
|
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");
|
|
|
|
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
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"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "b"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
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, &["new"]);
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "c"]);
|
2022-05-29 06:05:30 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
|
|
|
|
// Test the setup
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ d989314f3df0 c
|
|
|
|
o 2a2d19a3283f b
|
|
|
|
o 47a1e795d146 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// If we don't make any changes in the diff-editor, the whole change is moved
|
|
|
|
// from the parent
|
|
|
|
let edit_script = test_env.set_up_fake_diff_editor();
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-r", "b", "-i"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
Working copy now at: 37c961d0d1e2 (no description set)
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ 37c961d0d1e2 c
|
|
|
|
o 000af22057b9 b
|
|
|
|
o ee67504598b6 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "a"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Can unsquash only some changes in interactive mode
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
std::fs::write(&edit_script, "reset file1").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["unsquash", "-i"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: a8e8fded1021 (no description set)
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
@ a8e8fded1021 c
|
|
|
|
o 46cc06672a99 b
|
|
|
|
o 47a1e795d146 a
|
|
|
|
o 000000000000
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
b
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "c"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "c"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
c
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
|
|
test_env.jj_cmd_success(
|
|
|
|
repo_path,
|
|
|
|
&["log", "-T", r#"commit_id.short() " " branches"#],
|
|
|
|
)
|
|
|
|
}
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unsquash_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, &["unsquash"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
(no description set)
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// 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, &["unsquash"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
source
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// If the destination 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, &["unsquash"]);
|
|
|
|
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"]);
|
|
|
|
std::fs::write(
|
|
|
|
&edit_script,
|
|
|
|
r#"expect
|
|
|
|
JJ: Enter a description for the combined commit.
|
|
|
|
JJ: Description from the destination commit:
|
|
|
|
destination
|
2022-12-21 04:47:10 +00:00
|
|
|
|
2022-08-28 17:28:53 +00:00
|
|
|
JJ: Description from the source commit:
|
|
|
|
source
|
2022-12-21 04:47:10 +00:00
|
|
|
|
2022-08-28 17:28:53 +00:00
|
|
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
|
|
|
|
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
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// 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"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
source
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
destination
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
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],
|
|
|
|
)
|
|
|
|
}
|