2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-04-07 00:14:12 +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-05-29 23:46:47 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2022-04-07 00:14:12 +00:00
|
|
|
use crate::common::TestEnvironment;
|
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_squash() {
|
|
|
|
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-04-07 00:14:12 +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-04-07 00:14:12 +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-04-07 00:14:12 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
// Test the setup
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 90fe0a96fc90 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ fa5efbdf533c b
|
|
|
|
◉ 90aeefd03044 a
|
|
|
|
◉ 000000000000
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
// Squashes the working copy into the parent by default
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-08-28 17:28:53 +00:00
|
|
|
Working copy now at: b9280a9898cb (no description set)
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ b9280a9898cb
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 6ca29c9d2e7c b c
|
|
|
|
◉ 90aeefd03044 a
|
|
|
|
◉ 000000000000
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
|
|
|
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-07 00:14:12 +00:00
|
|
|
|
|
|
|
// Can squash a given commit into its parent
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: e87cf8ebc7e1 (no description set)
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ e87cf8ebc7e1 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 893c93ae2a87 a b
|
|
|
|
◉ 000000000000
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
|
|
|
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###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-07 00:14:12 +00:00
|
|
|
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-07 00:14:12 +00:00
|
|
|
|
|
|
|
// Cannot squash a merge commit (because it's unclear which parent it should go
|
|
|
|
// into)
|
|
|
|
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-04-07 00:14:12 +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-07 00:14:12 +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", "c", "d"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "e"]);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ c7a11b36d333 e
|
|
|
|
├─╮
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ 5658521e0f8b d
|
|
|
|
│ ◉ 90fe0a96fc90 c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ fa5efbdf533c b
|
|
|
|
◉ 90aeefd03044 a
|
|
|
|
◉ 000000000000
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
2022-08-31 05:39:32 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["squash"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Cannot squash merge commits
|
|
|
|
"###);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
|
|
|
// Can squash into 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, &["squash"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2022-08-31 05:39:32 +00:00
|
|
|
Working copy now at: 959145c11426 (no description set)
|
2022-04-28 23:32:18 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ 959145c11426
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 80960125bb96 e
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╮
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ │ 5658521e0f8b d
|
|
|
|
│ ◉ 90fe0a96fc90 c
|
2023-02-09 02:53:47 +00:00
|
|
|
├─╯
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ fa5efbdf533c b
|
|
|
|
◉ 90aeefd03044 a
|
|
|
|
◉ 000000000000
|
2022-04-07 00:14:12 +00:00
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "e"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
e
|
|
|
|
"###);
|
2022-04-07 00:14:12 +00:00
|
|
|
}
|
2022-04-07 04:53:48 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-04-09 17:27:17 +00:00
|
|
|
fn test_squash_partial() {
|
2022-04-07 04:53:48 +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");
|
|
|
|
|
2022-06-06 03:23:01 +00:00
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "a"]);
|
2022-04-07 04:53:48 +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-04-07 04:53:48 +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-04-07 04:53:48 +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
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ d989314f3df0 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 2a2d19a3283f b
|
|
|
|
◉ 47a1e795d146 a
|
|
|
|
◉ 000000000000
|
2022-04-07 04:53:48 +00:00
|
|
|
"###);
|
|
|
|
|
2022-04-09 17:27:17 +00:00
|
|
|
// If we don't make any changes in the diff-editor, the whole change is moved
|
|
|
|
// into the parent
|
2022-04-07 04:53:48 +00:00
|
|
|
let edit_script = test_env.set_up_fake_diff_editor();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "-i"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: f03d5ce4a973 (no description set)
|
2022-04-07 04:53:48 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ f03d5ce4a973 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ c9f931cd78af a b
|
|
|
|
◉ 000000000000
|
2022-04-07 04:53:48 +00:00
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-07 04:53:48 +00:00
|
|
|
|
2022-04-09 17:27:17 +00:00
|
|
|
// Can squash only some changes in interactive mode
|
2022-04-07 04:53:48 +00:00
|
|
|
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, &["squash", "-r", "b", "-i"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: e7a40106bee6 (no description set)
|
2022-04-07 04:53:48 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ e7a40106bee6 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ 05d951646873 b
|
|
|
|
◉ 0c5ddc685260 a
|
|
|
|
◉ 000000000000
|
2022-04-07 04:53:48 +00:00
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
2022-04-07 04:53:48 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-07 04:53:48 +00:00
|
|
|
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###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-07 04:53:48 +00:00
|
|
|
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###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-09 17:27:17 +00:00
|
|
|
|
|
|
|
// Can squash only some changes in non-interactive mode
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
// Clear the script so we know it won't be used even without -i
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["squash", "-r", "b", "file2"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Rebased 1 descendant commits
|
2022-05-17 17:22:46 +00:00
|
|
|
Working copy now at: a911fa1d0627 (no description set)
|
2022-04-09 17:27:17 +00:00
|
|
|
"###);
|
2022-05-29 23:46:47 +00:00
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2023-02-09 02:53:47 +00:00
|
|
|
@ a911fa1d0627 c
|
2023-03-15 03:37:56 +00:00
|
|
|
◉ fb73ad17899f b
|
|
|
|
◉ 70621f4c7a42 a
|
|
|
|
◉ 000000000000
|
2022-04-09 17:27:17 +00:00
|
|
|
"###);
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
a
|
|
|
|
"###);
|
2022-04-09 17:27:17 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-09 17:27:17 +00:00
|
|
|
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###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-09 17:27:17 +00:00
|
|
|
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###"
|
|
|
|
b
|
|
|
|
"###);
|
2022-04-07 04:53:48 +00:00
|
|
|
}
|
2022-05-29 23:46:47 +00:00
|
|
|
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &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(repo_path, &["log", "-T", template])
|
2022-05-29 23:46:47 +00:00
|
|
|
}
|
2022-08-28 17:28:53 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_squash_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, &["squash"]);
|
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, &["squash"]);
|
|
|
|
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, &["squash"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
destination
|
|
|
|
"###);
|
|
|
|
|
2023-04-03 22:16:23 +00:00
|
|
|
// An explicit description on the command-line overrides this
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
custom
|
|
|
|
"###);
|
|
|
|
|
2022-08-28 17:28:53 +00:00
|
|
|
// 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, &["squash"]);
|
|
|
|
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
|
|
|
|
2023-04-03 22:16:23 +00:00
|
|
|
// An explicit description on the command-line overrides prevents launching an
|
|
|
|
// editor
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["squash", "-m", "custom"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
custom
|
|
|
|
"###);
|
|
|
|
|
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"]);
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["squash", "file1"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
destination
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
source
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-01-24 09:21:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_squash_empty() {
|
|
|
|
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");
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "parent"]);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["squash"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: e45abe2cd9a9 (no description set)
|
|
|
|
"###);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
parent
|
|
|
|
"###);
|
|
|
|
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "child"]);
|
|
|
|
test_env.set_up_fake_editor();
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["squash"]);
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
parent
|
|
|
|
|
|
|
|
child
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-08-28 17:28:53 +00:00
|
|
|
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],
|
|
|
|
)
|
|
|
|
}
|