git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Bug: conflict in the last file line results in wrong combined diff
@ 2022-08-18 13:54 Danil Pristupov
  0 siblings, 0 replies; only message in thread
From: Danil Pristupov @ 2022-08-18 13:54 UTC (permalink / raw)
  To: git

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-18 13:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 13:54 Bug: conflict in the last file line results in wrong combined diff Danil Pristupov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).