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.
|
|
|
|
|
|
2024-06-30 10:02:21 +00:00
|
|
|
|
use std::path::{Path, PathBuf};
|
2022-05-29 23:46:47 +00:00
|
|
|
|
|
2023-07-03 10:04:31 +00:00
|
|
|
|
use crate::common::TestEnvironment;
|
2022-04-07 00:14:12 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 382c9bad7d42 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d5d59175b481 b
|
|
|
|
|
○ 184ddbcce5a9 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 00:14:12 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Squashes the working copy into the parent by default
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: vruxwmqv f7bb78d8 (empty) (no description set)
|
|
|
|
|
Parent commit : kkmpptxz 59f44460 b c | (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###"
|
2024-06-04 23:34:50 +00:00
|
|
|
|
@ f7bb78d8da62 (empty)
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 59f4446070a0 b c
|
|
|
|
|
○ 184ddbcce5a9 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 00:14:12 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2022-04-07 00:14:12 +00:00
|
|
|
|
Rebased 1 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: mzvwutvl 1d70f50a c | (no description set)
|
|
|
|
|
Parent commit : qpvuntsm 9146bcc8 a b | (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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 1d70f50afa6d c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 9146bcc8d996 a b
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 00:14:12 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "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)
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["edit", "b"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
std::fs::write(repo_path.join("file2"), "d\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "c", "d"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
|
2022-05-29 23:46:47 +00:00
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-04 23:34:50 +00:00
|
|
|
|
@ 41219719ab5f e (empty)
|
2023-02-09 02:53:47 +00:00
|
|
|
|
├─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ f86e2b3af3e3 d
|
|
|
|
|
○ │ 382c9bad7d42 c
|
2023-02-09 02:53:47 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d5d59175b481 b
|
|
|
|
|
○ 184ddbcce5a9 a
|
|
|
|
|
◆ 000000000000 (empty)
|
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
|
2024-03-05 05:26:31 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "e"]);
|
2022-04-07 00:14:12 +00:00
|
|
|
|
std::fs::write(repo_path.join("file1"), "e\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: xlzxqlsl b50b843d (empty) (no description set)
|
|
|
|
|
Parent commit : nmzmmopx 338cbc05 e | (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###"
|
2024-06-04 23:34:50 +00:00
|
|
|
|
@ b50b843d8555 (empty)
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 338cbc05e4e6 e
|
2023-02-09 02:53:47 +00:00
|
|
|
|
├─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ f86e2b3af3e3 d
|
|
|
|
|
○ │ 382c9bad7d42 c
|
2023-02-09 02:53:47 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d5d59175b481 b
|
|
|
|
|
○ 184ddbcce5a9 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 00:14:12 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "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();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-04-07 04:53:48 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&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();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&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();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ a0b1a272ebc4 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d117da276a0f b
|
|
|
|
|
○ 54d3c1c0e9fd a
|
|
|
|
|
◆ 000000000000 (empty)
|
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();
|
2024-07-08 13:28:40 +00:00
|
|
|
|
std::fs::write(&edit_script, "dump JJ-INSTRUCTIONS instrs").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "-i"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2022-04-07 04:53:48 +00:00
|
|
|
|
Rebased 1 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: mzvwutvl 3c633226 c | (no description set)
|
|
|
|
|
Parent commit : qpvuntsm 38ffd8b9 a b | (no description set)
|
2022-04-07 04:53:48 +00:00
|
|
|
|
"###);
|
2024-07-08 13:28:40 +00:00
|
|
|
|
|
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
|
std::fs::read_to_string(test_env.env_root().join("instrs")).unwrap(), @r###"
|
|
|
|
|
You are moving changes from: kkmpptxz d117da27 b | (no description set)
|
|
|
|
|
into commit: qpvuntsm 54d3c1c0 a | (no description set)
|
|
|
|
|
|
|
|
|
|
The left side of the diff shows the contents of the parent commit. The
|
|
|
|
|
right side initially shows the contents of the commit you're moving
|
|
|
|
|
changes from.
|
|
|
|
|
|
|
|
|
|
Adjust the right side until the diff shows the changes you want to move
|
|
|
|
|
to the destination. If you don't make any changes, then all the changes
|
|
|
|
|
from the source will be moved into the destination.
|
|
|
|
|
"###);
|
|
|
|
|
|
2022-05-29 23:46:47 +00:00
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 3c6332267ea8 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 38ffd8b98578 a b
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 04:53:48 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2022-04-07 04:53:48 +00:00
|
|
|
|
std::fs::write(&edit_script, "reset file1").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "-i"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-10 21:41:51 +00:00
|
|
|
|
Rebased 2 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: mzvwutvl 57c3cf20 c | (no description set)
|
|
|
|
|
Parent commit : kkmpptxz c4925e01 b | (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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 57c3cf20d0b1 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ c4925e01d298 b
|
|
|
|
|
○ 1fc159063ed3 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-07 04:53:48 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2022-04-09 17:27:17 +00:00
|
|
|
|
// Clear the script so we know it won't be used even without -i
|
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "file2"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-10 21:41:51 +00:00
|
|
|
|
Rebased 2 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: mzvwutvl 64d7ad7c c | (no description set)
|
|
|
|
|
Parent commit : kkmpptxz 60a26452 b | (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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 64d7ad7c43c1 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 60a264527aee b
|
|
|
|
|
○ 7314692d32e3 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2022-04-09 17:27:17 +00:00
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2", "-r", "a"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2", "-r", "b"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
2023-04-29 15:56:31 +00:00
|
|
|
|
|
2024-04-28 22:51:55 +00:00
|
|
|
|
// If we specify only a non-existent file, then nothing changes.
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "nonexistent"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-04-28 22:51:55 +00:00
|
|
|
|
Nothing changed.
|
2023-04-29 15:56:31 +00:00
|
|
|
|
"###);
|
2023-04-29 23:15:38 +00:00
|
|
|
|
|
|
|
|
|
// We get a warning if we pass a positional argument that looks like a revset
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2023-07-03 10:04:31 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "b"]);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-24 06:24:32 +00:00
|
|
|
|
Warning: The argument "b" is being interpreted as a path. To specify a revset, pass -r "b" instead.
|
2024-04-28 22:51:55 +00:00
|
|
|
|
Nothing changed.
|
2023-04-29 23:15:38 +00:00
|
|
|
|
"###);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
2022-04-07 04:53:48 +00:00
|
|
|
|
}
|
2022-05-29 23:46:47 +00:00
|
|
|
|
|
2024-06-04 23:34:50 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_keep_emptied() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
|
@ 382c9bad7d42 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d5d59175b481 b
|
|
|
|
|
○ 184ddbcce5a9 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-06-04 23:34:50 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-r", "b", "--keep-emptied"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 2 descendant commits
|
|
|
|
|
Working copy now at: mzvwutvl 7ee7f18a c | (no description set)
|
|
|
|
|
Parent commit : kkmpptxz 9490bd7f b | (empty) (no description set)
|
|
|
|
|
"###);
|
|
|
|
|
// With --keep-emptied, b remains even though it is now empty.
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
|
|
|
|
@ 7ee7f18a5223 c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 9490bd7f1e6a b (empty)
|
|
|
|
|
○ 53bf93080518 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-06-04 23:34:50 +00:00
|
|
|
|
"###);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "a"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
b
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 18:50:14 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_from_to() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
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.
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
|
|
|
|
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_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
|
|
|
|
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["edit", "a"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
|
|
|
|
|
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
|
|
|
|
|
std::fs::write(repo_path.join("file2"), "e\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "f"]);
|
|
|
|
|
std::fs::write(repo_path.join("file2"), "f\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ a847ab4967fe f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ c2f9de87325d e
|
|
|
|
|
○ e0dac715116f d
|
|
|
|
|
│ ○ 59597b34a0d8 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Errors out if source and destination are the same
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["squash", "--into", "@"]);
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Error: Source and destination cannot be the same
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash from sibling, which results in the source being abandoned
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "--from", "c"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kmkuslsw b902d1dd f | (no description set)
|
|
|
|
|
Parent commit : znkkpsqq c2f9de87 e | (no description set)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ b902d1dd59d9 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ c2f9de87325d e
|
|
|
|
|
○ e0dac715116f d
|
|
|
|
|
│ ○ 12d6103dc0c8 b c
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The change from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
|
|
|
|
// File `file2`, which was not changed in source, is unchanged
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
f
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash from ancestor
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "--from", "@--"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kmkuslsw cfc5eb87 f | (no description set)
|
|
|
|
|
Parent commit : znkkpsqq 4dc7c279 e | (no description set)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The change has been removed from the source (the change pointed to by 'd'
|
|
|
|
|
// became empty and was abandoned)
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ cfc5eb876eb1 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 4dc7c27994bd e
|
|
|
|
|
│ ○ 59597b34a0d8 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a d
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +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)
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
f
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash from descendant
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) =
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "--from", "e", "--into", "d"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 1 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kmkuslsw 6de62c22 f | (no description set)
|
|
|
|
|
Parent commit : vruxwmqv 32196a11 d e | (no description set)
|
2024-03-10 18:50:14 +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###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 6de62c22fa07 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 32196a117ee3 d e
|
|
|
|
|
│ ○ 59597b34a0d8 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The change from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2", "-r", "d"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
e
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_from_to_partial() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
|
// C
|
|
|
|
|
// |
|
|
|
|
|
// D B
|
|
|
|
|
// |/
|
|
|
|
|
// A
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
|
|
|
|
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_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
|
|
|
|
std::fs::write(repo_path.join("file3"), "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
|
|
|
|
|
std::fs::write(repo_path.join("file2"), "c\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["edit", "a"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
|
|
|
|
|
std::fs::write(repo_path.join("file3"), "d\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ e0dac715116f d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ 087591be5a01 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_diff_editor();
|
|
|
|
|
|
|
|
|
|
// If we don't make any changes in the diff-editor, the whole change is moved
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-i", "--from", "c"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: vruxwmqv 987bcfb2 d | (no description set)
|
|
|
|
|
Parent commit : qpvuntsm b7b76717 a | (no description set)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
Added 0 files, modified 2 files, removed 0 files
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 987bcfb2eb62 d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ 12d6103dc0c8 b c
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The changes from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
|
|
|
|
// File `file3`, which was not changed in source, is unchanged
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file3"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
d
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash only part of the change in interactive mode
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
std::fs::write(&edit_script, "reset file2").unwrap();
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "-i", "--from", "c"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: vruxwmqv 576244e8 d | (no description set)
|
|
|
|
|
Parent commit : qpvuntsm b7b76717 a | (no description set)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 576244e87883 d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ 6f486f2f4539 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The selected change from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
|
|
|
|
// The unselected change from the source has not been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
|
|
|
|
// File `file3`, which was changed in source's parent, is unchanged
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file3"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
d
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash only part of the change from a sibling in non-interactive mode
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
// Clear the script so we know it won't be used
|
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "--from", "c", "file1"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: vruxwmqv 5b407c24 d | (no description set)
|
|
|
|
|
Parent commit : qpvuntsm b7b76717 a | (no description set)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
Added 0 files, modified 1 files, removed 0 files
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 5b407c249fa7 d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ 724d64da1487 c
|
|
|
|
|
│ ○ 12d6103dc0c8 b
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The selected change from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
|
|
|
|
// The unselected change from the source has not been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
|
|
|
|
// File `file3`, which was changed in source's parent, is unchanged
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file3"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
d
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Can squash only part of the change from a descendant in non-interactive mode
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
// Clear the script so we know it won't be used
|
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["squash", "--from", "c", "--into", "b", "file1"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 1 descendant commits
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ d2a587ae205d c
|
|
|
|
|
○ a53394306362 b
|
2024-06-23 22:20:33 +00:00
|
|
|
|
│ @ e0dac715116f d
|
2024-03-10 18:50:14 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ b7b767179c44 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The selected change from the source has been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file1", "-r", "b"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
c
|
|
|
|
|
"###);
|
|
|
|
|
// The unselected change from the source has not been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "file2", "-r", "b"]);
|
2024-03-10 18:50:14 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
|
|
|
|
|
2024-04-28 22:51:55 +00:00
|
|
|
|
// If we specify only a non-existent file, then nothing changes.
|
2024-03-10 18:50:14 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) =
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "--from", "c", "nonexistent"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-04-28 22:51:55 +00:00
|
|
|
|
Nothing changed.
|
2024-03-10 18:50:14 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-11 04:46:21 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_from_multiple() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
|
// F
|
|
|
|
|
// |
|
|
|
|
|
// E
|
|
|
|
|
// /|\
|
|
|
|
|
// B C D
|
|
|
|
|
// \|/
|
|
|
|
|
// A
|
|
|
|
|
let file = repo_path.join("file");
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
|
|
|
|
std::fs::write(&file, "a\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
|
|
|
|
std::fs::write(&file, "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
|
|
|
|
|
std::fs::write(&file, "c\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
|
|
|
|
|
std::fs::write(&file, "d\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "all:visible_heads()"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
|
|
|
|
|
std::fs::write(&file, "e\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "f"]);
|
|
|
|
|
std::fs::write(&file, "f\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 94e57ecb8d4f f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 78ed28eb87b8 e
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─┬─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ │ ○ 35e764e4357c b
|
|
|
|
|
│ ○ │ 02a128cd4344 c
|
2024-03-11 04:46:21 +00:00
|
|
|
|
│ ├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ │ aaf7b53a1b64 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 3b1673b6370c a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Squash a few commits sideways
|
2024-04-03 03:25:06 +00:00
|
|
|
|
let (stdout, stderr) =
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "--from=b", "--from=c", "--into=d"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 2 descendant commits
|
|
|
|
|
New conflicts appeared in these commits:
|
2024-06-23 22:20:33 +00:00
|
|
|
|
yqosqzyt 98759deb d | (conflict) (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
To resolve the conflicts, start by updating to it:
|
|
|
|
|
jj new yqosqzytrlsw
|
|
|
|
|
Then use `jj resolve`, or edit the conflict markers in the file directly.
|
2024-07-16 17:30:40 +00:00
|
|
|
|
Once the conflicts are resolved, you may want to inspect the result with `jj diff`.
|
2024-03-11 04:46:21 +00:00
|
|
|
|
Then run `jj squash` to move the resolution into the conflicted commit.
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kpqxywon 3e25ee21 f | (no description set)
|
|
|
|
|
Parent commit : yostqsxw abb5a4ea e | (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 3e25ee211f3f f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ abb5a4ea1222 e
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
× │ 98759debcee5 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 3b1673b6370c a b c
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The changes from the sources have been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=d", "file"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
<<<<<<< Conflict 1 of 1
|
|
|
|
|
%%%%%%% Changes from base #1 to side #1
|
2024-03-11 04:46:21 +00:00
|
|
|
|
-a
|
|
|
|
|
+d
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
%%%%%%% Changes from base #2 to side #2
|
2024-03-11 04:46:21 +00:00
|
|
|
|
-a
|
|
|
|
|
+b
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
+++++++ Contents of side #3
|
2024-03-11 04:46:21 +00:00
|
|
|
|
c
|
2024-05-16 01:00:50 +00:00
|
|
|
|
>>>>>>> Conflict 1 of 1 ends
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Squash a few commits up an down
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "--from=b|c|f", "--into=e"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 1 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: xznxytkn 6a670d1a (empty) (no description set)
|
|
|
|
|
Parent commit : yostqsxw c1293ff7 e f | (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-04 23:34:50 +00:00
|
|
|
|
@ 6a670d1ac76e (empty)
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ c1293ff7be51 e f
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ │ aaf7b53a1b64 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 3b1673b6370c a b c
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The changes from the sources have been applied to the destination
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=e", "file"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
f
|
|
|
|
|
"###);
|
2024-04-03 03:25:06 +00:00
|
|
|
|
|
2024-04-28 22:51:55 +00:00
|
|
|
|
// Empty squash shouldn't crash
|
2024-04-03 03:25:06 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash", "--from=none()"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-04-28 22:51:55 +00:00
|
|
|
|
Nothing changed.
|
2024-04-03 03:25:06 +00:00
|
|
|
|
"###);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_from_multiple_partial() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
|
// F
|
|
|
|
|
// |
|
|
|
|
|
// E
|
|
|
|
|
// /|\
|
|
|
|
|
// B C D
|
|
|
|
|
// \|/
|
|
|
|
|
// A
|
|
|
|
|
let file1 = repo_path.join("file1");
|
|
|
|
|
let file2 = repo_path.join("file2");
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "a"]);
|
|
|
|
|
std::fs::write(&file1, "a\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "a\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "b"]);
|
|
|
|
|
std::fs::write(&file1, "b\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "c"]);
|
|
|
|
|
std::fs::write(&file1, "c\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "c\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "d"]);
|
|
|
|
|
std::fs::write(&file1, "d\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "d\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "all:visible_heads()"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "e"]);
|
|
|
|
|
std::fs::write(&file1, "e\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "e\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "f"]);
|
|
|
|
|
std::fs::write(&file1, "f\n").unwrap();
|
|
|
|
|
std::fs::write(&file2, "f\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 30980b9045f7 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 5326a04aac1f e
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─┬─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ │ ○ d117da276a0f b
|
|
|
|
|
│ ○ │ 93a7bfff61e7 c
|
2024-03-11 04:46:21 +00:00
|
|
|
|
│ ├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ │ 763809ca0131 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 54d3c1c0e9fd a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Partially squash a few commits sideways
|
|
|
|
|
let (stdout, stderr) =
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "--from=b|c", "--into=d", "file1"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 2 descendant commits
|
|
|
|
|
New conflicts appeared in these commits:
|
2024-06-23 22:20:33 +00:00
|
|
|
|
yqosqzyt b91b1157 d | (conflict) (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
To resolve the conflicts, start by updating to it:
|
|
|
|
|
jj new yqosqzytrlsw
|
|
|
|
|
Then use `jj resolve`, or edit the conflict markers in the file directly.
|
2024-07-16 17:30:40 +00:00
|
|
|
|
Once the conflicts are resolved, you may want to inspect the result with `jj diff`.
|
2024-03-11 04:46:21 +00:00
|
|
|
|
Then run `jj squash` to move the resolution into the conflicted commit.
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kpqxywon 056dc38b f | (no description set)
|
|
|
|
|
Parent commit : yostqsxw 45069475 e | (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 056dc38bf286 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 450694753699 e
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─┬─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ │ ○ 450d1499c1ae b
|
|
|
|
|
│ ○ │ 14b44bf0473c c
|
2024-03-11 04:46:21 +00:00
|
|
|
|
│ ├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
× │ b91b11575906 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 54d3c1c0e9fd a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The selected changes have been removed from the sources
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=b", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=c", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
|
|
|
|
// The selected changes from the sources have been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=d", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
<<<<<<< Conflict 1 of 1
|
|
|
|
|
%%%%%%% Changes from base #1 to side #1
|
2024-03-11 04:46:21 +00:00
|
|
|
|
-a
|
|
|
|
|
+d
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
%%%%%%% Changes from base #2 to side #2
|
2024-03-11 04:46:21 +00:00
|
|
|
|
-a
|
|
|
|
|
+b
|
conflicts.rs: label conflict number and sides next to conflict markers
For example,
```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```
or
```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```
Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.
Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.
While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.
I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.
Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-03-23 22:16:28 +00:00
|
|
|
|
+++++++ Contents of side #3
|
2024-03-11 04:46:21 +00:00
|
|
|
|
c
|
2024-05-16 01:00:50 +00:00
|
|
|
|
>>>>>>> Conflict 1 of 1 ends
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The unselected change from the sources have not been applied to the
|
|
|
|
|
// destination
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=d", "file2"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
d
|
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Partially squash a few commits up an down
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) =
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "--from=b|c|f", "--into=e", "file1"]);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
|
Rebased 1 descendant commits
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kpqxywon 3b7559b8 f | (no description set)
|
|
|
|
|
Parent commit : yostqsxw a3b1714c e | (no description set)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 3b7559b89a57 f
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ a3b1714cdfb2 e
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─┬─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ │ ○ 867efb38e801 b
|
|
|
|
|
│ ○ │ 84dcb3d4b3eb c
|
2024-03-11 04:46:21 +00:00
|
|
|
|
│ ├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ │ 763809ca0131 d
|
2024-03-11 04:46:21 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 54d3c1c0e9fd a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-03-11 04:46:21 +00:00
|
|
|
|
"###);
|
|
|
|
|
// The selected changes have been removed from the sources
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=b", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=c", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
a
|
|
|
|
|
"###);
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=f", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
f
|
|
|
|
|
"###);
|
|
|
|
|
// The selected changes from the sources have been applied to the destination
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=e", "file1"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
f
|
|
|
|
|
"###);
|
|
|
|
|
// The unselected changes from the sources have not been applied
|
2024-06-26 01:17:11 +00:00
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "show", "-r=d", "file2"]);
|
2024-03-11 04:46:21 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
|
d
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 18:06:18 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_from_multiple_partial_no_op() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-04-28 18:06:18 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
// Create history like this:
|
|
|
|
|
// B C D
|
|
|
|
|
// \|/
|
|
|
|
|
// A
|
|
|
|
|
let file_a = repo_path.join("a");
|
|
|
|
|
let file_b = repo_path.join("b");
|
|
|
|
|
let file_c = repo_path.join("c");
|
|
|
|
|
let file_d = repo_path.join("d");
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=a"]);
|
|
|
|
|
std::fs::write(file_a, "a\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "-m=b"]);
|
|
|
|
|
std::fs::write(file_b, "b\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=c"]);
|
|
|
|
|
std::fs::write(file_c, "c\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new", "@-", "-m=d"]);
|
|
|
|
|
std::fs::write(file_d, "d\n").unwrap();
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ b37ca1ee3306 d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ f40b442af3e8 c
|
2024-04-28 18:06:18 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ b73077b08c59 b
|
2024-04-28 18:06:18 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 2443ea76b0b1 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-04-28 18:06:18 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Source commits that didn't match the paths are not rewritten
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "b"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: mzvwutvl e178068a d
|
|
|
|
|
Parent commit : qpvuntsm 2443ea76 a
|
2024-04-28 18:06:18 +00:00
|
|
|
|
Added 1 files, modified 0 files, removed 0 files
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ e178068add8c d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ f40b442af3e8 c
|
2024-04-28 18:06:18 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 2443ea76b0b1 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-04-28 18:06:18 +00:00
|
|
|
|
"###);
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"obslog",
|
|
|
|
|
"-T",
|
|
|
|
|
r#"separate(" ", commit_id.short(), description)"#,
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ e178068add8c d
|
2024-04-29 15:56:51 +00:00
|
|
|
|
├─╮
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ b73077b08c59 b
|
|
|
|
|
│ ○ a786561e909f b
|
|
|
|
|
○ b37ca1ee3306 d
|
|
|
|
|
○ 1d9eb34614c9 d
|
2024-04-28 18:06:18 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// If no source commits match the paths, then the whole operation is a no-op
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&["squash", "--from=@-+ ~ @", "--into=@", "-m=d", "a"],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-04-28 22:51:55 +00:00
|
|
|
|
Nothing changed.
|
2024-04-28 18:06:18 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ b37ca1ee3306 d
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ f40b442af3e8 c
|
2024-04-28 18:06:18 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
│ ○ b73077b08c59 b
|
2024-04-28 18:06:18 +00:00
|
|
|
|
├─╯
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 2443ea76b0b1 a
|
|
|
|
|
◆ 000000000000 (empty)
|
2024-04-28 18:06:18 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 23:46:47 +00:00
|
|
|
|
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
2024-06-04 23:34:50 +00:00
|
|
|
|
let template = r#"separate(
|
|
|
|
|
" ",
|
|
|
|
|
commit_id.short(),
|
|
|
|
|
branches,
|
|
|
|
|
description,
|
|
|
|
|
if(empty, "(empty)")
|
|
|
|
|
)"#;
|
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();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
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();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
|
|
|
|
|
std::fs::write(repo_path.join("file2"), "b\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["op", "restore", "@--"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "@-", "-m", "destination"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "-m", "custom"]);
|
2023-04-03 22:16:23 +00:00
|
|
|
|
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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
|
2022-12-22 07:58:23 +00:00
|
|
|
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
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
|
|
|
|
|
|
2024-03-11 16:30:56 +00:00
|
|
|
|
JJ: Description from source commit:
|
2022-12-22 07:58:23 +00:00
|
|
|
|
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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "-m", "custom"]);
|
2023-04-03 22:16:23 +00:00
|
|
|
|
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
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "file1"]);
|
2022-08-28 17:28:53 +00:00
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
|
destination
|
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
|
|
|
|
source
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 10:02:21 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_description_editor_avoids_unc() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
|
|
|
|
|
std::fs::write(repo_path.join("file2"), "a\n").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&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_ok(&repo_path, &["describe", "@-", "-m", "destination"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "source"]);
|
|
|
|
|
|
|
|
|
|
std::fs::write(edit_script, "dump-path path").unwrap();
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
|
|
|
|
|
|
|
|
|
let edited_path =
|
|
|
|
|
PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path")).unwrap());
|
|
|
|
|
// While `assert!(!edited_path.starts_with("//?/"))` could work here in most
|
|
|
|
|
// cases, it fails when it is not safe to strip the prefix, such as paths
|
|
|
|
|
// over 260 chars.
|
|
|
|
|
assert_eq!(edited_path, dunce::simplified(&edited_path));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-24 09:21:02 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_empty() {
|
|
|
|
|
let mut test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2023-01-24 09:21:02 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "parent"]);
|
2023-01-24 09:21:02 +00:00
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2023-10-10 11:07:06 +00:00
|
|
|
|
insta::assert_snapshot!(stdout, @"");
|
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
Working copy now at: kkmpptxz adece6e8 (empty) (no description set)
|
|
|
|
|
Parent commit : qpvuntsm 5076fc41 (empty) parent
|
2023-01-24 09:21:02 +00:00
|
|
|
|
"###);
|
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
|
parent
|
|
|
|
|
"###);
|
|
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "child"]);
|
2023-01-24 09:21:02 +00:00
|
|
|
|
test_env.set_up_fake_editor();
|
2023-10-10 11:59:18 +00:00
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash"]);
|
2023-01-24 09:21:02 +00:00
|
|
|
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
|
|
|
|
parent
|
|
|
|
|
|
|
|
|
|
child
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 15:19:12 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_use_destination_message() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-04-02 15:19:12 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=a"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=b"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=c"]);
|
|
|
|
|
// Test the setup
|
|
|
|
|
insta::assert_snapshot!(get_log_output_with_description(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 8aac283daeac c
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 017c7f689ed7 b
|
|
|
|
|
○ d8d5f980a897 a
|
|
|
|
|
◆ 000000000000
|
2024-04-02 15:19:12 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Squash the current revision using the short name for the option.
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["squash", "-u"]);
|
|
|
|
|
insta::assert_snapshot!(get_log_output_with_description(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ fd33e4bc332b
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 3a17aa5dcce9 b
|
|
|
|
|
○ d8d5f980a897 a
|
|
|
|
|
◆ 000000000000
|
2024-04-02 15:19:12 +00:00
|
|
|
|
"###);
|
|
|
|
|
|
|
|
|
|
// Undo and squash again, but this time squash both "b" and "c" into "a".
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
|
|
|
|
test_env.jj_cmd_ok(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"squash",
|
|
|
|
|
"--use-destination-message",
|
|
|
|
|
"--from",
|
|
|
|
|
"description(b)::",
|
|
|
|
|
"--into",
|
|
|
|
|
"description(a)",
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
insta::assert_snapshot!(get_log_output_with_description(&test_env, &repo_path), @r###"
|
2024-06-23 22:20:33 +00:00
|
|
|
|
@ 7c832accbf60
|
2024-07-15 22:20:10 +00:00
|
|
|
|
○ 688660377651 a
|
|
|
|
|
◆ 000000000000
|
2024-04-02 15:19:12 +00:00
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The --use-destination-message and --message options are incompatible.
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_squash_use_destination_message_and_message_mutual_exclusion() {
|
|
|
|
|
let test_env = TestEnvironment::default();
|
2024-05-17 19:49:25 +00:00
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
2024-04-02 15:19:12 +00:00
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["commit", "-m=a"]);
|
|
|
|
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m=b"]);
|
|
|
|
|
insta::assert_snapshot!(test_env.jj_cmd_cli_error(
|
|
|
|
|
&repo_path,
|
|
|
|
|
&[
|
|
|
|
|
"squash",
|
|
|
|
|
"--message=123",
|
|
|
|
|
"--use-destination-message",
|
|
|
|
|
],
|
|
|
|
|
), @r###"
|
|
|
|
|
error: the argument '--message <MESSAGE>' cannot be used with '--use-destination-message'
|
|
|
|
|
|
|
|
|
|
Usage: jj squash --message <MESSAGE> [PATHS]...
|
|
|
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
|
"###);
|
|
|
|
|
}
|
|
|
|
|
|
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],
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-04-02 15:19:12 +00:00
|
|
|
|
|
|
|
|
|
fn get_log_output_with_description(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
|
|
|
let template = r#"separate(" ", commit_id.short(), description)"#;
|
|
|
|
|
test_env.jj_cmd_success(repo_path, &["log", "-T", template])
|
|
|
|
|
}
|