Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conflicts: allow missing newlines at end of file (based on previous content) #5186

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

scott2000
Copy link
Contributor

Fixes #3968. Alternative to #5181 and #4088.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@scott2000
Copy link
Contributor Author

One possible issue with this approach is that some conflicts become unreadable. For instance, a conflict with a base of base, a left side of left, and a right side of base\n would be rendered as:

<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1
left
%%%%%%% Changes from base to side #2
 base
>>>>>>> Conflict 1 of 1 ends

@yuja
Copy link
Contributor

yuja commented Dec 25, 2024

One possible issue with this approach is that some conflicts become unreadable. For instance, a conflict with a base of base, a left side of left, and a right side of base\n

I think base and base\n can still be rendered as different contents (though these two are visually identical.) Maybe we can add some comment to the marker description?

@scott2000 scott2000 force-pushed the conflict-missing-newline-alternative branch from f900119 to 6a87871 Compare December 25, 2024 18:05
@scott2000
Copy link
Contributor Author

Ok, I updated it so that it would render as this:

<<<<<<< Conflict 1 of 1
+++++++ Contents of side #1 [noeol]
left
%%%%%%% Changes from base to side #2 [-noeol]
 base
>>>>>>> Conflict 1 of 1 ends

&format!(
"Side #1 ({conflict_info}){}",
no_eol_marker(no_eol.get_add(0))
),
)?;
output.write_all(left)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think missing \n should be padded here. (applies to the other materialization styles and sides)

It's the matter of rendering.

@scott2000 scott2000 force-pushed the conflict-missing-newline-alternative branch from 6a87871 to af6c386 Compare December 26, 2024 03:16
A missing newline would cause the following conflict markers to become
invalid when materializing the conflict, so we add a newline to prevent
this from happening. When parsing, if we parsed a conflict at the end of
the file which ended in a newline, we can check whether the file
actually did end in a newline, and then remove the newline if it didn't.
@scott2000 scott2000 force-pushed the conflict-missing-newline-alternative branch from af6c386 to 1688e33 Compare December 26, 2024 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflicts at the end of files that don't end in a newline are not materialized correctly
2 participants