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

Sort out behaviour of newlineIsToken and ignoreWhitespace #486

Merged
merged 11 commits into from
Feb 15, 2024

Conversation

ExplodingCabbage
Copy link
Collaborator

@ExplodingCabbage ExplodingCabbage commented Feb 14, 2024

Three fixes here:

For me to do before merging:

  • Sanity check this works at all
  • Add release notes. Remember to call out the deprecation of diffTrimmedLines.
  • Take another look at Fix diffTrimmedLines not keep whitespaces in the output #219. (I didn't read the diff there before doing my own work on this - I'd actually forgotten @Mingun had actually put up a PR about this and not just an issue.)
  • Update the failing tests
  • Add a new test confirming compatibility between newlineIsToken and ignoreWhitespace.

@ExplodingCabbage ExplodingCabbage self-assigned this Feb 14, 2024
@ExplodingCabbage ExplodingCabbage marked this pull request as ready for review February 15, 2024 15:08
@ExplodingCabbage
Copy link
Collaborator Author

@Mingun I'd welcome any comments you have on this. Have I failed to properly handle anything here that your PR did better?

@ExplodingCabbage ExplodingCabbage merged commit 5f9cd41 into master Feb 15, 2024
@ExplodingCabbage ExplodingCabbage deleted the incompatible-newline-options branch February 15, 2024 15:10
Comment on lines +166 to +173
it(
'should not consider adding whitespace to an empty line an insertion ' +
'even in newlineIsToken mode where a token may be an empty string',
function() {
const diffResult = diffTrimmedLines('foo\n\nbar', 'foo\n \nbar', {newlineIsToken: true});
expect(convertChangesToXML(diffResult)).to.equal('foo\n \nbar');
}
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, crap, I meant to remove this test before merging. It doesn't pass (and I added docs noting that!)

@Mingun
Copy link
Contributor

Mingun commented Feb 15, 2024

Hi @ExplodingCabbage!

My intention was to get correct diff behavior that you usually expect from code diffs. When I implemented my fix in #219 I think, I got the expected results, that TortoiseGitMerge and similar tools give you when you merge file in ignored whitespace mode. I probably didn't actually investigate that behavior is identical, but I remember that at least results was not surprising:

  • removed lines keeps formatting from "old" chunk (there is anyway no "new" chunk)
  • added lines keeps formatting from "new" chunk (there is anyway no "old" chunk)
  • don't remember what was returned for changed lines

Anyway, I think, that your fix is simpler, but I suggest to take tests from my PR, because they:

I think, that having them it is much better to understand what to expect from results.

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.

Document (and throw an error over) the incompatibility between newlineIsToken and ignoreWhitespace
2 participants