Skip to content

Take nonewline context into account in diff parser

M. Hasbini requested to merge 0xbsec/gitlab-ce:nonewline-parser into master

What does this MR do?

The problem is that the parser doesn’t check which file doesn’t have no newline, it only check that there's a nonewline and add it for both sides of the diff.

My approach to fix this was to replace nonewline with old-nonewline and new-nonewline based on context.

This takes into assumption that no diff will have \ No newline at end of file before any changes.

The conflict parser also uses nonewline. I’ll update it but I need to make sure that my approach to fix this problem is good.

Update:

As I've tested, the conflict parser will not be affected by the nonewline problem.

These scenarios need to be tested / asserted:

  • a doesn’t have new line but b does.

  • a have new line but b doesn’t.

  • a doesn’t have new line and b doesn’t.

  • a have new line and b does.

Are there points in the code the reviewer needs to double check?

Screenshots (if relevant)

Currently the diff looks like this for the different scenarios:

1- a doesn’t have new line but b does.

this branch master 2d006b46
Screen_Shot_2017-03-05_at_11.33.22_AM Screen_Shot_2017-03-05_at_11.34.21_AM

diff:

$ git diff 3...4
diff --git a/d b/d
index 2e65efe..6178079 100644
--- a/d
+++ b/d
@@ -1 +1 @@
-a
\ No newline at end of file
+b

2- a have new line but b doesn’t.

this branch master 2d006b46
Screen_Shot_2017-03-04_at_11.48.08_PM Screen_Shot_2017-03-05_at_11.17.02_AM

diff:

$ git diff master...t
diff --git a/a b/a
index 7898192..63d8dbd 100644
--- a/a
+++ b/a
@@ -1 +1 @@
-a
+b
\ No newline at end of file

3- a doesn’t have new line and b doesn’t.

this branch master 2d006b46
Screen_Shot_2017-03-04_at_11.48.19_PM Screen_Shot_2017-03-05_at_11.16.55_AM

diff:

$ git diff master...b
diff --git a/a b/a
index 2e65efe..63d8dbd 100644
--- a/a
+++ b/a
@@ -1 +1 @@
-a
\ No newline at end of file
+b
\ No newline at end of file

4-a have new line and b does.

this branch master 2d006b46
Screen_Shot_2017-03-04_at_11.47.59_PM Screen_Shot_2017-03-05_at_11.17.08_AM

diff:

$ git diff 1...2
diff --git a/test b/test
index 7187db3..304d8aa 100644
--- a/test
+++ b/test
@@ -1,2 +1,2 @@
-lorem
 ipsum
+lorem

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes #28128 (closed)

Closes #22636 (closed)

Merge request reports