2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2021 The Jujutsu Authors
|
2021-10-13 19:53:35 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
use jujutsu_lib::backend::{Conflict, ConflictPart, TreeValue};
|
2021-10-29 03:55:36 +00:00
|
|
|
use jujutsu_lib::conflicts::{materialize_conflict, parse_conflict, update_conflict_from_content};
|
2022-10-30 21:26:07 +00:00
|
|
|
use jujutsu_lib::files::{ConflictHunk, MergeHunk};
|
2021-10-13 19:53:35 +00:00
|
|
|
use jujutsu_lib::repo_path::RepoPath;
|
2022-07-10 18:01:48 +00:00
|
|
|
use jujutsu_lib::store::Store;
|
2022-11-08 12:35:16 +00:00
|
|
|
use testutils::TestRepo;
|
2021-10-13 19:53:35 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_materialize_conflict_basic() {
|
2022-05-21 18:20:51 +00:00
|
|
|
let test_repo = TestRepo::init(false);
|
2022-02-05 23:34:27 +00:00
|
|
|
let store = test_repo.repo.store();
|
2021-10-13 19:53:35 +00:00
|
|
|
|
|
|
|
let path = RepoPath::from_internal_string("file");
|
|
|
|
let base_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let left_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
2022-07-10 17:36:45 +00:00
|
|
|
left 3.1
|
|
|
|
left 3.2
|
|
|
|
left 3.3
|
2021-10-13 19:53:35 +00:00
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let right_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
2022-07-10 17:36:45 +00:00
|
|
|
right 3.1
|
2021-10-13 19:53:35 +00:00
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
2022-07-10 17:36:45 +00:00
|
|
|
let mut conflict = Conflict {
|
2021-10-13 19:53:35 +00:00
|
|
|
removes: vec![ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: base_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
adds: vec![
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: left_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: right_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-07-10 18:01:48 +00:00
|
|
|
insta::assert_snapshot!(
|
|
|
|
&materialize_conflict_string(store, &path, &conflict),
|
|
|
|
@r###"
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
2022-07-10 18:01:48 +00:00
|
|
|
-line 3
|
2022-07-10 17:36:45 +00:00
|
|
|
+right 3.1
|
|
|
|
+++++++
|
|
|
|
left 3.1
|
|
|
|
left 3.2
|
|
|
|
left 3.3
|
|
|
|
>>>>>>>
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
// Test with the larger diff first. We still want the small diff.
|
|
|
|
conflict.adds.reverse();
|
|
|
|
insta::assert_snapshot!(
|
|
|
|
&materialize_conflict_string(store, &path, &conflict),
|
|
|
|
@r###"
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
2022-07-10 17:36:45 +00:00
|
|
|
-line 3
|
|
|
|
+right 3.1
|
2022-07-10 18:01:48 +00:00
|
|
|
+++++++
|
2022-07-10 17:36:45 +00:00
|
|
|
left 3.1
|
|
|
|
left 3.2
|
|
|
|
left 3.3
|
2022-07-10 18:01:48 +00:00
|
|
|
>>>>>>>
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
"###
|
2021-10-13 19:53:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_materialize_conflict_modify_delete() {
|
2022-05-21 18:20:51 +00:00
|
|
|
let test_repo = TestRepo::init(false);
|
2022-02-05 23:34:27 +00:00
|
|
|
let store = test_repo.repo.store();
|
2021-10-13 19:53:35 +00:00
|
|
|
|
|
|
|
let path = RepoPath::from_internal_string("file");
|
|
|
|
let base_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let left_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
left
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let right_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
let conflict = Conflict {
|
|
|
|
removes: vec![ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: base_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
adds: vec![
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: left_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: right_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-07-10 18:01:48 +00:00
|
|
|
insta::assert_snapshot!(&materialize_conflict_string(store, &path, &conflict), @r###"
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
2022-07-10 18:01:48 +00:00
|
|
|
-line 3
|
|
|
|
+++++++
|
2022-07-10 17:36:45 +00:00
|
|
|
left
|
2022-07-10 18:01:48 +00:00
|
|
|
>>>>>>>
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
"###
|
2021-10-13 19:53:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_materialize_conflict_delete_modify() {
|
2022-05-21 18:20:51 +00:00
|
|
|
let test_repo = TestRepo::init(false);
|
2022-02-05 23:34:27 +00:00
|
|
|
let store = test_repo.repo.store();
|
2021-10-13 19:53:35 +00:00
|
|
|
|
|
|
|
let path = RepoPath::from_internal_string("file");
|
|
|
|
let base_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let left_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
let right_id = testutils::write_file(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-13 19:53:35 +00:00
|
|
|
&path,
|
|
|
|
"line 1
|
|
|
|
line 2
|
|
|
|
right
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
let conflict = Conflict {
|
|
|
|
removes: vec![ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: base_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
adds: vec![
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: left_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-13 19:53:35 +00:00
|
|
|
id: right_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2022-07-10 18:01:48 +00:00
|
|
|
insta::assert_snapshot!(
|
|
|
|
&materialize_conflict_string(store, &path, &conflict),
|
|
|
|
@r###"
|
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
2022-07-10 18:01:48 +00:00
|
|
|
-line 3
|
|
|
|
+++++++
|
|
|
|
right
|
|
|
|
>>>>>>>
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
"###
|
2021-10-13 19:53:35 +00:00
|
|
|
);
|
|
|
|
}
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_resolved() {
|
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
line 2
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
1,
|
|
|
|
2
|
|
|
|
),
|
|
|
|
None
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_simple() {
|
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
line 2
|
|
|
|
-line 3
|
|
|
|
+left
|
|
|
|
line 4
|
|
|
|
+++++++
|
|
|
|
right
|
|
|
|
>>>>>>>
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
1,
|
|
|
|
2
|
|
|
|
),
|
|
|
|
Some(vec![
|
|
|
|
MergeHunk::Resolved(b"line 1\n".to_vec()),
|
2022-10-30 21:26:07 +00:00
|
|
|
MergeHunk::Conflict(ConflictHunk {
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
removes: vec![b"line 2\nline 3\nline 4\n".to_vec()],
|
|
|
|
adds: vec![b"line 2\nleft\nline 4\n".to_vec(), b"right\n".to_vec()]
|
2022-10-30 21:26:07 +00:00
|
|
|
}),
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
MergeHunk::Resolved(b"line 5\n".to_vec())
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_multi_way() {
|
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
line 2
|
|
|
|
-line 3
|
|
|
|
+left
|
|
|
|
line 4
|
|
|
|
+++++++
|
|
|
|
right
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
line 2
|
|
|
|
+forward
|
|
|
|
line 3
|
|
|
|
line 4
|
|
|
|
>>>>>>>
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
2,
|
|
|
|
3
|
|
|
|
),
|
|
|
|
Some(vec![
|
|
|
|
MergeHunk::Resolved(b"line 1\n".to_vec()),
|
2022-10-30 21:26:07 +00:00
|
|
|
MergeHunk::Conflict(ConflictHunk {
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
removes: vec![
|
|
|
|
b"line 2\nline 3\nline 4\n".to_vec(),
|
|
|
|
b"line 2\nline 3\nline 4\n".to_vec()
|
|
|
|
],
|
|
|
|
adds: vec![
|
|
|
|
b"line 2\nleft\nline 4\n".to_vec(),
|
|
|
|
b"right\n".to_vec(),
|
|
|
|
b"line 2\nforward\nline 3\nline 4\n".to_vec()
|
|
|
|
]
|
2022-10-30 21:26:07 +00:00
|
|
|
}),
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
MergeHunk::Resolved(b"line 5\n".to_vec())
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_different_wrong_arity() {
|
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
line 2
|
|
|
|
-line 3
|
|
|
|
+left
|
|
|
|
line 4
|
|
|
|
+++++++
|
|
|
|
right
|
|
|
|
>>>>>>>
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
2,
|
|
|
|
3
|
|
|
|
),
|
|
|
|
None
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_malformed_marker() {
|
2022-09-20 03:31:20 +00:00
|
|
|
// The conflict marker is missing `%%%%%%%`
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
<<<<<<<
|
|
|
|
line 2
|
|
|
|
-line 3
|
|
|
|
+left
|
|
|
|
line 4
|
|
|
|
+++++++
|
|
|
|
right
|
|
|
|
>>>>>>>
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
1,
|
|
|
|
2
|
|
|
|
),
|
|
|
|
None
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse_conflict_malformed_diff() {
|
|
|
|
// The diff part is invalid (missing space before "line 4")
|
|
|
|
assert_eq!(
|
|
|
|
parse_conflict(
|
|
|
|
b"line 1
|
|
|
|
<<<<<<<
|
2022-09-20 03:31:20 +00:00
|
|
|
%%%%%%%
|
conflicts: add a function for parsing a materialized conflict
I initially made the working copy materialize conflicts in its
`check_out()` method. Then I changed it later (exactly a year ago, on
Halloween of 2020, actually) so that the working copy expected
conflicts to already have been materalized, which happens in
`MutableRepo::check_out`().
I think my reasoning then was that the file system cannot represent a
conflict. While it's true that the file system itself doesn't have
information to know whether a file represents a conflict, we can
record that ourselves. We already record whether a file is executable
or not and then preserve that if we're on a file system that isn't
able to record it. It's not that different to do the same for
conflicts if we're on a file system that doesn't understand conflicts
(i.e. all file systems).
The plan is to have the working copy remember whether a file
represents a conflict. When we check if it has changed, we parse the
file, including conflict markers, and recreate the conflict from
it. We should be able to do that losslessly (and we should adjust
formats to make it possible if we find cases where it's not).
Having the working copy preserve conflict states has several
advantages:
* Because conflicts are not materialized in the working copy, you can
rebase the conflicted commit and the working copy without causing
more conflicts (that's currently a UX bug I run into every now and
then).
* If you don't change anything in the working copy, it will be
unchanged compared to its parent, which means we'll automatically
abandon it if you update away from it.
* The user can choose to resolve only some of the conflicts in a file
and squash those in, and it'll work they way you'd hope.
* It should make it easier to implement support for external merge
tools (#18) without having them treat the working copy differently.
This patch prepares for that work by adding support for parsing
materialized conflicts.
2021-10-31 18:57:12 +00:00
|
|
|
line 2
|
|
|
|
-line 3
|
|
|
|
+left
|
|
|
|
line 4
|
|
|
|
+++++++
|
|
|
|
right
|
|
|
|
>>>>>>>
|
|
|
|
line 5
|
|
|
|
",
|
|
|
|
1,
|
|
|
|
2
|
|
|
|
),
|
|
|
|
None
|
|
|
|
)
|
|
|
|
}
|
2021-10-29 03:55:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_update_conflict_from_content() {
|
2022-05-21 18:20:51 +00:00
|
|
|
let test_repo = TestRepo::init(false);
|
2022-02-05 23:34:27 +00:00
|
|
|
let store = test_repo.repo.store();
|
2021-10-29 03:55:36 +00:00
|
|
|
|
|
|
|
let path = RepoPath::from_internal_string("dir/file");
|
2021-11-21 07:46:54 +00:00
|
|
|
let base_file_id = testutils::write_file(store, &path, "line 1\nline 2\nline 3\n");
|
|
|
|
let left_file_id = testutils::write_file(store, &path, "left 1\nline 2\nleft 3\n");
|
|
|
|
let right_file_id = testutils::write_file(store, &path, "right 1\nline 2\nright 3\n");
|
2021-10-29 03:55:36 +00:00
|
|
|
let conflict = Conflict {
|
|
|
|
removes: vec![ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: base_file_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
adds: vec![
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: left_file_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: right_file_id,
|
|
|
|
executable: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2022-03-31 16:21:50 +00:00
|
|
|
let conflict_id = store.write_conflict(&path, &conflict).unwrap();
|
2021-10-29 03:55:36 +00:00
|
|
|
|
|
|
|
// If the content is unchanged compared to the materialized value, we get the
|
|
|
|
// old conflict id back.
|
|
|
|
let mut materialized = vec![];
|
2021-11-21 07:46:54 +00:00
|
|
|
materialize_conflict(store, &path, &conflict, &mut materialized).unwrap();
|
|
|
|
let result = update_conflict_from_content(store, &path, &conflict_id, &materialized).unwrap();
|
2021-10-29 03:55:36 +00:00
|
|
|
assert_eq!(result, Some(conflict_id.clone()));
|
|
|
|
|
|
|
|
// If the conflict is resolved, we None back to indicate that.
|
|
|
|
let result = update_conflict_from_content(
|
2021-11-21 07:46:54 +00:00
|
|
|
store,
|
2021-10-29 03:55:36 +00:00
|
|
|
&path,
|
|
|
|
&conflict_id,
|
|
|
|
b"resolved 1\nline 2\nresolved 3\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(result, None);
|
|
|
|
|
|
|
|
// If the conflict is partially resolved, we get a new conflict back.
|
2022-09-20 03:31:20 +00:00
|
|
|
let result = update_conflict_from_content(
|
|
|
|
store,
|
|
|
|
&path,
|
|
|
|
&conflict_id,
|
|
|
|
b"resolved 1\nline 2\n<<<<<<<\n%%%%%%%\n-line 3\n+left 3\n+++++++\nright 3\n>>>>>>>\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
2021-10-29 03:55:36 +00:00
|
|
|
assert_ne!(result, None);
|
|
|
|
assert_ne!(result, Some(conflict_id));
|
2022-03-31 16:21:50 +00:00
|
|
|
let new_conflict = store.read_conflict(&path, &result.unwrap()).unwrap();
|
2021-10-29 03:55:36 +00:00
|
|
|
// Calculate expected new FileIds
|
2021-11-21 07:46:54 +00:00
|
|
|
let new_base_file_id = testutils::write_file(store, &path, "resolved 1\nline 2\nline 3\n");
|
|
|
|
let new_left_file_id = testutils::write_file(store, &path, "resolved 1\nline 2\nleft 3\n");
|
|
|
|
let new_right_file_id = testutils::write_file(store, &path, "resolved 1\nline 2\nright 3\n");
|
2021-10-29 03:55:36 +00:00
|
|
|
assert_eq!(
|
|
|
|
new_conflict,
|
|
|
|
Conflict {
|
|
|
|
removes: vec![ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: new_base_file_id,
|
|
|
|
executable: false
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
adds: vec![
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: new_left_file_id,
|
|
|
|
executable: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ConflictPart {
|
2022-11-14 21:27:18 +00:00
|
|
|
value: TreeValue::File {
|
2021-10-29 03:55:36 +00:00
|
|
|
id: new_right_file_id,
|
|
|
|
executable: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2022-07-10 18:01:48 +00:00
|
|
|
|
|
|
|
fn materialize_conflict_string(store: &Store, path: &RepoPath, conflict: &Conflict) -> String {
|
|
|
|
let mut result: Vec<u8> = vec![];
|
|
|
|
materialize_conflict(store, path, conflict, &mut result).unwrap();
|
|
|
|
String::from_utf8(result).unwrap()
|
|
|
|
}
|