Skip to content

Commit 8502808

Browse files
authored
Merge pull request #12617 from Alizter/push-zrukywltvqwr
feat(cram): detect diff3 and jujutsu conflicts
2 parents f6a4b55 + 8b96fb0 commit 8502808

File tree

4 files changed

+203
-4
lines changed

4 files changed

+203
-4
lines changed

doc/changes/added/12538.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- Add a `(conflict error|ignore)` option to the cram stanza. When `(conflict
22
error)` is set, the cram test will fail in the presence of conflict markers.
3-
(#12538, fixes #12512, @rgrinberg)
3+
Git, diff3 and jujutsu conflict markers are detected. (#12538, #12617, fixes
4+
#12512, @rgrinberg, @Alizter)

src/dune_rules/cram/cram_exec.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ let quote_for_sh fn =
4141
;;
4242

4343
let cram_stanzas =
44+
let is_conflict_marker line =
45+
match line with
46+
| "=======" | "%%%%%%%" | "+++++++" | "-------" | "|||||||" -> true
47+
| _ -> false
48+
in
4449
let find_conflict state line =
4550
match state with
46-
| `No_conflict when line = "<<<<<<<" -> `Start
47-
| `Start when line = "=======" -> `Split
48-
| `Split when line = ">>>>>>>" ->
51+
| `No_conflict when line = "<<<<<<<" -> `Started
52+
| `Started when is_conflict_marker line -> `Has_markers
53+
| `Has_markers when is_conflict_marker line -> `Has_markers
54+
| `Has_markers when line = ">>>>>>>" ->
4955
(* CR-someday rgrinberg for alizter: insert a location spanning the
5056
entire once we start extracting it *)
5157
User_error.raise
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Cram tests can forbid git diff3 conflicts:
2+
3+
$ cat >dune-project <<EOF
4+
> (lang dune 3.21)
5+
> EOF
6+
7+
$ cat >dune <<EOF
8+
> (cram (conflict error))
9+
> EOF
10+
11+
Full diff3 conflict without command and output interleaving:
12+
13+
$ cat >test.t <<EOF
14+
> <<<<<<<
15+
> Left side
16+
> |||||||
17+
> Original
18+
> =======
19+
> Right side
20+
> >>>>>>>
21+
> $ echo tada
22+
> EOF
23+
24+
$ dune runtest test.t
25+
Error: Conflict found. Please remove it or set (conflict allow)
26+
-> required by _build/default/.cram.test.t/cram.sh
27+
-> required by _build/default/.cram.test.t/cram.out
28+
-> required by alias test
29+
[1]
30+
31+
Full diff3 conflict with command and output interleaving:
32+
33+
$ cat >test.t <<EOF
34+
> <<<<<<<
35+
> $ foo left
36+
> |||||||
37+
> $ foo original
38+
> =======
39+
> > bar right
40+
> >>>>>>>
41+
> $ echo tada
42+
> EOF
43+
44+
$ dune runtest test.t
45+
Error: Conflict found. Please remove it or set (conflict allow)
46+
-> required by _build/default/.cram.test.t/cram.sh
47+
-> required by _build/default/.cram.test.t/cram.out
48+
-> required by alias test
49+
[1]
50+
51+
Partial diff3 conflicts are ignored:
52+
53+
$ cat >test.t <<EOF
54+
> <<<<<<<
55+
> $ foo
56+
> > bar
57+
> |||||||
58+
> EOF
59+
60+
$ dune runtest test.t
61+
File "test.t", line 1, characters 0-0:
62+
Error: Files _build/default/test.t and _build/default/test.t.corrected
63+
differ.
64+
[1]
65+
66+
$ cat >test.t <<EOF
67+
> <<<<<<<
68+
> $ foo
69+
> |||||||
70+
> > original
71+
> EOF
72+
73+
$ dune runtest test.t
74+
File "test.t", line 1, characters 0-0:
75+
Error: Files _build/default/test.t and _build/default/test.t.corrected
76+
differ.
77+
[1]
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
Cram tests can forbid jujutsu conflicts:
2+
3+
$ cat >dune-project <<EOF
4+
> (lang dune 3.21)
5+
> EOF
6+
7+
$ cat >dune <<EOF
8+
> (cram (conflict error))
9+
> EOF
10+
11+
Full jujutsu conflict without command and output interleaving:
12+
13+
$ cat >test.t <<EOF
14+
> <<<<<<<
15+
> A Small
16+
> %%%%%%%
17+
> Conflict
18+
> >>>>>>>
19+
> $ echo tada
20+
> EOF
21+
22+
$ dune runtest test.t
23+
Error: Conflict found. Please remove it or set (conflict allow)
24+
-> required by _build/default/.cram.test.t/cram.sh
25+
-> required by _build/default/.cram.test.t/cram.out
26+
-> required by alias test
27+
[1]
28+
29+
Full jujutsu conflict with command and output interleaving:
30+
31+
$ cat >test.t <<EOF
32+
> <<<<<<<
33+
> $ foo
34+
> %%%%%%%
35+
> > bar
36+
> >>>>>>>
37+
> $ echo tada
38+
> EOF
39+
40+
$ dune runtest test.t
41+
Error: Conflict found. Please remove it or set (conflict allow)
42+
-> required by _build/default/.cram.test.t/cram.sh
43+
-> required by _build/default/.cram.test.t/cram.out
44+
-> required by alias test
45+
[1]
46+
47+
Jujutsu default style conflict (diff + snapshot):
48+
49+
$ cat >test.t <<EOF
50+
> <<<<<<<
51+
> %%%%%%%
52+
> -apple
53+
> +grapefruit
54+
> +++++++
55+
> APPLE
56+
> GRAPE
57+
> >>>>>>>
58+
> $ echo tada
59+
> EOF
60+
61+
$ dune runtest test.t
62+
Error: Conflict found. Please remove it or set (conflict allow)
63+
-> required by _build/default/.cram.test.t/cram.sh
64+
-> required by _build/default/.cram.test.t/cram.out
65+
-> required by alias test
66+
[1]
67+
68+
Jujutsu snapshot style conflict:
69+
70+
$ cat >test.t <<EOF
71+
> <<<<<<<
72+
> +++++++
73+
> Left side
74+
> -------
75+
> Original
76+
> +++++++
77+
> Right side
78+
> >>>>>>>
79+
> $ echo tada
80+
> EOF
81+
82+
$ dune runtest test.t
83+
Error: Conflict found. Please remove it or set (conflict allow)
84+
-> required by _build/default/.cram.test.t/cram.sh
85+
-> required by _build/default/.cram.test.t/cram.out
86+
-> required by alias test
87+
[1]
88+
89+
Partial jujutsu conflicts are ignored:
90+
91+
$ cat >test.t <<EOF
92+
> <<<<<<<
93+
> $ foo
94+
> > bar
95+
> >>>>>>>
96+
> EOF
97+
98+
$ dune runtest test.t
99+
File "test.t", line 1, characters 0-0:
100+
Error: Files _build/default/test.t and _build/default/test.t.corrected
101+
differ.
102+
[1]
103+
104+
$ cat >test.t <<EOF
105+
> <<<<<<<
106+
> $ foo
107+
> %%%%%%%
108+
> > bar
109+
> EOF
110+
111+
$ dune runtest test.t
112+
File "test.t", line 1, characters 0-0:
113+
Error: Files _build/default/test.t and _build/default/test.t.corrected
114+
differ.
115+
[1]

0 commit comments

Comments
 (0)