Bug: conflict in the last file line results in wrong combined diff

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found another bug in the combined diff. It is slightly related to
the one I reported some time ago (combined diff always misses
'NoEolAtEof' pragma), but it's different.

Description:
A simple conflict in the last line in a file with no EOL at EOF
results in a wrong -cc diff with a weird (invalid?) formatting.

Steps to reproduce:

```
git init

echo -n "1\n2" > m.txt
git add m.txt
git commit -m "initial commit"

echo -n "1m\n2m" > m.txt
git commit -am "master change"

git checkout -b branch1 HEAD^
echo -n "1b\n2b" > m.txt
git commit -am "branch1 change"

git merge master

git log --all --graph --oneline
git diff m.txt
```

Actual diff:

```
diff --cc m.txt
index d53cefe,cf67f83..0000000
--- a/m.txt
+++ b/m.txt
@@@ -1,2 -1,2 +1,7 @@@
++<<<<<<< HEAD
 +1b
- 2b      <- wrong! there was no '2b' in the initial commit
++2b      <- wrong! '++' ('both added') doesn't make sense inside a
conflict block
++=======
+ 1m
 -2m      <- wrong! there was no '2m' in the initial commit
++2m      <- wrong! '++' ('both added') doesn't make sense inside a
conflict block
++>>>>>>> master
```

Expected diff (I intentionally missed `\ No newline at end of file`
pragmas to simplify the idea):
```
$ git diff m.txt
diff --cc m.txt
index 7d8e479,73a8b45..0000000
--- a/m.txt
+++ b/m.txt
@@@ -1,2 -1,2 +1,7 @@@
++<<<<<<< HEAD
 +1b
 +2b
++=======
+ 1m
+ 2m
++>>>>>>> master
```

It looks like `\ No newline at end of file` handling is involved
because removing `-n` from the `echo` command in the steps to
reproduce makes diff to produce the correct output.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux