# Diff for unmerged files always misses the `\ No newline at end of file` mark

2 messages from 2022-06-23 to 2022-06-25. Participants: Danil Pristupov, brian m. carlson.
Thread: https://gitlist.dev/t/58059

## Danil Pristupov, 2022-06-23 15:39

Subject: Diff for unmerged files always misses the `\ No newline at end of file` mark
Message-ID: <CAKdzDnn7KkRpXta1LiHcDPCztPcPRTFv8zTW_v+GpBAuSTW6yg@mail.gmail.com>
URL: https://gitlist.dev/e/CAKdzDnn7KkRpXta1LiHcDPCztPcPRTFv8zTW_v%2BGpBAuSTW6yg%40mail.gmail.com

```
Some time ago I reported a bug there, but got no response. I hope it's
OK if I post it again.

Diff for unmerged files always misses the `\ No newline at end of file` mark.

I was able to reproduce this with all git versions on all platforms.

Steps to reproduce (macOS, 2.32.0 (Apple Git-132)):

ˋˋˋ
git init
echo "line1\nline2" > eol.txt
echo -n "line1\nline2" > noeol.txt
git add .
git commit -m "initial"
git branch br1
echo "line11\nline2" > eol.txt
echo -n "line11\nline2" > noeol.txt
git add .
git commit -m "line1"
git checkout br1
echo "line12\nline2" > eol.txt
echo -n "line12\nline2" > noeol.txt
git add .
git commit -m "line2"
git merge master
git diff -- eol.txt > eol.diff
git diff -- noeol.txt > noeol.diff
ˋˋˋ

Expected behavior: `noeol.diff` must have the `\\ No newline at end of
file` mark (I guess double slash `\` must be used as a prefix)

ˋˋˋ
$ git diff -- eol.txt
diff --cc eol.txt
index 3dc0c7e,5328e33..0000000
--- a/eol.txt
+++ b/eol.txt
@@@ -1,2 -1,2 +1,6 @@@
++<<<<<<< HEAD
 +line12
++=======
+ line11
++>>>>>>> master
  line2
\\ No newline at end of file
ˋˋˋ

Actual behavior: `noeol.diff` does NOT have the `\\ No newline at end
of file` mark

ˋˋˋ
$ git diff -- eol.txt
diff --cc eol.txt
index 3dc0c7e,5328e33..0000000
--- a/eol.txt
+++ b/eol.txt
@@@ -1,2 -1,2 +1,6 @@@
++<<<<<<< HEAD
 +line12
++=======
+ line11
++>>>>>>> master
  line2
ˋˋˋ

```

## brian m. carlson, 2022-06-25 11:49

Subject: Re: Diff for unmerged files always misses the `\ No newline at end of file` mark
Message-ID: <Yrb2Wv92eLmXY6NV@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Yrb2Wv92eLmXY6NV%40tapette.crustytoothpaste.net
In-Reply-To: <CAKdzDnn7KkRpXta1LiHcDPCztPcPRTFv8zTW_v+GpBAuSTW6yg@mail.gmail.com>

```
On 2022-06-23 at 15:39:07, Danil Pristupov wrote:
> Some time ago I reported a bug there, but got no response. I hope it's
> OK if I post it again.
> 
> Diff for unmerged files always misses the `\ No newline at end of file` mark.
> 
> I was able to reproduce this with all git versions on all platforms.
> 
> Steps to reproduce (macOS, 2.32.0 (Apple Git-132)):
> 
> ˋˋˋ
> git init
> echo "line1\nline2" > eol.txt
> echo -n "line1\nline2" > noeol.txt
> git add .
> git commit -m "initial"
> git branch br1
> echo "line11\nline2" > eol.txt
> echo -n "line11\nline2" > noeol.txt
> git add .
> git commit -m "line1"
> git checkout br1
> echo "line12\nline2" > eol.txt
> echo -n "line12\nline2" > noeol.txt
> git add .
> git commit -m "line2"
> git merge master
> git diff -- eol.txt > eol.diff
> git diff -- noeol.txt > noeol.diff
> ˋˋˋ

Thanks for the report.  I think this is indeed a bug, but maybe someone
more familiar with things than I am can confirm.

From a preliminary examination, it looks like the --cc and regular modes
render diffs completely differently, and code similar to what's at the
end of emit_rewrite_lines belongs at the end of dump_sline as well.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

```
