2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-08-30 18:47:38 +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-02-02 07:55:24 +00:00
|
|
|
use crate::common::TestEnvironment;
|
2022-08-30 18:47:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interdiff_basic() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file3"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
|
|
|
// implicit --to
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["interdiff", "--from", "left"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Modified regular file file2:
|
|
|
|
1 1: foo
|
|
|
|
2: bar
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// explicit --to
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["checkout", "@-"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&["interdiff", "--from", "left", "--to", "right"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Modified regular file file2:
|
|
|
|
1 1: foo
|
|
|
|
2: bar
|
|
|
|
"###);
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
|
|
|
// formats specifiers
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&["interdiff", "--from", "left", "--to", "right", "-s"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
M file2
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&["interdiff", "--from", "left", "--to", "right", "--git"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
diff --git a/file2 b/file2
|
|
|
|
index 257cc5642c...3bd1f0e297 100644
|
|
|
|
--- a/file2
|
|
|
|
+++ b/file2
|
|
|
|
@@ -1,1 +1,2 @@
|
|
|
|
foo
|
|
|
|
+bar
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interdiff_paths() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "bar\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "bar\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file1"), "baz\n").unwrap();
|
|
|
|
std::fs::write(repo_path.join("file2"), "baz\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&["interdiff", "--from", "left", "--to", "right", "file1"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Modified regular file file1:
|
|
|
|
1 1: barbaz
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&[
|
|
|
|
"interdiff",
|
|
|
|
"--from",
|
|
|
|
"left",
|
|
|
|
"--to",
|
|
|
|
"right",
|
|
|
|
"file1",
|
|
|
|
"file2",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Modified regular file file1:
|
|
|
|
1 1: barbaz
|
|
|
|
Modified regular file file2:
|
|
|
|
1 1: barbaz
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interdiff_conflicting() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
std::fs::write(repo_path.join("file"), "foo\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file"), "bar\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "left"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["checkout", "root()"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file"), "abc\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["new"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
std::fs::write(repo_path.join("file"), "def\n").unwrap();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "right"]);
|
2022-08-30 18:47:38 +00:00
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(
|
|
|
|
&repo_path,
|
|
|
|
&["interdiff", "--from", "left", "--to", "right", "--git"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
diff --git a/file b/file
|
2023-08-26 20:19:31 +00:00
|
|
|
index 0000000000...24c5735c3e 100644
|
2022-08-30 18:47:38 +00:00
|
|
|
--- a/file
|
|
|
|
+++ b/file
|
2022-09-20 03:31:20 +00:00
|
|
|
@@ -1,7 +1,1 @@
|
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 to side #1
|
2022-08-30 18:47:38 +00:00
|
|
|
--foo
|
|
|
|
-+abc
|
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 #2
|
2022-08-30 18:47:38 +00:00
|
|
|
-bar
|
|
|
|
->>>>>>>
|
|
|
|
+def
|
|
|
|
"###);
|
|
|
|
}
|