Skip to content

Commit

Permalink
conflicts: use clearer wording for missing newline comment
Browse files Browse the repository at this point in the history
The current comment uses `[noeol]`, which can be difficult to
understand. In this commit, the brackets are changed to parentheses to
make it clear that there is no semantic meaning to the comment, and the
wording is changed to be more clear to the user.
  • Loading branch information
scott2000 committed Jan 31, 2025
1 parent 0b71933 commit 66808e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
22 changes: 10 additions & 12 deletions docs/conflicts.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,18 @@ New Heading
>>>>>>>>>>>>>>> Conflict 1 of 1 ends
```

## Conflicts with missing terminating newline (`[noeol]`)
## Conflicts with missing terminating newline

When materializing conflicts, `jj` outputs them in a line-based format. This
format is easiest to interpret for text files that consist of a series of lines,
with each line terminated by a newline character (`\n`). This means that a text
file should either be empty, or it should end with a newline character.

While most text files follow this convention, some do not. To handle this case,
when `jj` encounters a missing terminating newline character in a conflict, it
will add a `[noeol]` comment to the conflict markers to indicate that the
"end-of-line" (EOL) character was missing. If you don't care about whether your
file ends with a terminating newline character, you can generally ignore this
comment and resolve the conflict normally.
While most text files follow this convention, some do not. When `jj` encounters
a missing terminating newline character in a conflict, it will add a comment to
the conflict markers to make the conflict easier to interpret. If you don't care
about whether your file ends with a terminating newline character, you can
generally ignore this comment and resolve the conflict normally.

For instance, if a file originally contained `grape` with no terminating newline
character, and one person changed `grape` to `grapefruit`, while another person
Expand All @@ -206,14 +205,13 @@ would look like this:

```
<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1 [noeol]
+++++++ Contents of side #1 (no terminating newline)
grapefruit
%%%%%%% Changes from base to side #2 [-noeol]
%%%%%%% Changes from base to side #2 (adds terminating newline)
-grape
+grape
>>>>>>> Conflict 1 of 1 ends
```

The `[-noeol]` comment for the diff section indicates that the base (`-`) was
missing a terminating newline character. A resolution of this conflict could be
`grapefruit\n`, with the terminating newline character added.
Therefore, a resolution of this conflict could be `grapefruit\n`, with the
terminating newline character added.
6 changes: 3 additions & 3 deletions lib/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub const MIN_CONFLICT_MARKER_LEN: usize = 7;
const CONFLICT_MARKER_LEN_INCREMENT: usize = 4;

/// Comment for missing terminating newline in a term of a conflict.
const NO_EOL_COMMENT: &str = " [noeol]";
const NO_EOL_COMMENT: &str = " (no terminating newline)";

/// Comment for missing terminating newline in the "add" side of a diff.
const ADD_NO_EOL_COMMENT: &str = " [+noeol]";
const ADD_NO_EOL_COMMENT: &str = " (removes terminating newline)";

/// Comment for missing terminating newline in the "remove" side of a diff.
const REMOVE_NO_EOL_COMMENT: &str = " [-noeol]";
const REMOVE_NO_EOL_COMMENT: &str = " (adds terminating newline)";

fn write_diff_hunks(hunks: &[DiffHunk], file: &mut dyn Write) -> io::Result<()> {
for hunk in hunks {
Expand Down
22 changes: 11 additions & 11 deletions lib/tests/test_conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,14 @@ fn test_materialize_conflict_no_newlines_at_eof() {
let materialized =
&materialize_conflict_string(store, path, &conflict, ConflictMarkerStyle::Diff);
insta::assert_snapshot!(materialized,
@r###"
@r##"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1 [-noeol]
%%%%%%% Changes from base to side #1 (adds terminating newline)
-base
+++++++ Contents of side #2 [noeol]
+++++++ Contents of side #2 (no terminating newline)
right
>>>>>>> Conflict 1 of 1 ends
"###
"##
);
// The conflict markers are parsed with the trailing newline, but it is removed
// by `update_from_content`
Expand Down Expand Up @@ -2057,7 +2057,7 @@ fn test_update_conflict_from_content_no_eol() {
+++++++ Contents of side #1
base
left
%%%%%%% Changes from base to side #2 [noeol]
%%%%%%% Changes from base to side #2 (no terminating newline)
-base
+right
>>>>>>> Conflict 2 of 2 ends
Expand Down Expand Up @@ -2096,9 +2096,9 @@ fn test_update_conflict_from_content_no_eol() {
+++++++ Contents of side #1
base
left
------- Contents of base [noeol]
------- Contents of base (no terminating newline)
base
+++++++ Contents of side #2 [noeol]
+++++++ Contents of side #2 (no terminating newline)
right
>>>>>>> Conflict 2 of 2 ends
"##
Expand Down Expand Up @@ -2197,15 +2197,15 @@ fn test_update_conflict_from_content_no_eol_in_diff_hunk() {
<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
side
%%%%%%% Changes from base #1 to side #2 [-noeol]
%%%%%%% Changes from base #1 to side #2 (adds terminating newline)
add newline
-line
+line
%%%%%%% Changes from base #2 to side #3 [+noeol]
%%%%%%% Changes from base #2 to side #3 (removes terminating newline)
remove newline
-line
+line
%%%%%%% Changes from base #3 to side #4 [noeol]
%%%%%%% Changes from base #3 to side #4 (no terminating newline)
no newline
-line 1
+line 2
Expand Down Expand Up @@ -2253,7 +2253,7 @@ fn test_update_conflict_from_content_only_no_eol_change() {
@r##"
line 1
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1 [+noeol]
%%%%%%% Changes from base to side #1 (removes terminating newline)
+line 2
+++++++ Contents of side #2
line 2
Expand Down

0 comments on commit 66808e5

Please sign in to comment.